-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathbatch-get-campaign-groups-query-tunneling.ts
More file actions
48 lines (42 loc) · 1.47 KB
/
batch-get-campaign-groups-query-tunneling.ts
File metadata and controls
48 lines (42 loc) · 1.47 KB
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
/**
* Example calls to perform BATCH_GET on campaign groups and illustrate automatic
* query tunneling.
*
* The 3-legged member access token should include the 'r_ads' scope, which
* is part of the Advertising APIs product.
*/
import { RestliClient } from 'linkedin-api-client';
import dotenv from 'dotenv';
dotenv.config();
const API_VERSION = '202212';
const AD_CAMPAIGN_GROUPS_RESOURCE = '/adCampaignGroups';
// Set a large number of entities to fetch to require query tunneling
const NUMBER_OF_ENTITIES = 300;
async function main(): Promise<void> {
const restliClient = new RestliClient();
restliClient.setDebugParams({ enabled: true });
const accessToken = process.env.ACCESS_TOKEN || '';
/**
* Randomly generate campaign group ids and send in a BATCH_GET request (we expect all 404 responses).
* The client should automatically do query tunneling and perform a POST request.
*/
const campaignGroupIds = Array.from({ length: NUMBER_OF_ENTITIES }).map((_) =>
Math.floor(Math.random() * 99999999999999)
);
const batchGetResponse = await restliClient.batchGet({
resourcePath: AD_CAMPAIGN_GROUPS_RESOURCE,
ids: campaignGroupIds,
accessToken,
versionString: API_VERSION
});
console.log(
`Successfully made a BATCH_GET request on /adCampaignGroups. HTTP Method: ${batchGetResponse.config.method}]`
);
}
main()
.then(() => {
console.log('Completed');
})
.catch((error) => {
console.log(`Error encountered: ${error.message}`);
});