Created
April 21, 2016 23:16
-
-
Save joetemp/ae65e43856a4bd479175eb8b157d4dc6 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(){ | |
| if (deals[i].stage_id === 2) { | |
| apps[deals[i].id] = deals[i]; | |
| } | |
| }); | |
| console.log(apps); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment