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.
@@ -0,0 +1,38 @@
1
+ import { loadCredentials } from "../auth.js";
2
+ import { callApi } from "../api.js";
3
+ import { output, fatal } from "../utils.js";
4
+ export function registerAccountCommands(program) {
5
+ program
6
+ .command("accounts")
7
+ .description("List ad accounts the user has access to")
8
+ .option("--page-size <n>", "Results per page (default 25, max 250)", "25")
9
+ .option("--bookmark <cursor>", "Pagination cursor")
10
+ .action(async (opts) => {
11
+ try {
12
+ const creds = loadCredentials(program.opts().credentials);
13
+ const params = {
14
+ page_size: opts.pageSize,
15
+ };
16
+ if (opts.bookmark)
17
+ params.bookmark = opts.bookmark;
18
+ const data = await callApi("/ad_accounts", { creds, params });
19
+ output(data, program.opts().format);
20
+ }
21
+ catch (err) {
22
+ fatal(err.message);
23
+ }
24
+ });
25
+ program
26
+ .command("account <ad-account-id>")
27
+ .description("Get details of a specific ad account")
28
+ .action(async (adAccountId) => {
29
+ try {
30
+ const creds = loadCredentials(program.opts().credentials);
31
+ const data = await callApi(`/ad_accounts/${adAccountId}`, { creds });
32
+ output(data, program.opts().format);
33
+ }
34
+ catch (err) {
35
+ fatal(err.message);
36
+ }
37
+ });
38
+ }
@@ -0,0 +1,37 @@
1
+ import { loadCredentials } from "../auth.js";
2
+ import { callApi } from "../api.js";
3
+ import { output, fatal } from "../utils.js";
4
+ export function registerAdgroupCommands(program) {
5
+ program
6
+ .command("adgroups <ad-account-id>")
7
+ .description("List ad groups for an ad account")
8
+ .option("--campaign-ids <ids>", "Filter by campaign IDs (comma-separated)")
9
+ .option("--ad-group-ids <ids>", "Filter by ad group IDs (comma-separated)")
10
+ .option("--entity-statuses <statuses>", "Filter by status (comma-separated, e.g. ACTIVE,PAUSED)")
11
+ .option("--page-size <n>", "Results per page (default 25, max 250)", "25")
12
+ .option("--order <order>", "Sort order: ASCENDING or DESCENDING")
13
+ .option("--bookmark <cursor>", "Pagination cursor")
14
+ .action(async (adAccountId, opts) => {
15
+ try {
16
+ const creds = loadCredentials(program.opts().credentials);
17
+ const params = {
18
+ page_size: opts.pageSize,
19
+ };
20
+ if (opts.campaignIds)
21
+ params.campaign_ids = opts.campaignIds;
22
+ if (opts.adGroupIds)
23
+ params.ad_group_ids = opts.adGroupIds;
24
+ if (opts.entityStatuses)
25
+ params.entity_statuses = opts.entityStatuses;
26
+ if (opts.order)
27
+ params.order = opts.order;
28
+ if (opts.bookmark)
29
+ params.bookmark = opts.bookmark;
30
+ const data = await callApi(`/ad_accounts/${adAccountId}/ad_groups`, { creds, params });
31
+ output(data, program.opts().format);
32
+ }
33
+ catch (err) {
34
+ fatal(err.message);
35
+ }
36
+ });
37
+ }
@@ -0,0 +1,40 @@
1
+ import { loadCredentials } from "../auth.js";
2
+ import { callApi } from "../api.js";
3
+ import { output, fatal } from "../utils.js";
4
+ export function registerAdCommands(program) {
5
+ program
6
+ .command("ads <ad-account-id>")
7
+ .description("List ads for an ad account")
8
+ .option("--campaign-ids <ids>", "Filter by campaign IDs (comma-separated)")
9
+ .option("--ad-group-ids <ids>", "Filter by ad group IDs (comma-separated)")
10
+ .option("--ad-ids <ids>", "Filter by ad IDs (comma-separated)")
11
+ .option("--entity-statuses <statuses>", "Filter by status (comma-separated, e.g. ACTIVE,PAUSED)")
12
+ .option("--page-size <n>", "Results per page (default 25, max 250)", "25")
13
+ .option("--order <order>", "Sort order: ASCENDING or DESCENDING")
14
+ .option("--bookmark <cursor>", "Pagination cursor")
15
+ .action(async (adAccountId, opts) => {
16
+ try {
17
+ const creds = loadCredentials(program.opts().credentials);
18
+ const params = {
19
+ page_size: opts.pageSize,
20
+ };
21
+ if (opts.campaignIds)
22
+ params.campaign_ids = opts.campaignIds;
23
+ if (opts.adGroupIds)
24
+ params.ad_group_ids = opts.adGroupIds;
25
+ if (opts.adIds)
26
+ params.ad_ids = opts.adIds;
27
+ if (opts.entityStatuses)
28
+ params.entity_statuses = opts.entityStatuses;
29
+ if (opts.order)
30
+ params.order = opts.order;
31
+ if (opts.bookmark)
32
+ params.bookmark = opts.bookmark;
33
+ const data = await callApi(`/ad_accounts/${adAccountId}/ads`, { creds, params });
34
+ output(data, program.opts().format);
35
+ }
36
+ catch (err) {
37
+ fatal(err.message);
38
+ }
39
+ });
40
+ }
@@ -0,0 +1,109 @@
1
+ import { loadCredentials } from "../auth.js";
2
+ import { callApi } from "../api.js";
3
+ import { output, fatal } from "../utils.js";
4
+ export function registerAnalyticsCommands(program) {
5
+ program
6
+ .command("analytics <ad-account-id>")
7
+ .description("Get ad account analytics")
8
+ .requiredOption("--start-date <date>", "Start date (YYYY-MM-DD)")
9
+ .requiredOption("--end-date <date>", "End date (YYYY-MM-DD)")
10
+ .requiredOption("--columns <cols>", "Metrics (comma-separated, e.g. SPEND_IN_MICRO_DOLLAR,IMPRESSION_1,CLICKTHROUGH_1)")
11
+ .option("--granularity <gran>", "Granularity: TOTAL, DAY, HOUR, WEEK, MONTH (default DAY)", "DAY")
12
+ .option("--click-window-days <n>", "Click attribution window: 0, 1, 7, 14, 30, 60")
13
+ .option("--view-window-days <n>", "View attribution window: 0, 1, 7, 14, 30, 60")
14
+ .action(async (adAccountId, opts) => {
15
+ try {
16
+ const creds = loadCredentials(program.opts().credentials);
17
+ const params = {
18
+ start_date: opts.startDate,
19
+ end_date: opts.endDate,
20
+ columns: opts.columns,
21
+ granularity: opts.granularity,
22
+ };
23
+ if (opts.clickWindowDays)
24
+ params.click_window_days = opts.clickWindowDays;
25
+ if (opts.viewWindowDays)
26
+ params.view_window_days = opts.viewWindowDays;
27
+ const data = await callApi(`/ad_accounts/${adAccountId}/analytics`, { creds, params });
28
+ output(data, program.opts().format);
29
+ }
30
+ catch (err) {
31
+ fatal(err.message);
32
+ }
33
+ });
34
+ program
35
+ .command("campaign-analytics <ad-account-id>")
36
+ .description("Get campaign-level analytics")
37
+ .requiredOption("--campaign-ids <ids>", "Campaign IDs (comma-separated)")
38
+ .requiredOption("--start-date <date>", "Start date (YYYY-MM-DD)")
39
+ .requiredOption("--end-date <date>", "End date (YYYY-MM-DD)")
40
+ .requiredOption("--columns <cols>", "Metrics (comma-separated)")
41
+ .option("--granularity <gran>", "Granularity: TOTAL, DAY, HOUR, WEEK, MONTH (default DAY)", "DAY")
42
+ .action(async (adAccountId, opts) => {
43
+ try {
44
+ const creds = loadCredentials(program.opts().credentials);
45
+ const params = {
46
+ campaign_ids: opts.campaignIds,
47
+ start_date: opts.startDate,
48
+ end_date: opts.endDate,
49
+ columns: opts.columns,
50
+ granularity: opts.granularity,
51
+ };
52
+ const data = await callApi(`/ad_accounts/${adAccountId}/campaigns/analytics`, { creds, params });
53
+ output(data, program.opts().format);
54
+ }
55
+ catch (err) {
56
+ fatal(err.message);
57
+ }
58
+ });
59
+ program
60
+ .command("adgroup-analytics <ad-account-id>")
61
+ .description("Get ad group-level analytics")
62
+ .requiredOption("--ad-group-ids <ids>", "Ad group IDs (comma-separated)")
63
+ .requiredOption("--start-date <date>", "Start date (YYYY-MM-DD)")
64
+ .requiredOption("--end-date <date>", "End date (YYYY-MM-DD)")
65
+ .requiredOption("--columns <cols>", "Metrics (comma-separated)")
66
+ .option("--granularity <gran>", "Granularity: TOTAL, DAY, HOUR, WEEK, MONTH (default DAY)", "DAY")
67
+ .action(async (adAccountId, opts) => {
68
+ try {
69
+ const creds = loadCredentials(program.opts().credentials);
70
+ const params = {
71
+ ad_group_ids: opts.adGroupIds,
72
+ start_date: opts.startDate,
73
+ end_date: opts.endDate,
74
+ columns: opts.columns,
75
+ granularity: opts.granularity,
76
+ };
77
+ const data = await callApi(`/ad_accounts/${adAccountId}/ad_groups/analytics`, { creds, params });
78
+ output(data, program.opts().format);
79
+ }
80
+ catch (err) {
81
+ fatal(err.message);
82
+ }
83
+ });
84
+ program
85
+ .command("ad-analytics <ad-account-id>")
86
+ .description("Get ad-level analytics")
87
+ .requiredOption("--ad-ids <ids>", "Ad IDs (comma-separated)")
88
+ .requiredOption("--start-date <date>", "Start date (YYYY-MM-DD)")
89
+ .requiredOption("--end-date <date>", "End date (YYYY-MM-DD)")
90
+ .requiredOption("--columns <cols>", "Metrics (comma-separated)")
91
+ .option("--granularity <gran>", "Granularity: TOTAL, DAY, HOUR, WEEK, MONTH (default DAY)", "DAY")
92
+ .action(async (adAccountId, opts) => {
93
+ try {
94
+ const creds = loadCredentials(program.opts().credentials);
95
+ const params = {
96
+ ad_ids: opts.adIds,
97
+ start_date: opts.startDate,
98
+ end_date: opts.endDate,
99
+ columns: opts.columns,
100
+ granularity: opts.granularity,
101
+ };
102
+ const data = await callApi(`/ad_accounts/${adAccountId}/ads/analytics`, { creds, params });
103
+ output(data, program.opts().format);
104
+ }
105
+ catch (err) {
106
+ fatal(err.message);
107
+ }
108
+ });
109
+ }
@@ -0,0 +1,51 @@
1
+ import { loadCredentials } from "../auth.js";
2
+ import { callApi } from "../api.js";
3
+ import { output, fatal } from "../utils.js";
4
+ export function registerAudienceCommands(program) {
5
+ program
6
+ .command("audiences <ad-account-id>")
7
+ .description("List audiences for an ad account")
8
+ .option("--page-size <n>", "Results per page (default 25, max 250)", "25")
9
+ .option("--order <order>", "Sort order: ASCENDING or DESCENDING")
10
+ .option("--bookmark <cursor>", "Pagination cursor")
11
+ .action(async (adAccountId, opts) => {
12
+ try {
13
+ const creds = loadCredentials(program.opts().credentials);
14
+ const params = {
15
+ page_size: opts.pageSize,
16
+ };
17
+ if (opts.order)
18
+ params.order = opts.order;
19
+ if (opts.bookmark)
20
+ params.bookmark = opts.bookmark;
21
+ const data = await callApi(`/ad_accounts/${adAccountId}/audiences`, { creds, params });
22
+ output(data, program.opts().format);
23
+ }
24
+ catch (err) {
25
+ fatal(err.message);
26
+ }
27
+ });
28
+ program
29
+ .command("customer-lists <ad-account-id>")
30
+ .description("List customer lists for an ad account")
31
+ .option("--page-size <n>", "Results per page (default 25, max 250)", "25")
32
+ .option("--order <order>", "Sort order: ASCENDING or DESCENDING")
33
+ .option("--bookmark <cursor>", "Pagination cursor")
34
+ .action(async (adAccountId, opts) => {
35
+ try {
36
+ const creds = loadCredentials(program.opts().credentials);
37
+ const params = {
38
+ page_size: opts.pageSize,
39
+ };
40
+ if (opts.order)
41
+ params.order = opts.order;
42
+ if (opts.bookmark)
43
+ params.bookmark = opts.bookmark;
44
+ const data = await callApi(`/ad_accounts/${adAccountId}/customer_lists`, { creds, params });
45
+ output(data, program.opts().format);
46
+ }
47
+ catch (err) {
48
+ fatal(err.message);
49
+ }
50
+ });
51
+ }
@@ -0,0 +1,64 @@
1
+ import { loadCredentials } from "../auth.js";
2
+ import { callApi } from "../api.js";
3
+ import { output, fatal } from "../utils.js";
4
+ export function registerBillingCommands(program) {
5
+ program
6
+ .command("billing-profiles <ad-account-id>")
7
+ .description("List billing profiles for an ad account")
8
+ .option("--is-active", "Only return active profiles")
9
+ .option("--page-size <n>", "Results per page (default 25, max 250)", "25")
10
+ .option("--bookmark <cursor>", "Pagination cursor")
11
+ .action(async (adAccountId, opts) => {
12
+ try {
13
+ const creds = loadCredentials(program.opts().credentials);
14
+ const params = {
15
+ page_size: opts.pageSize,
16
+ };
17
+ if (opts.isActive)
18
+ params.is_active = "true";
19
+ if (opts.bookmark)
20
+ params.bookmark = opts.bookmark;
21
+ const data = await callApi(`/ad_accounts/${adAccountId}/billing_profiles`, { creds, params });
22
+ output(data, program.opts().format);
23
+ }
24
+ catch (err) {
25
+ fatal(err.message);
26
+ }
27
+ });
28
+ program
29
+ .command("order-lines <ad-account-id>")
30
+ .description("List order lines for an ad account")
31
+ .option("--page-size <n>", "Results per page (default 25, max 250)", "25")
32
+ .option("--order <order>", "Sort order: ASCENDING or DESCENDING")
33
+ .option("--bookmark <cursor>", "Pagination cursor")
34
+ .action(async (adAccountId, opts) => {
35
+ try {
36
+ const creds = loadCredentials(program.opts().credentials);
37
+ const params = {
38
+ page_size: opts.pageSize,
39
+ };
40
+ if (opts.order)
41
+ params.order = opts.order;
42
+ if (opts.bookmark)
43
+ params.bookmark = opts.bookmark;
44
+ const data = await callApi(`/ad_accounts/${adAccountId}/order_lines`, { creds, params });
45
+ output(data, program.opts().format);
46
+ }
47
+ catch (err) {
48
+ fatal(err.message);
49
+ }
50
+ });
51
+ program
52
+ .command("order-line <ad-account-id> <order-line-id>")
53
+ .description("Get a specific order line")
54
+ .action(async (adAccountId, orderLineId) => {
55
+ try {
56
+ const creds = loadCredentials(program.opts().credentials);
57
+ const data = await callApi(`/ad_accounts/${adAccountId}/order_lines/${orderLineId}`, { creds });
58
+ output(data, program.opts().format);
59
+ }
60
+ catch (err) {
61
+ fatal(err.message);
62
+ }
63
+ });
64
+ }
@@ -0,0 +1,34 @@
1
+ import { loadCredentials } from "../auth.js";
2
+ import { callApi } from "../api.js";
3
+ import { output, fatal } from "../utils.js";
4
+ export function registerCampaignCommands(program) {
5
+ program
6
+ .command("campaigns <ad-account-id>")
7
+ .description("List campaigns for an ad account")
8
+ .option("--campaign-ids <ids>", "Filter by campaign IDs (comma-separated)")
9
+ .option("--entity-statuses <statuses>", "Filter by status (comma-separated, e.g. ACTIVE,PAUSED)")
10
+ .option("--page-size <n>", "Results per page (default 25, max 250)", "25")
11
+ .option("--order <order>", "Sort order: ASCENDING or DESCENDING")
12
+ .option("--bookmark <cursor>", "Pagination cursor")
13
+ .action(async (adAccountId, opts) => {
14
+ try {
15
+ const creds = loadCredentials(program.opts().credentials);
16
+ const params = {
17
+ page_size: opts.pageSize,
18
+ };
19
+ if (opts.campaignIds)
20
+ params.campaign_ids = opts.campaignIds;
21
+ if (opts.entityStatuses)
22
+ params.entity_statuses = opts.entityStatuses;
23
+ if (opts.order)
24
+ params.order = opts.order;
25
+ if (opts.bookmark)
26
+ params.bookmark = opts.bookmark;
27
+ const data = await callApi(`/ad_accounts/${adAccountId}/campaigns`, { creds, params });
28
+ output(data, program.opts().format);
29
+ }
30
+ catch (err) {
31
+ fatal(err.message);
32
+ }
33
+ });
34
+ }
@@ -0,0 +1,68 @@
1
+ import { loadCredentials } from "../auth.js";
2
+ import { callApi } from "../api.js";
3
+ import { output, fatal } from "../utils.js";
4
+ export function registerCatalogCommands(program) {
5
+ program
6
+ .command("catalogs")
7
+ .description("List catalogs")
8
+ .option("--page-size <n>", "Results per page (default 25, max 250)", "25")
9
+ .option("--bookmark <cursor>", "Pagination cursor")
10
+ .action(async (opts) => {
11
+ try {
12
+ const creds = loadCredentials(program.opts().credentials);
13
+ const params = {
14
+ page_size: opts.pageSize,
15
+ };
16
+ if (opts.bookmark)
17
+ params.bookmark = opts.bookmark;
18
+ const data = await callApi("/catalogs", { creds, params });
19
+ output(data, program.opts().format);
20
+ }
21
+ catch (err) {
22
+ fatal(err.message);
23
+ }
24
+ });
25
+ program
26
+ .command("feeds")
27
+ .description("List catalog feeds")
28
+ .option("--page-size <n>", "Results per page (default 25, max 250)", "25")
29
+ .option("--bookmark <cursor>", "Pagination cursor")
30
+ .action(async (opts) => {
31
+ try {
32
+ const creds = loadCredentials(program.opts().credentials);
33
+ const params = {
34
+ page_size: opts.pageSize,
35
+ };
36
+ if (opts.bookmark)
37
+ params.bookmark = opts.bookmark;
38
+ const data = await callApi("/catalogs/feeds", { creds, params });
39
+ output(data, program.opts().format);
40
+ }
41
+ catch (err) {
42
+ fatal(err.message);
43
+ }
44
+ });
45
+ program
46
+ .command("product-groups <ad-account-id>")
47
+ .description("List product groups for an ad account")
48
+ .option("--feed-id <id>", "Filter by feed ID")
49
+ .option("--page-size <n>", "Results per page (default 25, max 250)", "25")
50
+ .option("--bookmark <cursor>", "Pagination cursor")
51
+ .action(async (adAccountId, opts) => {
52
+ try {
53
+ const creds = loadCredentials(program.opts().credentials);
54
+ const params = {
55
+ page_size: opts.pageSize,
56
+ };
57
+ if (opts.feedId)
58
+ params.feed_id = opts.feedId;
59
+ if (opts.bookmark)
60
+ params.bookmark = opts.bookmark;
61
+ const data = await callApi(`/ad_accounts/${adAccountId}/product_groups/analytics`, { creds, params });
62
+ output(data, program.opts().format);
63
+ }
64
+ catch (err) {
65
+ fatal(err.message);
66
+ }
67
+ });
68
+ }
@@ -0,0 +1,31 @@
1
+ import { loadCredentials } from "../auth.js";
2
+ import { callApi } from "../api.js";
3
+ import { output, fatal } from "../utils.js";
4
+ export function registerConversionTagCommands(program) {
5
+ program
6
+ .command("conversion-tags <ad-account-id>")
7
+ .description("List conversion tags for an ad account")
8
+ .action(async (adAccountId) => {
9
+ try {
10
+ const creds = loadCredentials(program.opts().credentials);
11
+ const data = await callApi(`/ad_accounts/${adAccountId}/conversion_tags`, { creds });
12
+ output(data, program.opts().format);
13
+ }
14
+ catch (err) {
15
+ fatal(err.message);
16
+ }
17
+ });
18
+ program
19
+ .command("conversion-tag <ad-account-id> <tag-id>")
20
+ .description("Get a specific conversion tag")
21
+ .action(async (adAccountId, tagId) => {
22
+ try {
23
+ const creds = loadCredentials(program.opts().credentials);
24
+ const data = await callApi(`/ad_accounts/${adAccountId}/conversion_tags/${tagId}`, { creds });
25
+ output(data, program.opts().format);
26
+ }
27
+ catch (err) {
28
+ fatal(err.message);
29
+ }
30
+ });
31
+ }
@@ -0,0 +1,28 @@
1
+ import { loadCredentials } from "../auth.js";
2
+ import { callApi } from "../api.js";
3
+ import { output, fatal } from "../utils.js";
4
+ export function registerKeywordCommands(program) {
5
+ program
6
+ .command("keywords <ad-account-id>")
7
+ .description("List keywords for an ad account")
8
+ .option("--ad-group-id <id>", "Filter by ad group ID")
9
+ .option("--page-size <n>", "Results per page (default 25, max 250)", "25")
10
+ .option("--bookmark <cursor>", "Pagination cursor")
11
+ .action(async (adAccountId, opts) => {
12
+ try {
13
+ const creds = loadCredentials(program.opts().credentials);
14
+ const params = {
15
+ page_size: opts.pageSize,
16
+ };
17
+ if (opts.adGroupId)
18
+ params.ad_group_id = opts.adGroupId;
19
+ if (opts.bookmark)
20
+ params.bookmark = opts.bookmark;
21
+ const data = await callApi(`/ad_accounts/${adAccountId}/keywords`, { creds, params });
22
+ output(data, program.opts().format);
23
+ }
24
+ catch (err) {
25
+ fatal(err.message);
26
+ }
27
+ });
28
+ }
@@ -0,0 +1,41 @@
1
+ import { loadCredentials } from "../auth.js";
2
+ import { callApi } from "../api.js";
3
+ import { output, fatal } from "../utils.js";
4
+ export function registerLeadFormCommands(program) {
5
+ program
6
+ .command("lead-forms <ad-account-id>")
7
+ .description("List lead generation forms for an ad account")
8
+ .option("--page-size <n>", "Results per page (default 25, max 250)", "25")
9
+ .option("--order <order>", "Sort order: ASCENDING or DESCENDING")
10
+ .option("--bookmark <cursor>", "Pagination cursor")
11
+ .action(async (adAccountId, opts) => {
12
+ try {
13
+ const creds = loadCredentials(program.opts().credentials);
14
+ const params = {
15
+ page_size: opts.pageSize,
16
+ };
17
+ if (opts.order)
18
+ params.order = opts.order;
19
+ if (opts.bookmark)
20
+ params.bookmark = opts.bookmark;
21
+ const data = await callApi(`/ad_accounts/${adAccountId}/lead_forms`, { creds, params });
22
+ output(data, program.opts().format);
23
+ }
24
+ catch (err) {
25
+ fatal(err.message);
26
+ }
27
+ });
28
+ program
29
+ .command("lead-form <ad-account-id> <lead-form-id>")
30
+ .description("Get a specific lead form")
31
+ .action(async (adAccountId, leadFormId) => {
32
+ try {
33
+ const creds = loadCredentials(program.opts().credentials);
34
+ const data = await callApi(`/ad_accounts/${adAccountId}/lead_forms/${leadFormId}`, { creds });
35
+ output(data, program.opts().format);
36
+ }
37
+ catch (err) {
38
+ fatal(err.message);
39
+ }
40
+ });
41
+ }
@@ -0,0 +1,34 @@
1
+ import { loadCredentials } from "../auth.js";
2
+ import { callApi } from "../api.js";
3
+ import { output, fatal } from "../utils.js";
4
+ export function registerTrendCommands(program) {
5
+ program
6
+ .command("trends <region>")
7
+ .description("Get trending search terms for a region (e.g. US, GB, CA)")
8
+ .requiredOption("--trend-type <type>", "Trend type: growing, monthly, yearly, seasonal")
9
+ .option("--interests <interests>", "Filter by interests (comma-separated)")
10
+ .option("--genders <genders>", "Filter by genders (comma-separated)")
11
+ .option("--ages <ages>", "Filter by age groups (comma-separated)")
12
+ .option("--limit <n>", "Number of results (default 50)", "50")
13
+ .action(async (region, opts) => {
14
+ try {
15
+ const creds = loadCredentials(program.opts().credentials);
16
+ const params = {
17
+ region,
18
+ trend_type: opts.trendType,
19
+ limit: opts.limit,
20
+ };
21
+ if (opts.interests)
22
+ params.interests = opts.interests;
23
+ if (opts.genders)
24
+ params.genders = opts.genders;
25
+ if (opts.ages)
26
+ params.ages = opts.ages;
27
+ const data = await callApi("/trends/keywords", { creds, params });
28
+ output(data, program.opts().format);
29
+ }
30
+ catch (err) {
31
+ fatal(err.message);
32
+ }
33
+ });
34
+ }
package/dist/index.js ADDED
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from "commander";
3
+ import { registerAccountCommands } from "./commands/accounts.js";
4
+ import { registerCampaignCommands } from "./commands/campaigns.js";
5
+ import { registerAdgroupCommands } from "./commands/adgroups.js";
6
+ import { registerAdCommands } from "./commands/ads.js";
7
+ import { registerKeywordCommands } from "./commands/keywords.js";
8
+ import { registerAudienceCommands } from "./commands/audiences.js";
9
+ import { registerConversionTagCommands } from "./commands/conversion-tags.js";
10
+ import { registerBillingCommands } from "./commands/billing.js";
11
+ import { registerLeadFormCommands } from "./commands/lead-forms.js";
12
+ import { registerCatalogCommands } from "./commands/catalogs.js";
13
+ import { registerTrendCommands } from "./commands/trends.js";
14
+ import { registerAnalyticsCommands } from "./commands/analytics.js";
15
+ const program = new Command();
16
+ program
17
+ .name("pinterest-ads-cli")
18
+ .description("Pinterest Ads CLI for AI agents")
19
+ .version("1.0.0")
20
+ .option("--format <format>", "Output format", "json")
21
+ .option("--credentials <path>", "Path to credentials JSON file")
22
+ .addHelpText("after", "\nDocs: https://github.com/Bin-Huang/pinterest-ads-cli");
23
+ program.configureOutput({
24
+ writeErr: () => { },
25
+ });
26
+ program.hook("preAction", () => {
27
+ const format = program.opts().format;
28
+ if (format !== "json" && format !== "compact") {
29
+ process.stderr.write(JSON.stringify({ error: "Format must be 'json' or 'compact'." }) + "\n");
30
+ process.exit(1);
31
+ }
32
+ });
33
+ registerAccountCommands(program);
34
+ registerCampaignCommands(program);
35
+ registerAdgroupCommands(program);
36
+ registerAdCommands(program);
37
+ registerKeywordCommands(program);
38
+ registerAudienceCommands(program);
39
+ registerConversionTagCommands(program);
40
+ registerBillingCommands(program);
41
+ registerLeadFormCommands(program);
42
+ registerCatalogCommands(program);
43
+ registerTrendCommands(program);
44
+ registerAnalyticsCommands(program);
45
+ if (process.argv.length <= 2) {
46
+ program.outputHelp();
47
+ process.exit(0);
48
+ }
49
+ program.parse();
package/dist/utils.js ADDED
@@ -0,0 +1,12 @@
1
+ export function output(data, format) {
2
+ if (format === "compact") {
3
+ process.stdout.write(JSON.stringify(data) + "\n");
4
+ }
5
+ else {
6
+ process.stdout.write(JSON.stringify(data, null, 2) + "\n");
7
+ }
8
+ }
9
+ export function fatal(message) {
10
+ process.stderr.write(JSON.stringify({ error: message }) + "\n");
11
+ process.exit(1);
12
+ }