Created
April 8, 2016 20:12
-
-
Save joetemp/90f7e319e10d2b8e21a5d23e4e7a131e to your computer and use it in GitHub Desktop.
Program
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'); | |
| var url = {deals: 'https://api.pipedrive.com/v1/deals?start=0&api_token=a74cbe24c7ac34f45256356a747eaebf96445c94', | |
| activities: 'https://api.pipedrive.com/v1/activities?start=0&api_token=a74cbe24c7ac34f45256356a747eaebf96445c94'}; | |
| function getDeals (url, callback) { | |
| request(url, function (error, response, body) { | |
| if (error) { | |
| return console.log(error); | |
| } | |
| var parse = JSON.parse(body).data; | |
| callback(parse); | |
| }); | |
| } | |
| getDeals (url.deals, function (deals) { | |
| getDeals (url.activities, function (activities) { | |
| var applications = []; | |
| for (var i in deals) { | |
| // If the stage_id is 2, put the deal in the applications array. | |
| if (deals[i].stage_id === 2) { | |
| applications.push(deals[i].id); | |
| } | |
| } | |
| // This section is what's causing issues: | |
| for (var j in applications) { | |
| for (var i in activities) { | |
| /*This should check to see if a task already has an activity call "Foo". If it does, it will also check to see if the | |
| * deal_id matches applications[i]. If both are true, it should delete that deal from the applications array.*/ | |
| if (activities[i].subject === 'Foo' && applications[j] === activities[i].deal_id) { | |
| // Delete the deal from the applications array IF it already has a 'Foo' activity. | |
| applications.splice(j, 1); | |
| } | |
| } | |
| } | |
| addActivities(applications); | |
| }); | |
| }); | |
| function addActivities(applications) { | |
| for (var i in applications) { | |
| request.post('https://api.pipedrive.com/v1/activities?api_token=a74cbe24c7ac34f45256356a747eaebf96445c94', { | |
| form: {'subject': 'Foo', | |
| 'deal_id': applications[i]}}); | |
| } | |
| /* These are all the deals in the 'applications' array. If they are in this array, they should be in stage 2 and NOT already have a | |
| 'Foo' activity. Once this program is run... there should be NO items in this array. */ | |
| console.log(applications); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment