Skip to content

Instantly share code, notes, and snippets.

@clarle
Created October 24, 2015 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clarle/b8a096311e33cbda8c61 to your computer and use it in GitHub Desktop.
Save clarle/b8a096311e33cbda8c61 to your computer and use it in GitHub Desktop.
Target API data fetching with Express and Request
var _ = require('lodash'),
express = require('express'),
request = require('request'),
app = express();
var API_KEY = '1Kfdqvy6wHmvJ4LDyAVOl7saCBoKHcSb';
app.get('/products/:id', function(req, res) {
var ourData = {
age_group: '0-1 years old',
tags: ['math', 'problem solving', 'counting']
};
var id = req.params.id;
request.get('http://api.target.com/items/v3/' + id, {
qs: {
id_type: 'dpci',
key: API_KEY
},
json: true
}, function(err, response, body) {
var targetItems = _.get(body, 'product_composite_response.items');
ourData.urls = targetItems.map(function(item) {
return item.data_page_link;
});
res.json(ourData);
});
});
app.listen(5000);
console.log('App running on port 5000');
@Radicare
Copy link

Hi,
Are you getting response from this service? When i tried the URL is not forming properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment