Created
April 22, 2016 04:10
-
-
Save joetemp/46ba968ab9ff43d288dbd25382f729e1 to your computer and use it in GitHub Desktop.
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
| const request = require('request-promise'); | |
| var API_KEY = process.env.API_KEY; | |
| var urls = { deals: 'https://api.pipedrive.com/v1/deals?start=0&api_token=' + API_KEY, | |
| activities: 'https://api.pipedrive.com/v1/activities?start=0&api_token=' + API_KEY }; | |
| function getIt (url) { | |
| return request(url).then(function (body) { | |
| return JSON.parse(body).data; | |
| }); | |
| } | |
| function add (i) { | |
| return request.post('https://api.pipedrive.com/v1/activities?api_token=' + API_KEY, { | |
| form: {'subject': '4506-T', | |
| 'deal_id': i}}); | |
| } | |
| Promise.all([getIt(urls.deals), getIt(urls.activities)]).then(function(results) { | |
| var deals = results[0]; | |
| var activities = results[1]; | |
| var apps = {}; | |
| /* | |
| for (var i in deals) { | |
| if (deals[i].stage_id === 2) { | |
| apps[deals[i].id] = deals[i]; | |
| } | |
| } | |
| */ | |
| deals.forEach(function(deal){ | |
| if (deal.stage_id === 2) { | |
| apps[deal.id] = deal; | |
| } | |
| }); | |
| console.log(apps); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment