pinterest-ads-cli 1.0.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 ADDED
@@ -0,0 +1,201 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to the Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by the Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding any notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. Please also get an in-place
186
+ temporary or permanent copyright header for your project as
187
+ described on https://www.apache.org/legal/src-headers.html
188
+
189
+ Copyright 2026 Benn Huang
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,429 @@
1
+ # pinterest-ads-cli
2
+
3
+ Give AI agents direct access to Pinterest Ads data. One command to query campaigns, audiences, catalogs, trends, and pull performance analytics -- no SDK, no docs to read, no tokens wasted on boilerplate.
4
+
5
+ **Works with:** OpenClaw, Claude Code, Cursor, Codex, and any agent that can run shell commands.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install -g pinterest-ads-cli
11
+ ```
12
+
13
+ Or run directly with npx:
14
+
15
+ ```bash
16
+ npx pinterest-ads-cli --help
17
+ ```
18
+
19
+ ## How it works
20
+
21
+ Built on the official [Pinterest REST API v5](https://developers.pinterest.com/docs/api/v5/). Handles OAuth2 Bearer token authentication. Every command outputs structured JSON to stdout, ready for agents to parse without extra processing.
22
+
23
+ Core endpoints covered:
24
+
25
+ - **[Ad Accounts](https://developers.pinterest.com/docs/api/v5/#tag/ad_accounts)** -- list and inspect ad accounts
26
+ - **[Campaigns](https://developers.pinterest.com/docs/api/v5/#tag/campaigns)** -- list campaigns
27
+ - **[Ad Groups](https://developers.pinterest.com/docs/api/v5/#tag/ad_groups)** -- list ad groups
28
+ - **[Ads](https://developers.pinterest.com/docs/api/v5/#tag/ads)** -- list ads
29
+ - **[Keywords](https://developers.pinterest.com/docs/api/v5/#tag/keywords)** -- list targeting keywords
30
+ - **[Audiences](https://developers.pinterest.com/docs/api/v5/#tag/audiences)** -- list audiences and customer lists
31
+ - **[Conversion Tags](https://developers.pinterest.com/docs/api/v5/#tag/conversion_tags)** -- list conversion tracking tags
32
+ - **[Billing](https://developers.pinterest.com/docs/api/v5/#tag/billing)** -- billing profiles and order lines
33
+ - **[Lead Forms](https://developers.pinterest.com/docs/api/v5/#tag/lead_forms)** -- lead generation forms
34
+ - **[Catalogs](https://developers.pinterest.com/docs/api/v5/#tag/catalogs)** -- product catalogs and feeds (Pinterest Shopping)
35
+ - **[Trends](https://developers.pinterest.com/docs/api/v5/#tag/trends)** -- trending search terms by region
36
+ - **Analytics** -- account, campaign, ad group, and ad level performance metrics
37
+
38
+ ## Setup
39
+
40
+ ### Step 1: Create a Pinterest app
41
+
42
+ 1. Go to [Pinterest Developer Apps](https://developers.pinterest.com/apps/) and sign in.
43
+ 2. Create a new app. You need a Pinterest Business account.
44
+ 3. Note your **App ID** and **App Secret**.
45
+
46
+ ### Step 2: Get an OAuth2 access token
47
+
48
+ Use the Pinterest OAuth2 flow to get an access token with the `ads:read` scope. See [Pinterest OAuth docs](https://developers.pinterest.com/docs/getting-started/authentication/).
49
+
50
+ For testing, you can generate a token from the [Pinterest API Explorer](https://developers.pinterest.com/tools/api-explorer/).
51
+
52
+ ### Step 3: Place the credentials file
53
+
54
+ Choose one of these options:
55
+
56
+ ```bash
57
+ # Option A: Default path (recommended)
58
+ mkdir -p ~/.config/pinterest-ads-cli
59
+ cat > ~/.config/pinterest-ads-cli/credentials.json << EOF
60
+ {
61
+ "access_token": "YOUR_ACCESS_TOKEN"
62
+ }
63
+ EOF
64
+
65
+ # Option B: Environment variable
66
+ export PINTEREST_ADS_ACCESS_TOKEN=your_access_token
67
+
68
+ # Option C: Pass per command
69
+ pinterest-ads-cli --credentials /path/to/credentials.json accounts
70
+ ```
71
+
72
+ Credentials are resolved in this order:
73
+ 1. `--credentials <path>` flag
74
+ 2. `PINTEREST_ADS_ACCESS_TOKEN` env var
75
+ 3. `~/.config/pinterest-ads-cli/credentials.json` (auto-detected)
76
+
77
+ ### Step 4: Find your Ad Account ID
78
+
79
+ ```bash
80
+ pinterest-ads-cli accounts
81
+ ```
82
+
83
+ ## Usage
84
+
85
+ All commands output pretty-printed JSON by default. Use `--format compact` for compact single-line JSON.
86
+
87
+ Pagination uses cursor-based `--bookmark` values returned in the response.
88
+
89
+ ### accounts
90
+
91
+ List ad accounts the user has access to.
92
+
93
+ ```bash
94
+ pinterest-ads-cli accounts
95
+ pinterest-ads-cli accounts --page-size 50
96
+ ```
97
+
98
+ Options:
99
+ - `--page-size <n>` -- results per page (default 25, max 250)
100
+ - `--bookmark <cursor>` -- pagination cursor
101
+
102
+ ### account
103
+
104
+ Get details of a specific ad account.
105
+
106
+ ```bash
107
+ pinterest-ads-cli account 123456789
108
+ ```
109
+
110
+ ### campaigns
111
+
112
+ List campaigns for an ad account.
113
+
114
+ ```bash
115
+ pinterest-ads-cli campaigns 123456789
116
+ pinterest-ads-cli campaigns 123456789 --entity-statuses ACTIVE,PAUSED
117
+ pinterest-ads-cli campaigns 123456789 --order DESCENDING --page-size 100
118
+ ```
119
+
120
+ Options:
121
+ - `--campaign-ids <ids>` -- filter by campaign IDs (comma-separated, max 250)
122
+ - `--entity-statuses <statuses>` -- filter by status (comma-separated)
123
+ - `--page-size <n>` -- results per page (default 25, max 250)
124
+ - `--order <order>` -- sort order: ASCENDING or DESCENDING
125
+ - `--bookmark <cursor>` -- pagination cursor
126
+
127
+ ### adgroups
128
+
129
+ List ad groups for an ad account.
130
+
131
+ ```bash
132
+ pinterest-ads-cli adgroups 123456789
133
+ pinterest-ads-cli adgroups 123456789 --campaign-ids campaign_1,campaign_2
134
+ ```
135
+
136
+ Options:
137
+ - `--campaign-ids <ids>` -- filter by campaign IDs
138
+ - `--ad-group-ids <ids>` -- filter by ad group IDs
139
+ - `--entity-statuses <statuses>` -- filter by status
140
+ - `--page-size <n>` -- results per page (default 25, max 250)
141
+ - `--order <order>` -- sort order
142
+ - `--bookmark <cursor>` -- pagination cursor
143
+
144
+ ### ads
145
+
146
+ List ads for an ad account.
147
+
148
+ ```bash
149
+ pinterest-ads-cli ads 123456789
150
+ pinterest-ads-cli ads 123456789 --campaign-ids campaign_1 --entity-statuses ACTIVE
151
+ ```
152
+
153
+ Options:
154
+ - `--campaign-ids <ids>` -- filter by campaign IDs
155
+ - `--ad-group-ids <ids>` -- filter by ad group IDs
156
+ - `--ad-ids <ids>` -- filter by ad IDs
157
+ - `--entity-statuses <statuses>` -- filter by status
158
+ - `--page-size <n>` -- results per page (default 25, max 250)
159
+ - `--order <order>` -- sort order
160
+ - `--bookmark <cursor>` -- pagination cursor
161
+
162
+ ### keywords
163
+
164
+ List keywords for an ad account.
165
+
166
+ ```bash
167
+ pinterest-ads-cli keywords 123456789
168
+ pinterest-ads-cli keywords 123456789 --ad-group-id adgroup_1
169
+ ```
170
+
171
+ Options:
172
+ - `--ad-group-id <id>` -- filter by ad group ID
173
+ - `--page-size <n>` -- results per page (default 25, max 250)
174
+ - `--bookmark <cursor>` -- pagination cursor
175
+
176
+ ### audiences
177
+
178
+ List audiences for an ad account.
179
+
180
+ ```bash
181
+ pinterest-ads-cli audiences 123456789
182
+ ```
183
+
184
+ Options:
185
+ - `--page-size <n>` -- results per page (default 25, max 250)
186
+ - `--order <order>` -- sort order: ASCENDING or DESCENDING
187
+ - `--bookmark <cursor>` -- pagination cursor
188
+
189
+ ### customer-lists
190
+
191
+ List customer lists for an ad account.
192
+
193
+ ```bash
194
+ pinterest-ads-cli customer-lists 123456789
195
+ ```
196
+
197
+ Options:
198
+ - `--page-size <n>` -- results per page (default 25, max 250)
199
+ - `--order <order>` -- sort order: ASCENDING or DESCENDING
200
+ - `--bookmark <cursor>` -- pagination cursor
201
+
202
+ ### conversion-tags
203
+
204
+ List conversion tags for an ad account.
205
+
206
+ ```bash
207
+ pinterest-ads-cli conversion-tags 123456789
208
+ ```
209
+
210
+ ### conversion-tag
211
+
212
+ Get a specific conversion tag.
213
+
214
+ ```bash
215
+ pinterest-ads-cli conversion-tag 123456789 tag_abc
216
+ ```
217
+
218
+ ### billing-profiles
219
+
220
+ List billing profiles for an ad account.
221
+
222
+ ```bash
223
+ pinterest-ads-cli billing-profiles 123456789
224
+ pinterest-ads-cli billing-profiles 123456789 --is-active
225
+ ```
226
+
227
+ Options:
228
+ - `--is-active` -- only return active profiles
229
+ - `--page-size <n>` -- results per page (default 25, max 250)
230
+ - `--bookmark <cursor>` -- pagination cursor
231
+
232
+ ### order-lines
233
+
234
+ List order lines for an ad account.
235
+
236
+ ```bash
237
+ pinterest-ads-cli order-lines 123456789
238
+ ```
239
+
240
+ Options:
241
+ - `--page-size <n>` -- results per page (default 25, max 250)
242
+ - `--order <order>` -- sort order: ASCENDING or DESCENDING
243
+ - `--bookmark <cursor>` -- pagination cursor
244
+
245
+ ### order-line
246
+
247
+ Get a specific order line.
248
+
249
+ ```bash
250
+ pinterest-ads-cli order-line 123456789 orderline_abc
251
+ ```
252
+
253
+ ### lead-forms
254
+
255
+ List lead generation forms for an ad account.
256
+
257
+ ```bash
258
+ pinterest-ads-cli lead-forms 123456789
259
+ ```
260
+
261
+ Options:
262
+ - `--page-size <n>` -- results per page (default 25, max 250)
263
+ - `--order <order>` -- sort order: ASCENDING or DESCENDING
264
+ - `--bookmark <cursor>` -- pagination cursor
265
+
266
+ ### lead-form
267
+
268
+ Get a specific lead form.
269
+
270
+ ```bash
271
+ pinterest-ads-cli lead-form 123456789 leadform_abc
272
+ ```
273
+
274
+ ### catalogs
275
+
276
+ List catalogs.
277
+
278
+ ```bash
279
+ pinterest-ads-cli catalogs
280
+ ```
281
+
282
+ Options:
283
+ - `--page-size <n>` -- results per page (default 25, max 250)
284
+ - `--bookmark <cursor>` -- pagination cursor
285
+
286
+ ### feeds
287
+
288
+ List catalog feeds.
289
+
290
+ ```bash
291
+ pinterest-ads-cli feeds
292
+ ```
293
+
294
+ Options:
295
+ - `--page-size <n>` -- results per page (default 25, max 250)
296
+ - `--bookmark <cursor>` -- pagination cursor
297
+
298
+ ### product-groups
299
+
300
+ List product groups for an ad account.
301
+
302
+ ```bash
303
+ pinterest-ads-cli product-groups 123456789
304
+ pinterest-ads-cli product-groups 123456789 --feed-id feed_abc
305
+ ```
306
+
307
+ Options:
308
+ - `--feed-id <id>` -- filter by feed ID
309
+ - `--page-size <n>` -- results per page (default 25, max 250)
310
+ - `--bookmark <cursor>` -- pagination cursor
311
+
312
+ ### trends
313
+
314
+ Get trending search terms for a region.
315
+
316
+ ```bash
317
+ pinterest-ads-cli trends US --trend-type growing
318
+ pinterest-ads-cli trends US --trend-type monthly --interests fashion --limit 20
319
+ ```
320
+
321
+ Options:
322
+ - `--trend-type <type>` -- trend type: growing, monthly, yearly, seasonal (required)
323
+ - `--interests <interests>` -- filter by interests (comma-separated)
324
+ - `--genders <genders>` -- filter by genders (comma-separated)
325
+ - `--ages <ages>` -- filter by age groups (comma-separated)
326
+ - `--limit <n>` -- number of results (default 50)
327
+
328
+ ### analytics
329
+
330
+ Get ad account-level analytics.
331
+
332
+ ```bash
333
+ pinterest-ads-cli analytics 123456789 \
334
+ --start-date 2026-03-01 \
335
+ --end-date 2026-03-15 \
336
+ --columns SPEND_IN_MICRO_DOLLAR,IMPRESSION_1,CLICKTHROUGH_1 \
337
+ --granularity DAY
338
+ ```
339
+
340
+ Options:
341
+ - `--start-date <date>` -- start date, YYYY-MM-DD (required)
342
+ - `--end-date <date>` -- end date, YYYY-MM-DD (required)
343
+ - `--columns <cols>` -- metrics, comma-separated (required). Common: SPEND_IN_MICRO_DOLLAR, IMPRESSION_1, CLICKTHROUGH_1, CPC_IN_MICRO_DOLLAR, ECPM_IN_MICRO_DOLLAR, CTR, TOTAL_CONVERSIONS
344
+ - `--granularity <gran>` -- TOTAL, DAY, HOUR, WEEK, MONTH (default DAY)
345
+ - `--click-window-days <n>` -- click attribution window (0, 1, 7, 14, 30, 60)
346
+ - `--view-window-days <n>` -- view attribution window (0, 1, 7, 14, 30, 60)
347
+
348
+ ### campaign-analytics
349
+
350
+ Get campaign-level analytics.
351
+
352
+ ```bash
353
+ pinterest-ads-cli campaign-analytics 123456789 \
354
+ --campaign-ids campaign_1,campaign_2 \
355
+ --start-date 2026-03-01 \
356
+ --end-date 2026-03-15 \
357
+ --columns SPEND_IN_MICRO_DOLLAR,IMPRESSION_1,CLICKTHROUGH_1
358
+ ```
359
+
360
+ Options:
361
+ - `--campaign-ids <ids>` -- campaign IDs, comma-separated (required)
362
+ - `--start-date <date>` -- start date (required)
363
+ - `--end-date <date>` -- end date (required)
364
+ - `--columns <cols>` -- metrics (required)
365
+ - `--granularity <gran>` -- TOTAL, DAY, HOUR, WEEK, MONTH (default DAY)
366
+
367
+ ### adgroup-analytics
368
+
369
+ Get ad group-level analytics.
370
+
371
+ ```bash
372
+ pinterest-ads-cli adgroup-analytics 123456789 \
373
+ --ad-group-ids adgroup_1 \
374
+ --start-date 2026-03-01 \
375
+ --end-date 2026-03-15 \
376
+ --columns SPEND_IN_MICRO_DOLLAR,IMPRESSION_1
377
+ ```
378
+
379
+ Options:
380
+ - `--ad-group-ids <ids>` -- ad group IDs, comma-separated (required)
381
+ - `--start-date <date>` -- start date (required)
382
+ - `--end-date <date>` -- end date (required)
383
+ - `--columns <cols>` -- metrics (required)
384
+ - `--granularity <gran>` -- TOTAL, DAY, HOUR, WEEK, MONTH (default DAY)
385
+
386
+ ### ad-analytics
387
+
388
+ Get ad-level analytics.
389
+
390
+ ```bash
391
+ pinterest-ads-cli ad-analytics 123456789 \
392
+ --ad-ids ad_1 \
393
+ --start-date 2026-03-01 \
394
+ --end-date 2026-03-15 \
395
+ --columns SPEND_IN_MICRO_DOLLAR,IMPRESSION_1
396
+ ```
397
+
398
+ Options:
399
+ - `--ad-ids <ids>` -- ad IDs, comma-separated (required)
400
+ - `--start-date <date>` -- start date (required)
401
+ - `--end-date <date>` -- end date (required)
402
+ - `--columns <cols>` -- metrics (required)
403
+ - `--granularity <gran>` -- TOTAL, DAY, HOUR, WEEK, MONTH (default DAY)
404
+
405
+ ## Error output
406
+
407
+ Errors are written to stderr as JSON with an `error` field and a non-zero exit code:
408
+
409
+ ```json
410
+ {"error": "Not authorized to access the requested resource"}
411
+ ```
412
+
413
+ ## API Reference
414
+
415
+ - Official docs: https://developers.pinterest.com/docs/api/v5/
416
+ - Authentication: https://developers.pinterest.com/docs/getting-started/authentication/
417
+
418
+ ## Related
419
+
420
+ - [google-analytics-cli](https://github.com/Bin-Huang/google-analytics-cli) -- Google Analytics CLI for AI agents
421
+ - [google-search-console-cli](https://github.com/Bin-Huang/google-search-console-cli) -- Google Search Console CLI for AI agents
422
+ - [tiktok-ads-cli](https://github.com/Bin-Huang/tiktok-ads-cli) -- TikTok Ads CLI for AI agents
423
+ - [x-ads-cli](https://github.com/Bin-Huang/x-ads-cli) -- X Ads CLI for AI agents
424
+ - [reddit-ads-cli](https://github.com/Bin-Huang/reddit-ads-cli) -- Reddit Ads CLI for AI agents
425
+ - [apple-ads-cli](https://github.com/Bin-Huang/apple-ads-cli) -- Apple Ads CLI for AI agents
426
+
427
+ ## License
428
+
429
+ Apache-2.0
package/dist/api.js ADDED
@@ -0,0 +1,29 @@
1
+ const BASE_URL = "https://api.pinterest.com/v5";
2
+ export async function callApi(endpoint, opts) {
3
+ let url = `${BASE_URL}${endpoint}`;
4
+ const headers = {
5
+ Authorization: `Bearer ${opts.creds.access_token}`,
6
+ "Content-Type": "application/json",
7
+ Accept: "application/json",
8
+ };
9
+ if (opts.params) {
10
+ const searchParams = new URLSearchParams();
11
+ for (const [key, value] of Object.entries(opts.params)) {
12
+ if (value !== undefined && value !== null && value !== "") {
13
+ searchParams.set(key, value);
14
+ }
15
+ }
16
+ const qs = searchParams.toString();
17
+ if (qs)
18
+ url += `?${qs}`;
19
+ }
20
+ const res = await fetch(url, { method: "GET", headers });
21
+ const json = (await res.json());
22
+ if (!res.ok) {
23
+ const msg = json.message ??
24
+ json.error ??
25
+ `HTTP ${res.status}`;
26
+ throw new Error(msg);
27
+ }
28
+ return json;
29
+ }
package/dist/auth.js ADDED
@@ -0,0 +1,32 @@
1
+ import { readFileSync, existsSync } from "fs";
2
+ import { join } from "path";
3
+ import { homedir } from "os";
4
+ const DEFAULT_PATH = join(homedir(), ".config", "pinterest-ads-cli", "credentials.json");
5
+ export function loadCredentials(credentialsPath) {
6
+ // 1. --credentials flag
7
+ if (credentialsPath) {
8
+ return readJSON(credentialsPath);
9
+ }
10
+ // 2. Environment variable
11
+ if (process.env.PINTEREST_ADS_ACCESS_TOKEN) {
12
+ return {
13
+ access_token: process.env.PINTEREST_ADS_ACCESS_TOKEN,
14
+ };
15
+ }
16
+ // 3. Default credentials file
17
+ if (existsSync(DEFAULT_PATH)) {
18
+ return readJSON(DEFAULT_PATH);
19
+ }
20
+ throw new Error(`No credentials found. Provide one of:\n` +
21
+ ` 1. --credentials <path> flag\n` +
22
+ ` 2. PINTEREST_ADS_ACCESS_TOKEN env var\n` +
23
+ ` 3. ${DEFAULT_PATH}`);
24
+ }
25
+ function readJSON(path) {
26
+ const raw = readFileSync(path, "utf-8");
27
+ const data = JSON.parse(raw);
28
+ if (!data.access_token) {
29
+ throw new Error(`credentials file missing "access_token": ${path}`);
30
+ }
31
+ return data;
32
+ }