linkedin-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 +201 -0
- package/README.md +336 -0
- package/dist/api.js +33 -0
- package/dist/auth.js +16 -0
- package/dist/commands/accounts.js +64 -0
- package/dist/commands/analytics.js +53 -0
- package/dist/commands/audiences.js +71 -0
- package/dist/commands/campaigns.js +85 -0
- package/dist/commands/creatives.js +41 -0
- package/dist/commands/forecasts.js +77 -0
- package/dist/commands/leads.js +55 -0
- package/dist/commands/organizations.js +54 -0
- package/dist/index.js +53 -0
- package/dist/utils.js +10 -0
- package/package.json +42 -0
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,336 @@
|
|
|
1
|
+
# linkedin-ads-cli
|
|
2
|
+
|
|
3
|
+
LinkedIn Ads CLI for AI agents. Read-only access to LinkedIn Marketing API for campaign management and analytics.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g linkedin-ads-cli
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## How it works
|
|
12
|
+
|
|
13
|
+
- All output is JSON to stdout (machine-readable)
|
|
14
|
+
- Errors go to stderr as `{"error": "..."}`
|
|
15
|
+
- Exit code 0 = success, non-zero = failure
|
|
16
|
+
- Supports OAuth2 Bearer token authentication
|
|
17
|
+
|
|
18
|
+
## Setup
|
|
19
|
+
|
|
20
|
+
### Option 1: Environment variable
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
export LINKEDIN_ADS_ACCESS_TOKEN="your_access_token"
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Option 2: Credentials file
|
|
27
|
+
|
|
28
|
+
Create `~/.config/linkedin-ads-cli/credentials.json`:
|
|
29
|
+
|
|
30
|
+
```json
|
|
31
|
+
{
|
|
32
|
+
"access_token": "your_access_token"
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Option 3: Per-command credentials
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
linkedin-ads-cli accounts --credentials /path/to/creds.json
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Getting an access token
|
|
43
|
+
|
|
44
|
+
LinkedIn requires OAuth2 authentication. You need a [LinkedIn Developer Application](https://www.linkedin.com/developers/) with Marketing API access. Use the OAuth2 flow to get an access token with the required scopes:
|
|
45
|
+
- `r_ads` - Read ad accounts
|
|
46
|
+
- `r_ads_reporting` - Read ad analytics
|
|
47
|
+
- `r_organization_social` - Read organization data
|
|
48
|
+
|
|
49
|
+
## Entity hierarchy
|
|
50
|
+
|
|
51
|
+
LinkedIn Ads uses this hierarchy:
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
Organization (Company Page)
|
|
55
|
+
└── Ad Account
|
|
56
|
+
└── Campaign Group
|
|
57
|
+
└── Campaign
|
|
58
|
+
└── Creative
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Most list commands require the parent entity ID. Start with `me` to get your profile, then `organization-acls` to find organizations you manage, then `accounts` to find ad accounts.
|
|
62
|
+
|
|
63
|
+
## Usage
|
|
64
|
+
|
|
65
|
+
All commands output pretty-printed JSON by default. Use `--format compact` for single-line JSON.
|
|
66
|
+
|
|
67
|
+
LinkedIn uses URN format for IDs (e.g., `urn:li:sponsoredAccount:123456`). This CLI accepts both full URNs and plain numeric IDs.
|
|
68
|
+
|
|
69
|
+
### me
|
|
70
|
+
|
|
71
|
+
Get the authenticated user profile.
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
linkedin-ads-cli me
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### organization
|
|
78
|
+
|
|
79
|
+
Get an organization (company page) by ID.
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
linkedin-ads-cli organization 12345678
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### organization-acls
|
|
86
|
+
|
|
87
|
+
List organizations the authenticated user administers.
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
linkedin-ads-cli organization-acls
|
|
91
|
+
linkedin-ads-cli organization-acls --role ADMINISTRATOR
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Options:
|
|
95
|
+
- `--count <n>` -- results per page (default 100)
|
|
96
|
+
- `--start <n>` -- start index (default 0)
|
|
97
|
+
- `--role <role>` -- filter by role: ADMINISTRATOR, DIRECT_SPONSORED_CONTENT_POSTER, etc.
|
|
98
|
+
|
|
99
|
+
### accounts
|
|
100
|
+
|
|
101
|
+
List ad accounts the authenticated user has access to.
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
linkedin-ads-cli accounts
|
|
105
|
+
linkedin-ads-cli accounts --search "My Company"
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Options:
|
|
109
|
+
- `--count <n>` -- results per page (default 100)
|
|
110
|
+
- `--start <n>` -- start index (default 0)
|
|
111
|
+
- `--search <query>` -- search by account name or ID
|
|
112
|
+
|
|
113
|
+
### account
|
|
114
|
+
|
|
115
|
+
Get a specific ad account.
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
linkedin-ads-cli account 123456789
|
|
119
|
+
linkedin-ads-cli account urn:li:sponsoredAccount:123456789
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### account-users
|
|
123
|
+
|
|
124
|
+
List users with access to an ad account.
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
linkedin-ads-cli account-users 123456789
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Options:
|
|
131
|
+
- `--count <n>` -- results per page (default 100)
|
|
132
|
+
- `--start <n>` -- start index (default 0)
|
|
133
|
+
|
|
134
|
+
### campaign-groups
|
|
135
|
+
|
|
136
|
+
List campaign groups for an ad account.
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
linkedin-ads-cli campaign-groups 123456789
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Options:
|
|
143
|
+
- `--count <n>` -- results per page (default 100)
|
|
144
|
+
- `--start <n>` -- start index (default 0)
|
|
145
|
+
|
|
146
|
+
### campaign-group
|
|
147
|
+
|
|
148
|
+
Get a specific campaign group.
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
linkedin-ads-cli campaign-group 987654321
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### campaigns
|
|
155
|
+
|
|
156
|
+
List campaigns for an ad account.
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
linkedin-ads-cli campaigns 123456789
|
|
160
|
+
linkedin-ads-cli campaigns 123456789 --status ACTIVE
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Options:
|
|
164
|
+
- `--count <n>` -- results per page (default 100)
|
|
165
|
+
- `--start <n>` -- start index (default 0)
|
|
166
|
+
- `--status <status>` -- filter by status: ACTIVE, PAUSED, ARCHIVED, COMPLETED, CANCELED, DRAFT
|
|
167
|
+
- `--campaign-group <id>` -- filter by campaign group ID
|
|
168
|
+
|
|
169
|
+
### campaign
|
|
170
|
+
|
|
171
|
+
Get a specific campaign.
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
linkedin-ads-cli campaign 111222333
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### creatives
|
|
178
|
+
|
|
179
|
+
List creatives for a campaign.
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
linkedin-ads-cli creatives 111222333
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
Options:
|
|
186
|
+
- `--count <n>` -- results per page (default 100)
|
|
187
|
+
- `--start <n>` -- start index (default 0)
|
|
188
|
+
|
|
189
|
+
### creative
|
|
190
|
+
|
|
191
|
+
Get a specific creative.
|
|
192
|
+
|
|
193
|
+
```bash
|
|
194
|
+
linkedin-ads-cli creative 444555666
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### audiences
|
|
198
|
+
|
|
199
|
+
List matched audiences (DMP segments) for an ad account.
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
linkedin-ads-cli audiences 123456789
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
Options:
|
|
206
|
+
- `--count <n>` -- results per page (default 100)
|
|
207
|
+
- `--start <n>` -- start index (default 0)
|
|
208
|
+
|
|
209
|
+
### conversion-rules
|
|
210
|
+
|
|
211
|
+
List conversion rules for an ad account.
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
linkedin-ads-cli conversion-rules 123456789
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
Options:
|
|
218
|
+
- `--count <n>` -- results per page (default 100)
|
|
219
|
+
- `--start <n>` -- start index (default 0)
|
|
220
|
+
|
|
221
|
+
### insight-tags
|
|
222
|
+
|
|
223
|
+
List LinkedIn Insight Tags for an ad account.
|
|
224
|
+
|
|
225
|
+
```bash
|
|
226
|
+
linkedin-ads-cli insight-tags 123456789
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
Options:
|
|
230
|
+
- `--count <n>` -- results per page (default 100)
|
|
231
|
+
- `--start <n>` -- start index (default 0)
|
|
232
|
+
|
|
233
|
+
### analytics
|
|
234
|
+
|
|
235
|
+
Get ad analytics for an account.
|
|
236
|
+
|
|
237
|
+
```bash
|
|
238
|
+
linkedin-ads-cli analytics 123456789 --start-date 2026-01-01 --end-date 2026-01-31
|
|
239
|
+
linkedin-ads-cli analytics 123456789 --start-date 2026-01-01 --end-date 2026-01-31 --granularity DAILY --pivot CAMPAIGN
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
Options:
|
|
243
|
+
- `--start-date <date>` -- start date (YYYY-MM-DD) **required**
|
|
244
|
+
- `--end-date <date>` -- end date (YYYY-MM-DD) **required**
|
|
245
|
+
- `--granularity <gran>` -- time granularity: DAILY, MONTHLY, ALL (default DAILY)
|
|
246
|
+
- `--pivot <pivot>` -- pivot dimension: CAMPAIGN, CAMPAIGN_GROUP, CREATIVE, ACCOUNT (default CAMPAIGN)
|
|
247
|
+
- `--campaign-ids <ids>` -- filter by campaign IDs (comma-separated)
|
|
248
|
+
- `--campaign-group-ids <ids>` -- filter by campaign group IDs (comma-separated)
|
|
249
|
+
- `--fields <fields>` -- metric fields (comma-separated)
|
|
250
|
+
|
|
251
|
+
Default metrics: impressions, clicks, costInLocalCurrency, costInUsd, externalWebsiteConversions, likes, comments, shares, follows, videoViews
|
|
252
|
+
|
|
253
|
+
### lead-gen-forms
|
|
254
|
+
|
|
255
|
+
List Lead Gen forms for an ad account.
|
|
256
|
+
|
|
257
|
+
```bash
|
|
258
|
+
linkedin-ads-cli lead-gen-forms 123456789
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
Options:
|
|
262
|
+
- `--count <n>` -- results per page (default 100)
|
|
263
|
+
- `--start <n>` -- start index (default 0)
|
|
264
|
+
|
|
265
|
+
### lead-form-responses
|
|
266
|
+
|
|
267
|
+
List responses (submissions) for a Lead Gen form.
|
|
268
|
+
|
|
269
|
+
```bash
|
|
270
|
+
linkedin-ads-cli lead-form-responses 777888999
|
|
271
|
+
linkedin-ads-cli lead-form-responses 777888999 --start-time 1709251200000 --end-time 1711929600000
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
Options:
|
|
275
|
+
- `--count <n>` -- results per page (default 100)
|
|
276
|
+
- `--start <n>` -- start index (default 0)
|
|
277
|
+
- `--start-time <time>` -- filter responses after this time (epoch ms)
|
|
278
|
+
- `--end-time <time>` -- filter responses before this time (epoch ms)
|
|
279
|
+
|
|
280
|
+
### audience-counts
|
|
281
|
+
|
|
282
|
+
Get estimated audience size for targeting criteria.
|
|
283
|
+
|
|
284
|
+
```bash
|
|
285
|
+
linkedin-ads-cli audience-counts 123456789
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
### budget-recommendations
|
|
289
|
+
|
|
290
|
+
Get budget recommendations for a campaign.
|
|
291
|
+
|
|
292
|
+
```bash
|
|
293
|
+
linkedin-ads-cli budget-recommendations 111222333
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
### ad-forecasts
|
|
297
|
+
|
|
298
|
+
Get ad delivery forecasts for an account.
|
|
299
|
+
|
|
300
|
+
```bash
|
|
301
|
+
linkedin-ads-cli ad-forecasts 123456789
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
### targeting-facets
|
|
305
|
+
|
|
306
|
+
List available targeting facets for an ad account (industries, job titles, locations, etc.).
|
|
307
|
+
|
|
308
|
+
```bash
|
|
309
|
+
linkedin-ads-cli targeting-facets 123456789
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
## Error output
|
|
313
|
+
|
|
314
|
+
All errors are JSON to stderr:
|
|
315
|
+
|
|
316
|
+
```json
|
|
317
|
+
{"error": "No credentials found. Set LINKEDIN_ADS_ACCESS_TOKEN env var..."}
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
## API Reference
|
|
321
|
+
|
|
322
|
+
- [LinkedIn Marketing API Overview](https://learn.microsoft.com/en-us/linkedin/marketing/)
|
|
323
|
+
- [Ad Accounts API](https://learn.microsoft.com/en-us/linkedin/marketing/integrations/ads/account-structure/create-and-manage-an-account)
|
|
324
|
+
- [Analytics API](https://learn.microsoft.com/en-us/linkedin/marketing/integrations/ads-reporting/ads-reporting)
|
|
325
|
+
|
|
326
|
+
## Related
|
|
327
|
+
|
|
328
|
+
- [tiktok-ads-cli](https://github.com/Bin-Huang/tiktok-ads-cli) -- TikTok Ads CLI
|
|
329
|
+
- [x-ads-cli](https://github.com/Bin-Huang/x-ads-cli) -- X (Twitter) Ads CLI
|
|
330
|
+
- [snapchat-ads-cli](https://github.com/Bin-Huang/snapchat-ads-cli) -- Snapchat Ads CLI
|
|
331
|
+
- [pinterest-ads-cli](https://github.com/Bin-Huang/pinterest-ads-cli) -- Pinterest Ads CLI
|
|
332
|
+
- [reddit-ads-cli](https://github.com/Bin-Huang/reddit-ads-cli) -- Reddit Ads CLI
|
|
333
|
+
|
|
334
|
+
## License
|
|
335
|
+
|
|
336
|
+
Apache-2.0
|
package/dist/api.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const BASE_URL = "https://api.linkedin.com/rest";
|
|
2
|
+
const API_VERSION = "202603";
|
|
3
|
+
export async function callApi(opts) {
|
|
4
|
+
const url = new URL(`${BASE_URL}/${opts.path}`);
|
|
5
|
+
if (opts.params) {
|
|
6
|
+
for (const [k, v] of Object.entries(opts.params)) {
|
|
7
|
+
if (v !== undefined && v !== "")
|
|
8
|
+
url.searchParams.set(k, v);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
const res = await fetch(url.toString(), {
|
|
12
|
+
headers: {
|
|
13
|
+
Authorization: `Bearer ${opts.creds.access_token}`,
|
|
14
|
+
"LinkedIn-Version": API_VERSION,
|
|
15
|
+
"X-Restli-Protocol-Version": "2.0.0",
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
const text = await res.text();
|
|
19
|
+
let data;
|
|
20
|
+
try {
|
|
21
|
+
data = JSON.parse(text);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
data = { rawResponse: text };
|
|
25
|
+
}
|
|
26
|
+
if (!res.ok) {
|
|
27
|
+
const msg = typeof data === "object" && data !== null && "message" in data
|
|
28
|
+
? String(data.message)
|
|
29
|
+
: `HTTP ${res.status}`;
|
|
30
|
+
throw new Error(msg);
|
|
31
|
+
}
|
|
32
|
+
return data;
|
|
33
|
+
}
|
package/dist/auth.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { readFileSync, existsSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
const DEFAULT_PATH = join(homedir(), ".config", "linkedin-ads-cli", "credentials.json");
|
|
5
|
+
export function loadCredentials(path) {
|
|
6
|
+
if (path)
|
|
7
|
+
return JSON.parse(readFileSync(path, "utf-8"));
|
|
8
|
+
if (process.env.LINKEDIN_ADS_ACCESS_TOKEN) {
|
|
9
|
+
return { access_token: process.env.LINKEDIN_ADS_ACCESS_TOKEN };
|
|
10
|
+
}
|
|
11
|
+
if (existsSync(DEFAULT_PATH)) {
|
|
12
|
+
return JSON.parse(readFileSync(DEFAULT_PATH, "utf-8"));
|
|
13
|
+
}
|
|
14
|
+
throw new Error(`No credentials found. Set LINKEDIN_ADS_ACCESS_TOKEN env var, ` +
|
|
15
|
+
`use --credentials <path>, or place credentials at ${DEFAULT_PATH}`);
|
|
16
|
+
}
|
|
@@ -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 registerAccountCommands(program) {
|
|
5
|
+
program
|
|
6
|
+
.command("accounts")
|
|
7
|
+
.description("List ad accounts the authenticated user has access to")
|
|
8
|
+
.option("--count <n>", "Number of results (default 100)", "100")
|
|
9
|
+
.option("--start <n>", "Start index for pagination (default 0)", "0")
|
|
10
|
+
.option("--search <query>", "Search by account name or ID")
|
|
11
|
+
.action(async (opts) => {
|
|
12
|
+
try {
|
|
13
|
+
const creds = loadCredentials(program.opts().credentials);
|
|
14
|
+
const params = {
|
|
15
|
+
q: "search",
|
|
16
|
+
count: opts.count,
|
|
17
|
+
start: opts.start,
|
|
18
|
+
};
|
|
19
|
+
if (opts.search)
|
|
20
|
+
params["search.name.values[0]"] = opts.search;
|
|
21
|
+
const data = await callApi({ creds, path: "adAccounts", params });
|
|
22
|
+
output(data, program.opts().format);
|
|
23
|
+
}
|
|
24
|
+
catch (err) {
|
|
25
|
+
fatal(err.message);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
program
|
|
29
|
+
.command("account <account-id>")
|
|
30
|
+
.description("Get a specific ad account (format: urn:li:sponsoredAccount:ID or just ID)")
|
|
31
|
+
.action(async (accountId) => {
|
|
32
|
+
try {
|
|
33
|
+
const creds = loadCredentials(program.opts().credentials);
|
|
34
|
+
const urn = accountId.startsWith("urn:") ? accountId : `urn:li:sponsoredAccount:${accountId}`;
|
|
35
|
+
const encoded = encodeURIComponent(urn);
|
|
36
|
+
const data = await callApi({ creds, path: `adAccounts/${encoded}` });
|
|
37
|
+
output(data, program.opts().format);
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
fatal(err.message);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
program
|
|
44
|
+
.command("account-users <account-id>")
|
|
45
|
+
.description("List users with access to an ad account")
|
|
46
|
+
.option("--count <n>", "Number of results (default 100)", "100")
|
|
47
|
+
.option("--start <n>", "Start index (default 0)", "0")
|
|
48
|
+
.action(async (accountId, opts) => {
|
|
49
|
+
try {
|
|
50
|
+
const creds = loadCredentials(program.opts().credentials);
|
|
51
|
+
const params = {
|
|
52
|
+
q: "account",
|
|
53
|
+
account: accountId.startsWith("urn:") ? accountId : `urn:li:sponsoredAccount:${accountId}`,
|
|
54
|
+
count: opts.count,
|
|
55
|
+
start: opts.start,
|
|
56
|
+
};
|
|
57
|
+
const data = await callApi({ creds, path: "adAccountUsers", params });
|
|
58
|
+
output(data, program.opts().format);
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
fatal(err.message);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
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 <account-id>")
|
|
7
|
+
.description("Get ad analytics for an account")
|
|
8
|
+
.requiredOption("--start-date <date>", "Start date (YYYY-MM-DD)")
|
|
9
|
+
.requiredOption("--end-date <date>", "End date (YYYY-MM-DD)")
|
|
10
|
+
.option("--granularity <gran>", "Time granularity: DAILY, MONTHLY, ALL (default DAILY)", "DAILY")
|
|
11
|
+
.option("--pivot <pivot>", "Pivot dimension: CAMPAIGN, CAMPAIGN_GROUP, CREATIVE, ACCOUNT (default CAMPAIGN)", "CAMPAIGN")
|
|
12
|
+
.option("--campaign-ids <ids>", "Filter by campaign IDs (comma-separated)")
|
|
13
|
+
.option("--campaign-group-ids <ids>", "Filter by campaign group IDs (comma-separated)")
|
|
14
|
+
.option("--fields <fields>", "Metric fields (comma-separated, default common set)")
|
|
15
|
+
.action(async (accountId, opts) => {
|
|
16
|
+
try {
|
|
17
|
+
const creds = loadCredentials(program.opts().credentials);
|
|
18
|
+
const account = accountId.startsWith("urn:") ? accountId : `urn:li:sponsoredAccount:${accountId}`;
|
|
19
|
+
const [sy, sm, sd] = opts.startDate.split("-").map(Number);
|
|
20
|
+
const [ey, em, ed] = opts.endDate.split("-").map(Number);
|
|
21
|
+
const params = {
|
|
22
|
+
q: "analytics",
|
|
23
|
+
pivot: `(value:${opts.pivot})`,
|
|
24
|
+
dateRange: `(start:(year:${sy},month:${sm},day:${sd}),end:(year:${ey},month:${em},day:${ed}))`,
|
|
25
|
+
timeGranularity: `(value:${opts.granularity})`,
|
|
26
|
+
"accounts[0]": account,
|
|
27
|
+
};
|
|
28
|
+
if (opts.fields) {
|
|
29
|
+
params.fields = opts.fields;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
params.fields = "impressions,clicks,costInLocalCurrency,costInUsd,externalWebsiteConversions,likes,comments,shares,follows,videoViews";
|
|
33
|
+
}
|
|
34
|
+
if (opts.campaignIds) {
|
|
35
|
+
opts.campaignIds.split(",").forEach((id, i) => {
|
|
36
|
+
const urn = id.trim().startsWith("urn:") ? id.trim() : `urn:li:sponsoredCampaign:${id.trim()}`;
|
|
37
|
+
params[`campaigns[${i}]`] = urn;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
if (opts.campaignGroupIds) {
|
|
41
|
+
opts.campaignGroupIds.split(",").forEach((id, i) => {
|
|
42
|
+
const urn = id.trim().startsWith("urn:") ? id.trim() : `urn:li:sponsoredCampaignGroup:${id.trim()}`;
|
|
43
|
+
params[`campaignGroups[${i}]`] = urn;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
const data = await callApi({ creds, path: "adAnalytics", params });
|
|
47
|
+
output(data, program.opts().format);
|
|
48
|
+
}
|
|
49
|
+
catch (err) {
|
|
50
|
+
fatal(err.message);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
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 <account-id>")
|
|
7
|
+
.description("List matched audiences (DMP segments) for an ad account")
|
|
8
|
+
.option("--count <n>", "Number of results (default 100)", "100")
|
|
9
|
+
.option("--start <n>", "Start index (default 0)", "0")
|
|
10
|
+
.action(async (accountId, opts) => {
|
|
11
|
+
try {
|
|
12
|
+
const creds = loadCredentials(program.opts().credentials);
|
|
13
|
+
const account = accountId.startsWith("urn:") ? accountId : `urn:li:sponsoredAccount:${accountId}`;
|
|
14
|
+
const params = {
|
|
15
|
+
q: "account",
|
|
16
|
+
account,
|
|
17
|
+
count: opts.count,
|
|
18
|
+
start: opts.start,
|
|
19
|
+
};
|
|
20
|
+
const data = await callApi({ creds, path: "dmpSegments", params });
|
|
21
|
+
output(data, program.opts().format);
|
|
22
|
+
}
|
|
23
|
+
catch (err) {
|
|
24
|
+
fatal(err.message);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
program
|
|
28
|
+
.command("conversion-rules <account-id>")
|
|
29
|
+
.description("List conversion rules for an ad account")
|
|
30
|
+
.option("--count <n>", "Number of results (default 100)", "100")
|
|
31
|
+
.option("--start <n>", "Start index (default 0)", "0")
|
|
32
|
+
.action(async (accountId, opts) => {
|
|
33
|
+
try {
|
|
34
|
+
const creds = loadCredentials(program.opts().credentials);
|
|
35
|
+
const account = accountId.startsWith("urn:") ? accountId : `urn:li:sponsoredAccount:${accountId}`;
|
|
36
|
+
const params = {
|
|
37
|
+
q: "account",
|
|
38
|
+
account,
|
|
39
|
+
count: opts.count,
|
|
40
|
+
start: opts.start,
|
|
41
|
+
};
|
|
42
|
+
const data = await callApi({ creds, path: "conversions", params });
|
|
43
|
+
output(data, program.opts().format);
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
fatal(err.message);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
program
|
|
50
|
+
.command("insight-tags <account-id>")
|
|
51
|
+
.description("List LinkedIn Insight Tags for an ad account")
|
|
52
|
+
.option("--count <n>", "Number of results (default 100)", "100")
|
|
53
|
+
.option("--start <n>", "Start index (default 0)", "0")
|
|
54
|
+
.action(async (accountId, opts) => {
|
|
55
|
+
try {
|
|
56
|
+
const creds = loadCredentials(program.opts().credentials);
|
|
57
|
+
const account = accountId.startsWith("urn:") ? accountId : `urn:li:sponsoredAccount:${accountId}`;
|
|
58
|
+
const params = {
|
|
59
|
+
q: "account",
|
|
60
|
+
account,
|
|
61
|
+
count: opts.count,
|
|
62
|
+
start: opts.start,
|
|
63
|
+
};
|
|
64
|
+
const data = await callApi({ creds, path: "insightTags", params });
|
|
65
|
+
output(data, program.opts().format);
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
fatal(err.message);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
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("campaign-groups <account-id>")
|
|
7
|
+
.description("List campaign groups for an ad account")
|
|
8
|
+
.option("--count <n>", "Number of results (default 100)", "100")
|
|
9
|
+
.option("--start <n>", "Start index (default 0)", "0")
|
|
10
|
+
.action(async (accountId, opts) => {
|
|
11
|
+
try {
|
|
12
|
+
const creds = loadCredentials(program.opts().credentials);
|
|
13
|
+
const account = accountId.startsWith("urn:") ? accountId : `urn:li:sponsoredAccount:${accountId}`;
|
|
14
|
+
const params = {
|
|
15
|
+
q: "search",
|
|
16
|
+
"search.account.values[0]": account,
|
|
17
|
+
count: opts.count,
|
|
18
|
+
start: opts.start,
|
|
19
|
+
};
|
|
20
|
+
const data = await callApi({ creds, path: "adCampaignGroups", params });
|
|
21
|
+
output(data, program.opts().format);
|
|
22
|
+
}
|
|
23
|
+
catch (err) {
|
|
24
|
+
fatal(err.message);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
program
|
|
28
|
+
.command("campaign-group <campaign-group-id>")
|
|
29
|
+
.description("Get a specific campaign group")
|
|
30
|
+
.action(async (id) => {
|
|
31
|
+
try {
|
|
32
|
+
const creds = loadCredentials(program.opts().credentials);
|
|
33
|
+
const urn = id.startsWith("urn:") ? id : `urn:li:sponsoredCampaignGroup:${id}`;
|
|
34
|
+
const data = await callApi({ creds, path: `adCampaignGroups/${encodeURIComponent(urn)}` });
|
|
35
|
+
output(data, program.opts().format);
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
fatal(err.message);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
program
|
|
42
|
+
.command("campaigns <account-id>")
|
|
43
|
+
.description("List campaigns for an ad account")
|
|
44
|
+
.option("--count <n>", "Number of results (default 100)", "100")
|
|
45
|
+
.option("--start <n>", "Start index (default 0)", "0")
|
|
46
|
+
.option("--status <status>", "Filter by status: ACTIVE, PAUSED, ARCHIVED, COMPLETED, CANCELED, DRAFT")
|
|
47
|
+
.option("--campaign-group <id>", "Filter by campaign group ID")
|
|
48
|
+
.action(async (accountId, opts) => {
|
|
49
|
+
try {
|
|
50
|
+
const creds = loadCredentials(program.opts().credentials);
|
|
51
|
+
const account = accountId.startsWith("urn:") ? accountId : `urn:li:sponsoredAccount:${accountId}`;
|
|
52
|
+
const params = {
|
|
53
|
+
q: "search",
|
|
54
|
+
"search.account.values[0]": account,
|
|
55
|
+
count: opts.count,
|
|
56
|
+
start: opts.start,
|
|
57
|
+
};
|
|
58
|
+
if (opts.status)
|
|
59
|
+
params["search.status.values[0]"] = opts.status;
|
|
60
|
+
if (opts.campaignGroup) {
|
|
61
|
+
const cg = opts.campaignGroup.startsWith("urn:") ? opts.campaignGroup : `urn:li:sponsoredCampaignGroup:${opts.campaignGroup}`;
|
|
62
|
+
params["search.campaignGroup.values[0]"] = cg;
|
|
63
|
+
}
|
|
64
|
+
const data = await callApi({ creds, path: "adCampaigns", params });
|
|
65
|
+
output(data, program.opts().format);
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
fatal(err.message);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
program
|
|
72
|
+
.command("campaign <campaign-id>")
|
|
73
|
+
.description("Get a specific campaign")
|
|
74
|
+
.action(async (id) => {
|
|
75
|
+
try {
|
|
76
|
+
const creds = loadCredentials(program.opts().credentials);
|
|
77
|
+
const urn = id.startsWith("urn:") ? id : `urn:li:sponsoredCampaign:${id}`;
|
|
78
|
+
const data = await callApi({ creds, path: `adCampaigns/${encodeURIComponent(urn)}` });
|
|
79
|
+
output(data, program.opts().format);
|
|
80
|
+
}
|
|
81
|
+
catch (err) {
|
|
82
|
+
fatal(err.message);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
@@ -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 registerCreativeCommands(program) {
|
|
5
|
+
program
|
|
6
|
+
.command("creatives <campaign-id>")
|
|
7
|
+
.description("List creatives for a campaign")
|
|
8
|
+
.option("--count <n>", "Number of results (default 100)", "100")
|
|
9
|
+
.option("--start <n>", "Start index (default 0)", "0")
|
|
10
|
+
.action(async (campaignId, opts) => {
|
|
11
|
+
try {
|
|
12
|
+
const creds = loadCredentials(program.opts().credentials);
|
|
13
|
+
const campaign = campaignId.startsWith("urn:") ? campaignId : `urn:li:sponsoredCampaign:${campaignId}`;
|
|
14
|
+
const params = {
|
|
15
|
+
q: "search",
|
|
16
|
+
"search.campaign.values[0]": campaign,
|
|
17
|
+
count: opts.count,
|
|
18
|
+
start: opts.start,
|
|
19
|
+
};
|
|
20
|
+
const data = await callApi({ creds, path: "adCreatives", params });
|
|
21
|
+
output(data, program.opts().format);
|
|
22
|
+
}
|
|
23
|
+
catch (err) {
|
|
24
|
+
fatal(err.message);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
program
|
|
28
|
+
.command("creative <creative-id>")
|
|
29
|
+
.description("Get a specific creative")
|
|
30
|
+
.action(async (id) => {
|
|
31
|
+
try {
|
|
32
|
+
const creds = loadCredentials(program.opts().credentials);
|
|
33
|
+
const urn = id.startsWith("urn:") ? id : `urn:li:sponsoredCreative:${id}`;
|
|
34
|
+
const data = await callApi({ creds, path: `adCreatives/${encodeURIComponent(urn)}` });
|
|
35
|
+
output(data, program.opts().format);
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
fatal(err.message);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { loadCredentials } from "../auth.js";
|
|
2
|
+
import { callApi } from "../api.js";
|
|
3
|
+
import { output, fatal } from "../utils.js";
|
|
4
|
+
export function registerForecastCommands(program) {
|
|
5
|
+
program
|
|
6
|
+
.command("audience-counts <account-id>")
|
|
7
|
+
.description("Get estimated audience size for targeting criteria")
|
|
8
|
+
.action(async (accountId) => {
|
|
9
|
+
try {
|
|
10
|
+
const creds = loadCredentials(program.opts().credentials);
|
|
11
|
+
const account = accountId.startsWith("urn:") ? accountId : `urn:li:sponsoredAccount:${accountId}`;
|
|
12
|
+
const params = {
|
|
13
|
+
q: "account",
|
|
14
|
+
account,
|
|
15
|
+
};
|
|
16
|
+
const data = await callApi({ creds, path: "adTargetingFacets", params });
|
|
17
|
+
output(data, program.opts().format);
|
|
18
|
+
}
|
|
19
|
+
catch (err) {
|
|
20
|
+
fatal(err.message);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
program
|
|
24
|
+
.command("budget-recommendations <campaign-id>")
|
|
25
|
+
.description("Get budget recommendations for a campaign")
|
|
26
|
+
.action(async (campaignId) => {
|
|
27
|
+
try {
|
|
28
|
+
const creds = loadCredentials(program.opts().credentials);
|
|
29
|
+
const campaign = campaignId.startsWith("urn:") ? campaignId : `urn:li:sponsoredCampaign:${campaignId}`;
|
|
30
|
+
const params = {
|
|
31
|
+
q: "campaign",
|
|
32
|
+
campaign,
|
|
33
|
+
};
|
|
34
|
+
const data = await callApi({ creds, path: "adBudgetRecommendations", params });
|
|
35
|
+
output(data, program.opts().format);
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
fatal(err.message);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
program
|
|
42
|
+
.command("ad-forecasts <account-id>")
|
|
43
|
+
.description("Get ad delivery forecasts for an account")
|
|
44
|
+
.action(async (accountId) => {
|
|
45
|
+
try {
|
|
46
|
+
const creds = loadCredentials(program.opts().credentials);
|
|
47
|
+
const account = accountId.startsWith("urn:") ? accountId : `urn:li:sponsoredAccount:${accountId}`;
|
|
48
|
+
const params = {
|
|
49
|
+
q: "account",
|
|
50
|
+
account,
|
|
51
|
+
};
|
|
52
|
+
const data = await callApi({ creds, path: "adForecasts", params });
|
|
53
|
+
output(data, program.opts().format);
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
fatal(err.message);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
program
|
|
60
|
+
.command("targeting-facets <account-id>")
|
|
61
|
+
.description("List available targeting facets for an ad account")
|
|
62
|
+
.action(async (accountId) => {
|
|
63
|
+
try {
|
|
64
|
+
const creds = loadCredentials(program.opts().credentials);
|
|
65
|
+
const account = accountId.startsWith("urn:") ? accountId : `urn:li:sponsoredAccount:${accountId}`;
|
|
66
|
+
const params = {
|
|
67
|
+
q: "account",
|
|
68
|
+
account,
|
|
69
|
+
};
|
|
70
|
+
const data = await callApi({ creds, path: "adTargetingFacets", params });
|
|
71
|
+
output(data, program.opts().format);
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
fatal(err.message);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { loadCredentials } from "../auth.js";
|
|
2
|
+
import { callApi } from "../api.js";
|
|
3
|
+
import { output, fatal } from "../utils.js";
|
|
4
|
+
export function registerLeadCommands(program) {
|
|
5
|
+
program
|
|
6
|
+
.command("lead-gen-forms <account-id>")
|
|
7
|
+
.description("List Lead Gen forms for an ad account")
|
|
8
|
+
.option("--count <n>", "Number of results (default 100)", "100")
|
|
9
|
+
.option("--start <n>", "Start index (default 0)", "0")
|
|
10
|
+
.action(async (accountId, opts) => {
|
|
11
|
+
try {
|
|
12
|
+
const creds = loadCredentials(program.opts().credentials);
|
|
13
|
+
const account = accountId.startsWith("urn:") ? accountId : `urn:li:sponsoredAccount:${accountId}`;
|
|
14
|
+
const params = {
|
|
15
|
+
q: "account",
|
|
16
|
+
account,
|
|
17
|
+
count: opts.count,
|
|
18
|
+
start: opts.start,
|
|
19
|
+
};
|
|
20
|
+
const data = await callApi({ creds, path: "leadForms", params });
|
|
21
|
+
output(data, program.opts().format);
|
|
22
|
+
}
|
|
23
|
+
catch (err) {
|
|
24
|
+
fatal(err.message);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
program
|
|
28
|
+
.command("lead-form-responses <form-id>")
|
|
29
|
+
.description("List responses (submissions) for a Lead Gen form")
|
|
30
|
+
.option("--count <n>", "Number of results (default 100)", "100")
|
|
31
|
+
.option("--start <n>", "Start index (default 0)", "0")
|
|
32
|
+
.option("--start-time <time>", "Filter responses after this time (epoch ms)")
|
|
33
|
+
.option("--end-time <time>", "Filter responses before this time (epoch ms)")
|
|
34
|
+
.action(async (formId, opts) => {
|
|
35
|
+
try {
|
|
36
|
+
const creds = loadCredentials(program.opts().credentials);
|
|
37
|
+
const form = formId.startsWith("urn:") ? formId : `urn:li:leadForm:${formId}`;
|
|
38
|
+
const params = {
|
|
39
|
+
q: "form",
|
|
40
|
+
form,
|
|
41
|
+
count: opts.count,
|
|
42
|
+
start: opts.start,
|
|
43
|
+
};
|
|
44
|
+
if (opts.startTime)
|
|
45
|
+
params.submittedAtStart = opts.startTime;
|
|
46
|
+
if (opts.endTime)
|
|
47
|
+
params.submittedAtEnd = opts.endTime;
|
|
48
|
+
const data = await callApi({ creds, path: "leadFormResponses", params });
|
|
49
|
+
output(data, program.opts().format);
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
fatal(err.message);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { loadCredentials } from "../auth.js";
|
|
2
|
+
import { callApi } from "../api.js";
|
|
3
|
+
import { output, fatal } from "../utils.js";
|
|
4
|
+
export function registerOrganizationCommands(program) {
|
|
5
|
+
program
|
|
6
|
+
.command("me")
|
|
7
|
+
.description("Get the authenticated user profile")
|
|
8
|
+
.action(async () => {
|
|
9
|
+
try {
|
|
10
|
+
const creds = loadCredentials(program.opts().credentials);
|
|
11
|
+
const data = await callApi({ creds, path: "me" });
|
|
12
|
+
output(data, program.opts().format);
|
|
13
|
+
}
|
|
14
|
+
catch (err) {
|
|
15
|
+
fatal(err.message);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
program
|
|
19
|
+
.command("organization <org-id>")
|
|
20
|
+
.description("Get an organization (company page) by ID")
|
|
21
|
+
.action(async (orgId) => {
|
|
22
|
+
try {
|
|
23
|
+
const creds = loadCredentials(program.opts().credentials);
|
|
24
|
+
const data = await callApi({ creds, path: `organizations/${orgId}` });
|
|
25
|
+
output(data, program.opts().format);
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
fatal(err.message);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
program
|
|
32
|
+
.command("organization-acls")
|
|
33
|
+
.description("List organizations the authenticated user administers")
|
|
34
|
+
.option("--count <n>", "Number of results (default 100)", "100")
|
|
35
|
+
.option("--start <n>", "Start index (default 0)", "0")
|
|
36
|
+
.option("--role <role>", "Filter by role: ADMINISTRATOR, DIRECT_SPONSORED_CONTENT_POSTER, etc.")
|
|
37
|
+
.action(async (opts) => {
|
|
38
|
+
try {
|
|
39
|
+
const creds = loadCredentials(program.opts().credentials);
|
|
40
|
+
const params = {
|
|
41
|
+
q: "roleAssignee",
|
|
42
|
+
count: opts.count,
|
|
43
|
+
start: opts.start,
|
|
44
|
+
};
|
|
45
|
+
if (opts.role)
|
|
46
|
+
params.role = opts.role;
|
|
47
|
+
const data = await callApi({ creds, path: "organizationAcls", params });
|
|
48
|
+
output(data, program.opts().format);
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
fatal(err.message);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
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 { registerCreativeCommands } from "./commands/creatives.js";
|
|
6
|
+
import { registerAnalyticsCommands } from "./commands/analytics.js";
|
|
7
|
+
import { registerAudienceCommands } from "./commands/audiences.js";
|
|
8
|
+
import { registerOrganizationCommands } from "./commands/organizations.js";
|
|
9
|
+
import { registerLeadCommands } from "./commands/leads.js";
|
|
10
|
+
import { registerForecastCommands } from "./commands/forecasts.js";
|
|
11
|
+
const program = new Command();
|
|
12
|
+
program
|
|
13
|
+
.name("linkedin-ads-cli")
|
|
14
|
+
.description("LinkedIn Ads CLI for AI agents")
|
|
15
|
+
.version("1.0.0")
|
|
16
|
+
.option("--format <format>", "Output format", "json")
|
|
17
|
+
.option("--credentials <path>", "Path to credentials JSON file")
|
|
18
|
+
.addHelpText("after", "\nDocs: https://github.com/Bin-Huang/linkedin-ads-cli");
|
|
19
|
+
program.configureOutput({
|
|
20
|
+
writeErr: (str) => {
|
|
21
|
+
const msg = str.replace(/^error: /i, "").trim();
|
|
22
|
+
if (msg)
|
|
23
|
+
process.stderr.write(JSON.stringify({ error: msg }) + "\n");
|
|
24
|
+
},
|
|
25
|
+
writeOut: (str) => {
|
|
26
|
+
process.stdout.write(str);
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
program.showHelpAfterError(false);
|
|
30
|
+
program.hook("preAction", () => {
|
|
31
|
+
const format = program.opts().format;
|
|
32
|
+
if (format !== "json" && format !== "compact") {
|
|
33
|
+
process.stderr.write(JSON.stringify({ error: "Format must be 'json' or 'compact'." }) + "\n");
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
registerOrganizationCommands(program);
|
|
38
|
+
registerAccountCommands(program);
|
|
39
|
+
registerCampaignCommands(program);
|
|
40
|
+
registerCreativeCommands(program);
|
|
41
|
+
registerAudienceCommands(program);
|
|
42
|
+
registerAnalyticsCommands(program);
|
|
43
|
+
registerLeadCommands(program);
|
|
44
|
+
registerForecastCommands(program);
|
|
45
|
+
program.on("command:*", (operands) => {
|
|
46
|
+
process.stderr.write(JSON.stringify({ error: `Unknown command: ${operands[0]}. Run --help for available commands.` }) + "\n");
|
|
47
|
+
process.exit(1);
|
|
48
|
+
});
|
|
49
|
+
if (process.argv.length <= 2) {
|
|
50
|
+
program.outputHelp();
|
|
51
|
+
process.exit(0);
|
|
52
|
+
}
|
|
53
|
+
program.parse();
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export function output(data, format) {
|
|
2
|
+
const json = format === "compact"
|
|
3
|
+
? JSON.stringify(data)
|
|
4
|
+
: JSON.stringify(data, null, 2);
|
|
5
|
+
process.stdout.write(json + "\n");
|
|
6
|
+
}
|
|
7
|
+
export function fatal(message) {
|
|
8
|
+
process.stderr.write(JSON.stringify({ error: message }) + "\n");
|
|
9
|
+
process.exit(1);
|
|
10
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "linkedin-ads-cli",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "LinkedIn Ads CLI for AI agents",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"linkedin-ads-cli": "dist/index.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"README.md",
|
|
12
|
+
"LICENSE"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsc",
|
|
16
|
+
"prepack": "pnpm build"
|
|
17
|
+
},
|
|
18
|
+
"author": "Benn Huang <tohuangbin@gmail.com>",
|
|
19
|
+
"license": "Apache-2.0",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "https://github.com/Bin-Huang/linkedin-ads-cli.git"
|
|
23
|
+
},
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=18"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"linkedin-ads",
|
|
29
|
+
"ads",
|
|
30
|
+
"cli",
|
|
31
|
+
"ai-agent",
|
|
32
|
+
"api"
|
|
33
|
+
],
|
|
34
|
+
"packageManager": "pnpm@10.32.1+sha512.a706938f0e89ac1456b6563eab4edf1d1faf3368d1191fc5c59790e96dc918e4456ab2e67d613de1043d2e8c81f87303e6b40d4ffeca9df15ef1ad567348f2be",
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/node": "^25.5.0",
|
|
37
|
+
"typescript": "^5.9.3"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"commander": "^14.0.3"
|
|
41
|
+
}
|
|
42
|
+
}
|