forked from CTres/machinepack-facebookads
/
get-ads-in-ad-set.js
64 lines (47 loc) · 1.67 KB
/
get-ads-in-ad-set.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
module.exports = {
friendlyName: 'get-ads-in-ad-set',
description: 'get ads in an ad set with standard metadata',
extendedDescription: 'get ads in an ad set and standard metadata',
cacheable: true,
inputs: {
adCampaignId: {
example: '31231321312',
description: 'an adcampaign is an adset',
required: true
},
accessToken: {
example: 'CAACEdEose0cBACBhZA7DJbYapwM7oZBt1EWhPiGqibBZAZAZCZCe6IOkfDRzrs1jyZCS93zSuj9GaNQQtxbny0jeSCqyBNaQUl3ocDiD3lO4GSboFm5B7NogSHFzTGYw0rdpndDKolQcfsS5nYeYwZAIKXF1WPzgGaGxNIDh36oZBHuazcN3WSNmL9jGyO9YmYlZBmZCcigBuMFvtXj4XlzNWyb',
description: 'this is the facebook issued access token for a given user and app pair',
required: true
},
},
defaultExit: 'success',
exits: {
error: {
description: 'The Facebook API returned an error (i.e. a non-2xx status code)',
},
success: {
description: 'Here are the ads in the ad set and their standard metadata',
},
},
// get ad sets by campaign - first, find the right campaign id for a given name
// second, fetch all the ad sets for that given campaign
fn: function (inputs,exits) {
var doJSONRequest = require('../lib/do-request');
var fields = inputs.fields || 'id,stats,name,adgroup_status';
// GET ad accounts/ and send the api token as a header
doJSONRequest({
method: 'get',
url: ['/v2.3/', inputs.adCampaignId, '/adgroups' ].join(""),
data: {
'access_token': inputs.accessToken,
'fields' : fields
},
headers: {},
},
function (err, responseBody) {
if (err) { return exits.error(err); }
return exits.success(responseBody);
});
}
};