Created
October 24, 2015 16:06
-
-
Save clarle/b8a096311e33cbda8c61 to your computer and use it in GitHub Desktop.
Target API data fetching with Express and Request
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
Are you getting response from this service? When i tried the URL is not forming properly.