@hermoso/ads 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +105 -2
- package/docs/bring-your-own-app.md +391 -0
- package/package.json +66 -4
- package/src/core.js +20 -0
- package/src/credentials.js +53 -0
- package/src/errors.js +29 -0
- package/src/hash.js +30 -0
- package/src/http.js +148 -0
- package/src/index.js +103 -0
- package/src/money.js +25 -0
- package/src/oauth.js +34 -0
- package/src/ops.js +49 -0
- package/src/platform.js +56 -0
- package/src/platforms/amazon-ads.js +218 -0
- package/src/platforms/apple-ads.js +236 -0
- package/src/platforms/applovin-ads.js +182 -0
- package/src/platforms/google-ads.js +435 -0
- package/src/platforms/index.js +21 -0
- package/src/platforms/linkedin-ads.js +297 -0
- package/src/platforms/meta.js +518 -0
- package/src/platforms/microsoft-ads.js +381 -0
- package/src/platforms/openai-ads.js +246 -0
- package/src/platforms/outbrain-ads.js +128 -0
- package/src/platforms/pinterest-ads.js +271 -0
- package/src/platforms/reddit-ads.js +259 -0
- package/src/platforms/snapchat-ads.js +276 -0
- package/src/platforms/taboola-ads.js +57 -0
- package/src/platforms/tiktok-ads.js +348 -0
- package/src/platforms/trade-desk.js +111 -0
- package/src/platforms/x-ads.js +274 -0
- package/src/safety.js +96 -0
- package/src/tools.js +81 -0
- package/src/zip.js +47 -0
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { definePlatform, row, pickLevel, dateRange } from '../platform.js';
|
|
3
|
+
import { AdsError } from '../errors.js';
|
|
4
|
+
import { assertBornPaused, gateStatus, gateBudget, gateDelete, requireConfirm, checkLength, STATUS } from '../safety.js';
|
|
5
|
+
import { toMajor } from '../money.js';
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
const BASE = 'https://business-api.tiktok.com/open_api/v1.3';
|
|
9
|
+
const SANDBOX = 'https://sandbox-ads.tiktok.com/open_api/v1.3';
|
|
10
|
+
const OBJECTIVES = ['TRAFFIC', 'REACH', 'VIDEO_VIEWS', 'ENGAGEMENT', 'WEB_CONVERSIONS', 'LEAD_GENERATION', 'APP_INSTALL', 'PRODUCT_SALES', 'CONVERSIONS'];
|
|
11
|
+
const RETIRED_OBJECTIVES = { CATALOG_SALES: 'retired by TikTok; use PRODUCT_SALES', SHOP_PURCHASES: 'needs a TikTok Shop', RF_ENGAGEMENT: 'not supported', RF_APP_INSTALL: 'not supported' };
|
|
12
|
+
const BILLING_FOR_GOAL = {
|
|
13
|
+
CLICK: 'CPC', PAGE_VISIT: 'CPC', SHOW: 'CPM', REACH: 'CPM', ENGAGED_VIEW: 'CPV', ENGAGED_VIEW_FIFTEEN: 'CPV',
|
|
14
|
+
CONVERT: 'OCPM', INSTALL: 'OCPM', IN_APP_EVENT: 'OCPM', TRAFFIC_LANDING_PAGE_VIEW: 'OCPM', LEAD_GENERATION: 'OCPM', CONVERSATION: 'OCPM',
|
|
15
|
+
FOLLOWERS: 'OCPM', VALUE: 'OCPM', AUTOMATIC_VALUE_OPTIMIZATION: 'OCPM', DESTINATION_VISIT: 'OCPM',
|
|
16
|
+
};
|
|
17
|
+
const LEVEL = { campaign: 'campaign', adGroup: 'adgroup', ad: 'ad' };
|
|
18
|
+
|
|
19
|
+
function code(body) { return body && typeof body === 'object' && 'code' in body ? Number(body.code) : null; }
|
|
20
|
+
|
|
21
|
+
function classify(c, message) {
|
|
22
|
+
if (/complete payment|payment method|add.{0,12}payment|insufficient balance/i.test(message ?? '')) {
|
|
23
|
+
return { kind: 'refused', code: c, message, userMessage: `TikTok: the ad account has no usable payment method (the connection is fine). ${message}` };
|
|
24
|
+
}
|
|
25
|
+
if (c === 40001) return { kind: /permission/i.test(message ?? '') ? 'permission' : 'auth', code: c, message };
|
|
26
|
+
if (c === 40105) return { kind: 'auth', code: c, message };
|
|
27
|
+
if (c === 40100) return { kind: 'rate_limit', code: c, message };
|
|
28
|
+
if (c === 40002) return { kind: 'validation', code: c, message };
|
|
29
|
+
if (c === 40911) return { kind: 'validation', code: c, message, userMessage: `TikTok: a file with that name already exists for this advertiser. ${message}` };
|
|
30
|
+
return { kind: 'vendor', code: c, message };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export default definePlatform({
|
|
34
|
+
id: 'tiktok_ads',
|
|
35
|
+
label: 'TikTok Ads',
|
|
36
|
+
money: 'major',
|
|
37
|
+
credentials: [
|
|
38
|
+
{ name: 'accessToken', required: true, env: 'TIKTOK_ADS_ACCESS_TOKEN', desc: 'Long-term advertiser access token (does not expire until revoked).' },
|
|
39
|
+
{ name: 'appId', env: 'TIKTOK_ADS_APP_ID', desc: 'Your Marketing API app id (needed to list advertisers).' },
|
|
40
|
+
{ name: 'secret', env: 'TIKTOK_ADS_APP_SECRET', desc: 'Your app secret (needed to list advertisers).' },
|
|
41
|
+
{ name: 'sandbox', env: 'TIKTOK_ADS_SANDBOX', desc: '"true" for the sandbox host.' },
|
|
42
|
+
],
|
|
43
|
+
baseUrl: (c) => (c.sandbox === 'true' || c.sandbox === true ? SANDBOX : BASE),
|
|
44
|
+
authHeaders: (c) => ({ 'Access-Token': c.accessToken }),
|
|
45
|
+
checkBody: (body) => {
|
|
46
|
+
const c = code(body);
|
|
47
|
+
return c != null && c !== 0 ? classify(c, body.message) : null;
|
|
48
|
+
},
|
|
49
|
+
parseError: (status, body) => (code(body) != null ? classify(code(body), body.message) : null),
|
|
50
|
+
notes: [
|
|
51
|
+
'TikTok creates objects ENABLED by default; every create here forces DISABLE and reads it back.',
|
|
52
|
+
'An ad needs an identity (identity_id + identity_type); list them with your app or pass a Spark post via tiktokItemId.',
|
|
53
|
+
'Smart+ (automated) campaigns: pass smartPlus: true to createCampaign / createAdGroup / createAd / setStatus.',
|
|
54
|
+
'Reach & Frequency ad groups cannot be created paused, so they are not offered here.',
|
|
55
|
+
],
|
|
56
|
+
setup: {
|
|
57
|
+
app: 'A developer app on TikTok for Business (business-api.tiktok.com/portal) with the Marketing API, and the permission groups you need ticked (Ads Management, Ad Account Management, Audience Management, Reporting, Creative Management, Pixel Management).',
|
|
58
|
+
scopes: ['(TikTok has no OAuth scopes: permission groups are chosen on the app and granted at authorization)'],
|
|
59
|
+
review: 'The app is reviewed by TikTok before it can be authorized by other advertisers. Permission groups bind at authorization time, so adding a group later means re-authorizing. Rate limits start low and are raised on request.',
|
|
60
|
+
hosted: { connect: 'app', note: 'Hosted Hermoso connects with one click where supported, with no developer app of your own.' },
|
|
61
|
+
docs: 'https://business-api.tiktok.com/portal/docs',
|
|
62
|
+
},
|
|
63
|
+
ops: {
|
|
64
|
+
listAccounts: {
|
|
65
|
+
run: async (ctx, a) => {
|
|
66
|
+
const c = await ctx.creds();
|
|
67
|
+
if (!c.appId || !c.secret) throw new AdsError('validation', 'Listing advertisers needs appId and secret alongside the access token.', { field: 'appId' });
|
|
68
|
+
const r = await ctx.request({ path: '/oauth2/advertiser/get/', query: { app_id: c.appId, secret: c.secret } });
|
|
69
|
+
return { items: (r.data?.list ?? []).map((x) => row(x, { id: String(x.advertiser_id), name: x.advertiser_name }, a)) };
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
listCampaigns: {
|
|
73
|
+
params: { accountId: { required: true, desc: 'Advertiser id.' }, smartPlus: { type: 'boolean' } },
|
|
74
|
+
run: async (ctx, a) => {
|
|
75
|
+
const r = await ctx.request({ path: a.smartPlus ? '/smart_plus/campaign/get/' : '/campaign/get/', query: { advertiser_id: a.accountId, page_size: Math.min(a.limit ?? 100, 1000), page: a.cursor ?? 1 } });
|
|
76
|
+
const pi = r.data?.page_info;
|
|
77
|
+
return { items: (r.data?.list ?? []).map((c) => row(c, { id: String(c.campaign_id), name: c.campaign_name, status: c.operation_status, secondaryStatus: c.secondary_status, objective: c.objective_type, budget: c.budget, budgetMode: c.budget_mode }, a)),
|
|
78
|
+
next: pi && pi.page < pi.total_page ? String(pi.page + 1) : null };
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
getCampaign: {
|
|
82
|
+
params: { accountId: { required: true }, id: { required: true } },
|
|
83
|
+
run: async (ctx, a) => {
|
|
84
|
+
const r = await ctx.request({ path: '/campaign/get/', query: { advertiser_id: a.accountId, filtering: { campaign_ids: [String(a.id)] } } });
|
|
85
|
+
const c = r.data?.list?.[0];
|
|
86
|
+
if (!c) throw new AdsError('not_found', `Campaign ${a.id} not found (TikTok reads can lag a fresh write by a second or two).`);
|
|
87
|
+
return row(c, { id: String(c.campaign_id), name: c.campaign_name, status: c.operation_status, objective: c.objective_type, budget: c.budget, budgetMode: c.budget_mode }, a);
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
createCampaign: {
|
|
91
|
+
params: {
|
|
92
|
+
accountId: { required: true }, name: { required: true },
|
|
93
|
+
objective: { type: 'string', desc: `${OBJECTIVES.join(', ')} (Smart+: WEB_CONVERSIONS, APP_PROMOTION, LEAD_GENERATION).` },
|
|
94
|
+
dailyBudget: {}, lifetimeBudget: {}, smartPlus: { type: 'boolean', desc: 'Create a Smart+ (automated) campaign.' },
|
|
95
|
+
},
|
|
96
|
+
run: async (ctx, a) => {
|
|
97
|
+
assertBornPaused(a, 'campaign');
|
|
98
|
+
const objective = a.objective ?? 'TRAFFIC';
|
|
99
|
+
if (RETIRED_OBJECTIVES[objective]) throw new AdsError('validation', `Objective ${objective}: ${RETIRED_OBJECTIVES[objective]}.`, { field: 'objective' });
|
|
100
|
+
if (!a.smartPlus && !OBJECTIVES.includes(objective)) throw new AdsError('validation', `objective must be one of ${OBJECTIVES.join(', ')}`, { field: 'objective' });
|
|
101
|
+
const budget = a.dailyBudget != null ? { budget_mode: 'BUDGET_MODE_DAY', budget: toMajor(a.dailyBudget, 'dailyBudget') }
|
|
102
|
+
: a.lifetimeBudget != null ? { budget_mode: 'BUDGET_MODE_TOTAL', budget: toMajor(a.lifetimeBudget, 'lifetimeBudget') }
|
|
103
|
+
: { budget_mode: 'BUDGET_MODE_INFINITE' };
|
|
104
|
+
const body = { advertiser_id: a.accountId, campaign_name: a.name, objective_type: objective, ...budget, operation_status: 'DISABLE', ...(a.fields ?? {}) };
|
|
105
|
+
if (a.smartPlus) {
|
|
106
|
+
if (budget.budget_mode === 'BUDGET_MODE_DAY') body.budget_mode = 'BUDGET_MODE_DYNAMIC_DAILY_BUDGET';
|
|
107
|
+
body.request_id = requestId(body);
|
|
108
|
+
}
|
|
109
|
+
body.operation_status = 'DISABLE';
|
|
110
|
+
const r = await ctx.request({ method: 'POST', path: a.smartPlus ? '/smart_plus/campaign/create/' : '/campaign/create/', json: body });
|
|
111
|
+
const id = String(r.data?.campaign_id ?? '');
|
|
112
|
+
return { id, status: STATUS.PAUSED, stored: r.data?.operation_status ?? null };
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
listAdGroups: {
|
|
116
|
+
params: { accountId: { required: true }, campaignId: {} },
|
|
117
|
+
run: async (ctx, a) => {
|
|
118
|
+
const r = await ctx.request({ path: '/adgroup/get/', query: { advertiser_id: a.accountId, page_size: Math.min(a.limit ?? 100, 1000), ...(a.campaignId ? { filtering: { campaign_ids: [String(a.campaignId)] } } : {}) } });
|
|
119
|
+
return { items: (r.data?.list ?? []).map((g) => row(g, { id: String(g.adgroup_id), name: g.adgroup_name, status: g.operation_status, campaignId: String(g.campaign_id), budget: g.budget, optimizationGoal: g.optimization_goal, billingEvent: g.billing_event }, a)) };
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
createAdGroup: {
|
|
123
|
+
params: {
|
|
124
|
+
accountId: { required: true }, campaignId: { required: true }, name: { required: true },
|
|
125
|
+
dailyBudget: {}, lifetimeBudget: {}, locationIds: { type: 'array', required: true, desc: 'Location ids from searchTargeting type "locations".' },
|
|
126
|
+
optimizationGoal: { type: 'string', desc: 'Default CLICK.' }, bidPrice: { type: 'number' }, pixelId: { type: 'string' }, optimizationEvent: { type: 'string' },
|
|
127
|
+
placements: { type: 'array', desc: 'Default ["PLACEMENT_TIKTOK"].' }, ageGroups: { type: 'array' }, gender: { type: 'string' }, interestCategoryIds: { type: 'array' },
|
|
128
|
+
scheduleStartTime: { type: 'string', desc: '"YYYY-MM-DD HH:MM:SS" (UTC); default now.' }, scheduleEndTime: { type: 'string' },
|
|
129
|
+
smartPlus: { type: 'boolean' },
|
|
130
|
+
},
|
|
131
|
+
run: async (ctx, a) => {
|
|
132
|
+
assertBornPaused(a, 'ad group');
|
|
133
|
+
const goal = a.optimizationGoal ?? 'CLICK';
|
|
134
|
+
const billing = BILLING_FOR_GOAL[goal];
|
|
135
|
+
if (!billing) throw new AdsError('validation', `Unknown optimizationGoal ${goal}. Known: ${Object.keys(BILLING_FOR_GOAL).join(', ')}`, { field: 'optimizationGoal' });
|
|
136
|
+
if (['CONVERT', 'VALUE'].includes(goal) && (!a.pixelId || !a.optimizationEvent)) throw new AdsError('validation', `Goal ${goal} needs pixelId and optimizationEvent.`, { field: 'pixelId' });
|
|
137
|
+
if (a.pixelId && !['CONVERT', 'VALUE', 'TRAFFIC_LANDING_PAGE_VIEW'].includes(goal)) throw new AdsError('validation', `A pixel only applies to conversion goals, not ${goal}.`, { field: 'pixelId' });
|
|
138
|
+
if (a.dailyBudget == null && a.lifetimeBudget == null) throw new AdsError('validation', 'An ad group needs dailyBudget or lifetimeBudget.', { field: 'dailyBudget' });
|
|
139
|
+
if ((a.locationIds ?? []).length > 3000) throw new AdsError('validation', 'At most 3000 locations.', { field: 'locationIds' });
|
|
140
|
+
const now = new Date(Date.now() + 5 * 60000).toISOString().slice(0, 19).replace('T', ' ');
|
|
141
|
+
const body = {
|
|
142
|
+
advertiser_id: a.accountId, campaign_id: String(a.campaignId), adgroup_name: a.name,
|
|
143
|
+
budget_mode: a.dailyBudget != null ? 'BUDGET_MODE_DAY' : 'BUDGET_MODE_TOTAL', budget: toMajor(a.dailyBudget ?? a.lifetimeBudget, 'dailyBudget'),
|
|
144
|
+
schedule_type: a.scheduleEndTime ? 'SCHEDULE_START_END' : 'SCHEDULE_FROM_NOW', schedule_start_time: a.scheduleStartTime ?? now, ...(a.scheduleEndTime ? { schedule_end_time: a.scheduleEndTime } : {}),
|
|
145
|
+
optimization_goal: goal, billing_event: billing, bid_type: a.bidPrice != null ? 'BID_TYPE_CUSTOM' : 'BID_TYPE_NO_BID',
|
|
146
|
+
...(a.bidPrice != null ? { [billing === 'OCPM' ? 'conversion_bid_price' : 'bid_price']: toMajor(a.bidPrice, 'bidPrice') } : {}),
|
|
147
|
+
pacing: 'PACING_MODE_SMOOTH', placement_type: 'PLACEMENT_TYPE_NORMAL', placements: a.placements ?? ['PLACEMENT_TIKTOK'], promotion_type: 'WEBSITE',
|
|
148
|
+
location_ids: a.locationIds.map(String),
|
|
149
|
+
...(a.ageGroups ? { age_groups: a.ageGroups } : {}), ...(a.gender ? { gender: a.gender } : {}), ...(a.interestCategoryIds ? { interest_category_ids: a.interestCategoryIds } : {}),
|
|
150
|
+
...(a.pixelId ? { pixel_id: a.pixelId, optimization_event: a.optimizationEvent } : {}),
|
|
151
|
+
...(a.fields ?? {}),
|
|
152
|
+
operation_status: 'DISABLE',
|
|
153
|
+
};
|
|
154
|
+
if (a.smartPlus) body.request_id = requestId(body);
|
|
155
|
+
const r = await ctx.request({ method: 'POST', path: a.smartPlus ? '/smart_plus/adgroup/create/' : '/adgroup/create/', json: body });
|
|
156
|
+
return { id: String(r.data?.adgroup_id ?? ''), status: STATUS.PAUSED };
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
updateAdGroup: {
|
|
160
|
+
params: { accountId: { required: true }, id: { required: true }, name: {}, bidPrice: { type: 'number' }, locationIds: { type: 'array' } },
|
|
161
|
+
run: async (ctx, a) => {
|
|
162
|
+
const r = await ctx.request({ path: '/adgroup/get/', query: { advertiser_id: a.accountId, filtering: { adgroup_ids: [String(a.id)] } } });
|
|
163
|
+
const cur = r.data?.list?.[0];
|
|
164
|
+
if (!cur) throw new AdsError('not_found', `Ad group ${a.id} not found.`);
|
|
165
|
+
if (/SMART_PLUS/.test(cur.campaign_automation_type ?? '')) throw new AdsError('refused', 'Smart+ ad groups are edited through the Smart+ endpoints.');
|
|
166
|
+
if (cur.operation_status === 'ENABLE') requireConfirm(a, 'Editing a live ad group');
|
|
167
|
+
const body = { ...cur, advertiser_id: a.accountId, adgroup_id: String(a.id), ...(a.name ? { adgroup_name: a.name } : {}), ...(a.locationIds ? { location_ids: a.locationIds.map(String) } : {}), ...(a.fields ?? {}) };
|
|
168
|
+
if (a.bidPrice != null) body[cur.billing_event === 'OCPM' ? 'conversion_bid_price' : 'bid_price'] = toMajor(a.bidPrice, 'bidPrice');
|
|
169
|
+
if (body.bid_type === 'BID_TYPE_NO_BID') { delete body.bid_price; delete body.conversion_bid_price; }
|
|
170
|
+
for (const k of ['operation_status', 'secondary_status', 'create_time', 'modify_time', 'campaign_automation_type']) delete body[k];
|
|
171
|
+
await ctx.request({ method: 'POST', path: '/adgroup/update/', json: body });
|
|
172
|
+
return { id: String(a.id) };
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
listAds: {
|
|
176
|
+
params: { accountId: { required: true }, adGroupId: {} },
|
|
177
|
+
run: async (ctx, a) => {
|
|
178
|
+
const r = await ctx.request({ path: '/ad/get/', query: { advertiser_id: a.accountId, page_size: Math.min(a.limit ?? 100, 1000), ...(a.adGroupId ? { filtering: { adgroup_ids: [String(a.adGroupId)] } } : {}) } });
|
|
179
|
+
return { items: (r.data?.list ?? []).map((x) => row(x, { id: String(x.ad_id), name: x.ad_name, status: x.operation_status, adGroupId: String(x.adgroup_id), text: x.ad_text, videoId: x.video_id }, a)) };
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
uploadAsset: {
|
|
183
|
+
params: { accountId: { required: true }, url: { type: 'string', required: true }, kind: { type: 'string', enum: ['image', 'video'] }, fileName: { type: 'string', desc: 'Must be unique per advertiser.' } },
|
|
184
|
+
run: async (ctx, a) => {
|
|
185
|
+
const kind = a.kind ?? (/\.(mp4|mov|webm)(\?|$)/i.test(a.url) ? 'video' : 'image');
|
|
186
|
+
const fileName = a.fileName ?? `upload-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
187
|
+
const r = await ctx.request({ method: 'POST', path: kind === 'video' ? '/file/video/ad/upload/' : '/file/image/ad/upload/',
|
|
188
|
+
json: { advertiser_id: a.accountId, upload_type: 'UPLOAD_BY_URL', file_name: fileName, [kind === 'video' ? 'video_url' : 'image_url']: a.url } });
|
|
189
|
+
const d = Array.isArray(r.data) ? r.data[0] : r.data;
|
|
190
|
+
const out = kind === 'video'
|
|
191
|
+
? { kind, videoId: d?.video_id, coverUrl: d?.video_cover_url, width: d?.width, height: d?.height, duration: d?.duration }
|
|
192
|
+
: { kind, imageId: d?.image_id, url: d?.image_url };
|
|
193
|
+
if (d?.displayable === false) out.warning = 'TikTok marked this file as not displayable: an ad built from it will be refused (use at least 720x1280).';
|
|
194
|
+
if (kind === 'video') out.note = 'A video ad also needs a cover image: upload coverUrl as an image and pass its imageId to createAd.';
|
|
195
|
+
return out;
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
createAd: {
|
|
199
|
+
params: {
|
|
200
|
+
accountId: { required: true }, adGroupId: { required: true }, name: { required: true },
|
|
201
|
+
identityId: { type: 'string', required: true }, identityType: { type: 'string', required: true, desc: 'CUSTOMIZED_USER, AUTH_CODE, TT_USER, BC_AUTH_TT or TTS_TT.' },
|
|
202
|
+
text: { type: 'string', desc: 'Ad text.' }, landingPageUrl: { type: 'string' }, cta: { type: 'string', desc: 'Default LEARN_MORE.' },
|
|
203
|
+
videoId: { type: 'string' }, coverImageId: { type: 'string', desc: 'Required with videoId.' }, imageIds: { type: 'array' },
|
|
204
|
+
tiktokItemId: { type: 'string', desc: 'Spark ad: promote an existing TikTok post (identity AUTH_CODE, TT_USER or BC_AUTH_TT).' },
|
|
205
|
+
smartPlus: { type: 'boolean' },
|
|
206
|
+
},
|
|
207
|
+
run: async (ctx, a) => {
|
|
208
|
+
assertBornPaused(a, 'ad');
|
|
209
|
+
if (a.tiktokItemId && a.videoId) throw new AdsError('validation', 'Use tiktokItemId (Spark) or videoId, not both.', { field: 'videoId' });
|
|
210
|
+
if (a.tiktokItemId && !['AUTH_CODE', 'TT_USER', 'BC_AUTH_TT'].includes(a.identityType)) throw new AdsError('validation', 'Spark ads need identityType AUTH_CODE, TT_USER or BC_AUTH_TT.', { field: 'identityType' });
|
|
211
|
+
if (a.videoId && !a.coverImageId) throw new AdsError('validation', 'A video ad needs coverImageId (upload the video\'s cover as an image).', { field: 'coverImageId' });
|
|
212
|
+
checkLength('text', a.text, 100);
|
|
213
|
+
const creative = {
|
|
214
|
+
ad_name: a.name, identity_id: a.identityId, identity_type: a.identityType, ad_format: a.imageIds && !a.videoId ? 'SINGLE_IMAGE' : 'SINGLE_VIDEO',
|
|
215
|
+
ad_text: a.text, call_to_action: a.cta ?? 'LEARN_MORE', landing_page_url: a.landingPageUrl,
|
|
216
|
+
...(a.videoId ? { video_id: a.videoId, image_ids: [a.coverImageId] } : {}), ...(a.imageIds ? { image_ids: a.imageIds } : {}),
|
|
217
|
+
...(a.tiktokItemId ? { tiktok_item_id: a.tiktokItemId } : {}), ...(a.fields ?? {}),
|
|
218
|
+
operation_status: 'DISABLE',
|
|
219
|
+
};
|
|
220
|
+
const body = { advertiser_id: a.accountId, adgroup_id: String(a.adGroupId), creatives: [creative], operation_status: 'DISABLE' };
|
|
221
|
+
if (a.smartPlus) { delete creative.operation_status; delete body.operation_status; body.request_id = requestId(body); }
|
|
222
|
+
const r = await ctx.request({ method: 'POST', path: a.smartPlus ? '/smart_plus/ad/create/' : '/ad/create/', json: body });
|
|
223
|
+
const d = r.data?.creatives?.[0] ?? r.data?.list?.[0] ?? {};
|
|
224
|
+
const id = String(d.ad_id ?? r.data?.ad_ids?.[0] ?? '');
|
|
225
|
+
const out = { id, status: STATUS.PAUSED };
|
|
226
|
+
if (d.operation_status && d.operation_status !== 'DISABLE') out.warning = `TikTok stored this ad as ${d.operation_status}; pause it now with setStatus.`;
|
|
227
|
+
return out;
|
|
228
|
+
},
|
|
229
|
+
},
|
|
230
|
+
listAudiences: {
|
|
231
|
+
params: { accountId: { required: true } },
|
|
232
|
+
run: async (ctx, a) => {
|
|
233
|
+
const r = await ctx.request({ path: '/dmp/custom_audience/list/', query: { advertiser_id: a.accountId, page: a.cursor ?? 1, page_size: Math.min(a.limit ?? 100, 100) } });
|
|
234
|
+
return { items: (r.data?.list ?? []).map((x) => row(x, { id: String(x.custom_audience_id ?? x.audience_id), name: x.name, type: x.audience_type, size: x.cover_num, valid: x.is_valid }, a)) };
|
|
235
|
+
},
|
|
236
|
+
},
|
|
237
|
+
createAudience: {
|
|
238
|
+
params: { accountId: { required: true }, name: { required: true }, kind: { type: 'string', enum: ['lookalike', 'rule'], required: true }, sourceAudienceId: { type: 'string', desc: 'Lookalike seed.' }, locations: { type: 'array' }, ruleSpec: { type: 'object', desc: 'Rule audiences: TikTok rule_spec.' }, audienceType: { type: 'string' } },
|
|
239
|
+
run: async (ctx, a) => {
|
|
240
|
+
checkLength('name', a.name, 128);
|
|
241
|
+
if (a.kind === 'lookalike') {
|
|
242
|
+
if (!a.sourceAudienceId) throw new AdsError('validation', 'A lookalike needs sourceAudienceId.', { field: 'sourceAudienceId' });
|
|
243
|
+
const r = await ctx.request({ method: 'POST', path: '/dmp/custom_audience/lookalike/create/', json: { advertiser_id: a.accountId, custom_audience_name: a.name, source_audience_id: a.sourceAudienceId, lookalike_spec: { location_ids: a.locations ?? [], audience_size: 'NARROW' }, ...(a.fields ?? {}) } });
|
|
244
|
+
return { id: String(r.data?.custom_audience_id ?? ''), note: 'Audiences take about 48 hours to become valid.' };
|
|
245
|
+
}
|
|
246
|
+
if (!a.ruleSpec || !a.audienceType) throw new AdsError('validation', 'A rule audience needs audienceType and ruleSpec.', { field: 'ruleSpec' });
|
|
247
|
+
const r = await ctx.request({ method: 'POST', path: '/dmp/custom_audience/rule/create/', json: { advertiser_id: a.accountId, custom_audience_name: a.name, audience_type: a.audienceType, rule_spec: a.ruleSpec, ...(a.fields ?? {}) } });
|
|
248
|
+
return { id: String(r.data?.custom_audience_id ?? ''), note: 'Audiences take about 48 hours to become valid.' };
|
|
249
|
+
},
|
|
250
|
+
},
|
|
251
|
+
setStatus: {
|
|
252
|
+
params: { accountId: { required: true }, id: { required: true }, level: {}, status: { required: true }, smartPlus: { type: 'boolean' } },
|
|
253
|
+
run: async (ctx, a) => {
|
|
254
|
+
const status = gateStatus(a);
|
|
255
|
+
if (status === STATUS.ARCHIVED) throw new AdsError('validation', 'TikTok has no archive; use deleteObject.', { field: 'status' });
|
|
256
|
+
const level = pickLevel(a, LEVEL, ctx.platform);
|
|
257
|
+
await ctx.request({ method: 'POST', path: a.smartPlus ? `/smart_plus/${level}/status/update/` : `/${level}/status/update/`,
|
|
258
|
+
json: { advertiser_id: a.accountId, [`${level}_ids`]: [String(a.id)], operation_status: status === STATUS.ACTIVE ? 'ENABLE' : 'DISABLE' } });
|
|
259
|
+
return { id: String(a.id), status };
|
|
260
|
+
},
|
|
261
|
+
},
|
|
262
|
+
setBudget: {
|
|
263
|
+
params: { accountId: { required: true }, id: { required: true }, level: { desc: 'campaign (default) or adGroup.' }, amount: { required: true } },
|
|
264
|
+
run: async (ctx, a) => {
|
|
265
|
+
const level = pickLevel({ level: a.level ?? 'campaign' }, { campaign: 'campaign', adGroup: 'adgroup' }, ctx.platform);
|
|
266
|
+
const r = await ctx.request({ path: `/${level}/get/`, query: { advertiser_id: a.accountId, filtering: { [`${level}_ids`]: [String(a.id)] } } });
|
|
267
|
+
const cur = r.data?.list?.[0];
|
|
268
|
+
if (!cur) throw new AdsError('not_found', `${level} ${a.id} not found.`);
|
|
269
|
+
gateBudget(a, cur.budget);
|
|
270
|
+
await ctx.request({ method: 'POST', path: `/${level}/update/`, json: { advertiser_id: a.accountId, [`${level}_id`]: String(a.id), budget: toMajor(a.amount), budget_mode: cur.budget_mode } });
|
|
271
|
+
return { id: String(a.id), budget: toMajor(a.amount), previous: cur.budget };
|
|
272
|
+
},
|
|
273
|
+
},
|
|
274
|
+
deleteObject: {
|
|
275
|
+
params: { accountId: { required: true }, id: { required: true }, level: { required: true }, confirm: {}, confirmName: {}, confirmChildren: {} },
|
|
276
|
+
run: async (ctx, a) => {
|
|
277
|
+
const level = pickLevel(a, LEVEL, ctx.platform);
|
|
278
|
+
const cur = (await ctx.request({ path: `/${level}/get/`, query: { advertiser_id: a.accountId, filtering: { [`${level}_ids`]: [String(a.id)] } } })).data?.list?.[0];
|
|
279
|
+
if (!cur) throw new AdsError('not_found', `${level} ${a.id} not found.`);
|
|
280
|
+
const children = [];
|
|
281
|
+
if (level === 'campaign') children.push({ label: 'ad groups', count: (await ctx.request({ path: '/adgroup/get/', query: { advertiser_id: a.accountId, filtering: { campaign_ids: [String(a.id)] } } })).data?.list?.length ?? 0 });
|
|
282
|
+
if (level === 'adgroup') children.push({ label: 'ads', count: (await ctx.request({ path: '/ad/get/', query: { advertiser_id: a.accountId, filtering: { adgroup_ids: [String(a.id)] } } })).data?.list?.length ?? 0 });
|
|
283
|
+
gateDelete(a, { what: a.level, name: cur[`${level}_name`], children, live: cur.operation_status === 'ENABLE' });
|
|
284
|
+
await ctx.request({ method: 'POST', path: `/${level}/status/update/`, json: { advertiser_id: a.accountId, [`${level}_ids`]: [String(a.id)], operation_status: 'DELETE' } });
|
|
285
|
+
return { id: String(a.id), deleted: true };
|
|
286
|
+
},
|
|
287
|
+
},
|
|
288
|
+
report: {
|
|
289
|
+
params: {
|
|
290
|
+
accountId: { required: true }, since: {}, until: {},
|
|
291
|
+
level: { type: 'string', enum: ['advertiser', 'campaign', 'adGroup', 'ad'], desc: 'Default campaign.' },
|
|
292
|
+
metrics: { type: 'array' }, dimensions: { type: 'array', desc: 'Default [<level>_id]; add "stat_time_day" for daily rows.' },
|
|
293
|
+
},
|
|
294
|
+
run: async (ctx, a) => {
|
|
295
|
+
const { since, until } = dateRange(a);
|
|
296
|
+
const lv = { advertiser: ['AUCTION_ADVERTISER', 'advertiser_id'], campaign: ['AUCTION_CAMPAIGN', 'campaign_id'], adGroup: ['AUCTION_ADGROUP', 'adgroup_id'], ad: ['AUCTION_AD', 'ad_id'] }[a.level ?? 'campaign'];
|
|
297
|
+
if (!lv) throw new AdsError('validation', 'level must be advertiser, campaign, adGroup or ad', { field: 'level' });
|
|
298
|
+
const r = await ctx.request({ path: '/report/integrated/get/', query: {
|
|
299
|
+
advertiser_id: a.accountId, report_type: 'BASIC', data_level: lv[0], dimensions: a.dimensions ?? [lv[1]],
|
|
300
|
+
metrics: a.metrics ?? ['spend', 'impressions', 'clicks', 'ctr', 'cpc', 'cpm', 'conversion'],
|
|
301
|
+
start_date: since, end_date: until, page: a.cursor ?? 1, page_size: Math.min(a.limit ?? 100, 1000) } });
|
|
302
|
+
const pi = r.data?.page_info;
|
|
303
|
+
return { rows: r.data?.list ?? [], ...(pi && pi.total_page > pi.page ? { partial: true, next: String(pi.page + 1) } : {}) };
|
|
304
|
+
},
|
|
305
|
+
},
|
|
306
|
+
searchTargeting: {
|
|
307
|
+
params: { accountId: { required: true }, type: { required: true, enum: ['locations', 'interests', 'languages', 'keywords', 'hashtags'] }, query: { required: true }, objective: { type: 'string', desc: 'For locations: the campaign objective (default TRAFFIC).' } },
|
|
308
|
+
run: async (ctx, a) => {
|
|
309
|
+
const q = String(a.query).toLowerCase();
|
|
310
|
+
const base = { advertiser_id: a.accountId };
|
|
311
|
+
const filt = (list, nameKey = 'name') => (list ?? []).filter((x) => String(x[nameKey] ?? '').toLowerCase().includes(q)).slice(0, a.limit ?? 50);
|
|
312
|
+
switch (a.type) {
|
|
313
|
+
case 'locations': {
|
|
314
|
+
const r = await ctx.request({ path: '/tool/region/', query: { ...base, placements: ['PLACEMENT_TIKTOK'], objective_type: a.objective ?? 'TRAFFIC' } });
|
|
315
|
+
return { items: filt(r.data?.region_info).map((x) => ({ id: String(x.location_id ?? x.region_id), name: x.name, level: x.level ?? x.region_level })) };
|
|
316
|
+
}
|
|
317
|
+
case 'interests': {
|
|
318
|
+
const r = await ctx.request({ path: '/tool/interest_category/', query: base });
|
|
319
|
+
return { items: filt(r.data?.interest_categories, 'interest_category_name').map((x) => ({ id: String(x.interest_category_id), name: x.interest_category_name })) };
|
|
320
|
+
}
|
|
321
|
+
case 'languages': {
|
|
322
|
+
const r = await ctx.request({ path: '/tool/language/', query: base });
|
|
323
|
+
return { items: filt(r.data?.languages).map((x) => ({ id: x.code, name: x.name })) };
|
|
324
|
+
}
|
|
325
|
+
case 'keywords': {
|
|
326
|
+
const r = await ctx.request({ path: '/tool/interest_keyword/recommend/', query: { ...base, keyword: a.query } });
|
|
327
|
+
return { items: (r.data?.keywords ?? []).map((x) => ({ id: String(x.keyword_id), name: x.keyword })) };
|
|
328
|
+
}
|
|
329
|
+
case 'hashtags': {
|
|
330
|
+
const r = await ctx.request({ path: '/tool/hashtag/recommend/', query: { ...base, keyword: a.query } });
|
|
331
|
+
return { items: (r.data?.hashtags ?? []).map((x) => ({ id: String(x.hashtag_id ?? x.id), name: x.hashtag_name ?? x.name })) };
|
|
332
|
+
}
|
|
333
|
+
default: throw new AdsError('validation', 'Unknown type', { field: 'type' });
|
|
334
|
+
}
|
|
335
|
+
},
|
|
336
|
+
},
|
|
337
|
+
},
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Smart+ requests carry an idempotency key: a decimal string of a positive signed 64-bit
|
|
342
|
+
* integer (UUIDs are refused). Derived from the payload so a retry reuses the same key.
|
|
343
|
+
*/
|
|
344
|
+
export function requestId(payload) {
|
|
345
|
+
const h = createHash('sha256').update(JSON.stringify(payload)).digest();
|
|
346
|
+
const n = h.readBigUInt64BE(0) & 0x7fffffffffffffffn;
|
|
347
|
+
return n.toString();
|
|
348
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { definePlatform, row } from '../platform.js';
|
|
2
|
+
import { AdsError } from '../errors.js';
|
|
3
|
+
import { assertBornPaused, gateStatus, requireConfirm, checkLength, STATUS } from '../safety.js';
|
|
4
|
+
import { toMajor } from '../money.js';
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
const V3 = 'https://api.thetradedesk.com/v3';
|
|
8
|
+
const WF = 'https://api.thetradedesk.com/workflows';
|
|
9
|
+
|
|
10
|
+
const query = (ctx, path, json) => ctx.request({ method: 'POST', base: V3, path, json: { PageStartIndex: 0, PageSize: 250, ...json } });
|
|
11
|
+
|
|
12
|
+
export default definePlatform({
|
|
13
|
+
id: 'trade_desk',
|
|
14
|
+
label: 'The Trade Desk',
|
|
15
|
+
money: 'major',
|
|
16
|
+
credentials: [
|
|
17
|
+
{ name: 'token', required: true, env: 'TTD_API_TOKEN', desc: 'Platform API token (Access Management > Generate Token).' },
|
|
18
|
+
{ name: 'partnerId', required: true, env: 'TTD_PARTNER_ID' },
|
|
19
|
+
],
|
|
20
|
+
baseUrl: V3,
|
|
21
|
+
authHeaders: (c) => ({ 'TTD-Auth': c.token }),
|
|
22
|
+
parseError: (status, body) => {
|
|
23
|
+
const message = body?.Message ?? body?.detail ?? body?.title ?? body?.message;
|
|
24
|
+
if (status === 403) return { kind: 'permission', message, userMessage: `The Trade Desk refused (no access, or the id does not exist). ${message ?? ''}`.trim() };
|
|
25
|
+
return message ? { message } : null;
|
|
26
|
+
},
|
|
27
|
+
notes: [
|
|
28
|
+
'accountId is the advertiser id (listAccounts).',
|
|
29
|
+
'Campaigns have no status: they deliver through enabled ad groups. Pausing a campaign pauses all its ad groups.',
|
|
30
|
+
'Archiving is permanent.',
|
|
31
|
+
'Every ad group budget change needs confirm.',
|
|
32
|
+
],
|
|
33
|
+
setup: {
|
|
34
|
+
app: 'No developer app: generate a Platform API token in The Trade Desk (Access Management > Generate Token, application "Platform API").',
|
|
35
|
+
scopes: ['(token, no scopes)'],
|
|
36
|
+
review: 'API access comes with your partner seat; tokens last one week to one year.',
|
|
37
|
+
hosted: { connect: 'own', note: 'The Trade Desk issues API tokens per partner seat.' },
|
|
38
|
+
docs: 'https://partner.thetradedesk.com/v3/portal/api/doc/ApiOverview',
|
|
39
|
+
},
|
|
40
|
+
ops: {
|
|
41
|
+
listAccounts: {
|
|
42
|
+
run: async (ctx, a) => {
|
|
43
|
+
const c = await ctx.creds();
|
|
44
|
+
const r = await query(ctx, '/advertiser/query/partner', { PartnerId: c.partnerId, Availabilities: ['Available'] });
|
|
45
|
+
return { items: (r.Result ?? []).map((x) => row(x, { id: x.AdvertiserId, name: x.AdvertiserName, currency: x.CurrencyCode }, a)) };
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
listCampaigns: {
|
|
49
|
+
params: { accountId: { required: true, desc: 'Advertiser id.' } },
|
|
50
|
+
run: async (ctx, a) => ({ items: ((await query(ctx, '/campaign/query/advertiser', { AdvertiserId: a.accountId })).Result ?? []).map((c) => row(c, { id: c.CampaignId, name: c.CampaignName, availability: c.Availability, budget: c.Budget?.Amount, currency: c.Budget?.CurrencyCode, start: c.StartDate, end: c.EndDate }, a)) }),
|
|
51
|
+
},
|
|
52
|
+
getCampaign: {
|
|
53
|
+
params: { id: { required: true } },
|
|
54
|
+
run: async (ctx, a) => { const c = await ctx.request({ path: `/campaign/${a.id}` }); return row(c, { id: c.CampaignId, name: c.CampaignName, availability: c.Availability, budget: c.Budget?.Amount, start: c.StartDate, end: c.EndDate }, a); },
|
|
55
|
+
},
|
|
56
|
+
createCampaign: {
|
|
57
|
+
params: { accountId: { required: true }, name: { required: true }, channel: { type: 'string', desc: 'Display (default), Video, Audio, TV, NativeDisplay, DOOH.' }, lifetimeBudget: {}, startDate: { type: 'string' }, endDate: { type: 'string' } },
|
|
58
|
+
run: async (ctx, a) => {
|
|
59
|
+
assertBornPaused(a, 'campaign');
|
|
60
|
+
checkLength('name', a.name, 256);
|
|
61
|
+
const r = await ctx.request({ method: 'POST', base: WF, path: '/campaign', json: { primaryInput: {
|
|
62
|
+
advertiserId: a.accountId, name: a.name, primaryChannel: a.channel ?? 'Display', primaryGoal: { maximizeReach: true },
|
|
63
|
+
startDateInUtc: a.startDate ? new Date(a.startDate).toISOString() : new Date().toISOString(), ...(a.endDate ? { endDateInUtc: new Date(a.endDate).toISOString() } : {}),
|
|
64
|
+
...(a.lifetimeBudget != null ? { budget: { pacingMode: 'PaceEvenly', budgetInAdvertiserCurrency: toMajor(a.lifetimeBudget, 'lifetimeBudget') } } : {}), ...(a.fields ?? {}) } } });
|
|
65
|
+
return { id: r.campaign?.id ?? r.id, status: STATUS.PAUSED, note: 'Created with no ad groups, so it cannot spend until an ad group is enabled.' };
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
listAdGroups: {
|
|
69
|
+
params: { campaignId: { required: true } },
|
|
70
|
+
run: async (ctx, a) => ({ items: ((await query(ctx, '/adgroup/query/campaign', { CampaignId: a.campaignId })).Result ?? []).map((g) => row(g, { id: g.AdGroupId, name: g.AdGroupName, status: g.IsEnabled ? STATUS.ACTIVE : STATUS.PAUSED, budget: g.RTBAttributes?.BudgetSettings?.Budget?.Amount, baseBid: g.RTBAttributes?.BaseBidCPM?.Amount }, a)) }),
|
|
71
|
+
},
|
|
72
|
+
listAds: {
|
|
73
|
+
params: { accountId: { required: true } },
|
|
74
|
+
run: async (ctx, a) => ({ items: ((await query(ctx, '/creative/query/advertiser', { AdvertiserId: a.accountId })).Result ?? []).map((x) => row(x, { id: x.CreativeId, name: x.CreativeName, availability: x.Availability }, a)) }),
|
|
75
|
+
},
|
|
76
|
+
setStatus: {
|
|
77
|
+
params: { id: { required: true }, level: { desc: 'adGroup (default) or campaign (pause only).' }, status: { required: true } },
|
|
78
|
+
run: async (ctx, a) => {
|
|
79
|
+
const status = gateStatus(a);
|
|
80
|
+
if (status === STATUS.ARCHIVED) return ctx.platform.ops.deleteObject.run(ctx, a);
|
|
81
|
+
if ((a.level ?? 'adGroup') === 'campaign') {
|
|
82
|
+
if (status === STATUS.ACTIVE) throw new AdsError('validation', 'A campaign cannot be turned on as a whole: enable its ad groups one by one.', { field: 'status' });
|
|
83
|
+
const groups = ((await query(ctx, '/adgroup/query/campaign', { CampaignId: a.id })).Result ?? []).filter((g) => g.IsEnabled);
|
|
84
|
+
for (const g of groups) await ctx.request({ method: 'PATCH', base: WF, path: '/adgroup', json: { id: g.AdGroupId, primaryInput: { isEnabled: false } } });
|
|
85
|
+
return { id: a.id, status, pausedAdGroups: groups.map((g) => g.AdGroupId) };
|
|
86
|
+
}
|
|
87
|
+
await ctx.request({ method: 'PATCH', base: WF, path: '/adgroup', json: { id: a.id, primaryInput: { isEnabled: status === STATUS.ACTIVE } } });
|
|
88
|
+
return { id: a.id, status };
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
setBudget: {
|
|
92
|
+
params: { id: { required: true, desc: 'Ad group id.' }, amount: { required: true }, daily: { type: 'boolean', desc: 'Set the daily target instead of the lifetime budget.' } },
|
|
93
|
+
run: async (ctx, a) => {
|
|
94
|
+
const g = await ctx.request({ path: `/adgroup/${a.id}` });
|
|
95
|
+
const cur = a.daily ? g.RTBAttributes?.BudgetSettings?.DailyBudget?.Amount : g.RTBAttributes?.BudgetSettings?.Budget?.Amount;
|
|
96
|
+
requireConfirm(a, `Changing the ${a.daily ? 'daily' : 'lifetime'} budget from ${cur ?? 'unset'} to ${a.amount}`);
|
|
97
|
+
await ctx.request({ method: 'PATCH', base: WF, path: '/adgroup', json: { id: a.id, primaryInput: { budget: a.daily ? { dailyTargetInAdvertiserCurrency: toMajor(a.amount) } : { budgetInAdvertiserCurrency: toMajor(a.amount) } } } });
|
|
98
|
+
return { id: a.id, budget: toMajor(a.amount), previous: cur ?? null };
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
deleteObject: {
|
|
102
|
+
params: { id: { required: true }, level: { required: true, desc: 'campaign or adGroup (archived, permanently).' }, confirm: {} },
|
|
103
|
+
run: async (ctx, a) => {
|
|
104
|
+
if (!['campaign', 'adGroup'].includes(a.level)) throw new AdsError('validation', 'level must be campaign or adGroup.', { field: 'level' });
|
|
105
|
+
requireConfirm(a, `Archiving this ${a.level} (permanent)`);
|
|
106
|
+
await ctx.request({ method: 'POST', base: WF, path: `/${a.level === 'campaign' ? 'campaign' : 'adgroup'}/archive`, query: { forceArchive: false }, json: [a.id] });
|
|
107
|
+
return { id: a.id, status: STATUS.ARCHIVED };
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
});
|