cli-meta-ads 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +188 -0
- package/AI_CONTEXT.md +144 -0
- package/CLAUDE.md +183 -0
- package/README.md +590 -0
- package/REQUIREMENTS.md +148 -0
- package/dist/auth/constants.d.ts +1 -0
- package/dist/auth/constants.js +1 -0
- package/dist/auth/guards.d.ts +5 -0
- package/dist/auth/guards.js +16 -0
- package/dist/auth/login.d.ts +28 -0
- package/dist/auth/login.js +222 -0
- package/dist/cli/action.d.ts +11 -0
- package/dist/cli/action.js +77 -0
- package/dist/cli/build-cli.d.ts +2 -0
- package/dist/cli/build-cli.js +110 -0
- package/dist/cli/context.d.ts +24 -0
- package/dist/cli/context.js +19 -0
- package/dist/client/meta-api-client.d.ts +50 -0
- package/dist/client/meta-api-client.js +258 -0
- package/dist/client/meta-discovery.d.ts +13 -0
- package/dist/client/meta-discovery.js +88 -0
- package/dist/commands/accounts.d.ts +4 -0
- package/dist/commands/accounts.js +42 -0
- package/dist/commands/ads.d.ts +4 -0
- package/dist/commands/ads.js +148 -0
- package/dist/commands/adsets.d.ts +4 -0
- package/dist/commands/adsets.js +49 -0
- package/dist/commands/anomalies.d.ts +4 -0
- package/dist/commands/anomalies.js +44 -0
- package/dist/commands/assets.d.ts +4 -0
- package/dist/commands/assets.js +116 -0
- package/dist/commands/audiences.d.ts +4 -0
- package/dist/commands/audiences.js +40 -0
- package/dist/commands/auth.d.ts +4 -0
- package/dist/commands/auth.js +139 -0
- package/dist/commands/campaigns.d.ts +4 -0
- package/dist/commands/campaigns.js +273 -0
- package/dist/commands/capi.d.ts +4 -0
- package/dist/commands/capi.js +64 -0
- package/dist/commands/creatives.d.ts +4 -0
- package/dist/commands/creatives.js +49 -0
- package/dist/commands/diagnostics.d.ts +4 -0
- package/dist/commands/diagnostics.js +88 -0
- package/dist/commands/helpers.d.ts +13 -0
- package/dist/commands/helpers.js +50 -0
- package/dist/commands/launch.d.ts +4 -0
- package/dist/commands/launch.js +109 -0
- package/dist/commands/performance.d.ts +4 -0
- package/dist/commands/performance.js +55 -0
- package/dist/commands/pixel.d.ts +4 -0
- package/dist/commands/pixel.js +68 -0
- package/dist/commands/report.d.ts +4 -0
- package/dist/commands/report.js +30 -0
- package/dist/config/file-config.d.ts +6 -0
- package/dist/config/file-config.js +174 -0
- package/dist/config/types.d.ts +32 -0
- package/dist/config/types.js +1 -0
- package/dist/domain/account-scope.d.ts +7 -0
- package/dist/domain/account-scope.js +28 -0
- package/dist/domain/analytics.d.ts +52 -0
- package/dist/domain/analytics.js +125 -0
- package/dist/domain/approval-service.d.ts +10 -0
- package/dist/domain/approval-service.js +48 -0
- package/dist/domain/asset-feed-compiler.d.ts +43 -0
- package/dist/domain/asset-feed-compiler.js +104 -0
- package/dist/domain/launch-service.d.ts +200 -0
- package/dist/domain/launch-service.js +558 -0
- package/dist/domain/meta-ads-service.d.ts +620 -0
- package/dist/domain/meta-ads-service.js +841 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +9 -0
- package/dist/output/render.d.ts +3 -0
- package/dist/output/render.js +103 -0
- package/dist/types.d.ts +42 -0
- package/dist/types.js +1 -0
- package/dist/utils/currency.d.ts +4 -0
- package/dist/utils/currency.js +40 -0
- package/dist/utils/date-range.d.ts +20 -0
- package/dist/utils/date-range.js +115 -0
- package/dist/utils/errors.d.ts +35 -0
- package/dist/utils/errors.js +68 -0
- package/dist/utils/ids.d.ts +4 -0
- package/dist/utils/ids.js +23 -0
- package/dist/utils/meta-placement-assets.d.ts +44 -0
- package/dist/utils/meta-placement-assets.js +315 -0
- package/dist/utils/security.d.ts +5 -0
- package/dist/utils/security.js +104 -0
- package/dist/validators/common.d.ts +10 -0
- package/dist/validators/common.js +56 -0
- package/dist/validators/create-spec.d.ts +373 -0
- package/dist/validators/create-spec.js +394 -0
- package/dist/validators/launch-spec.d.ts +229 -0
- package/dist/validators/launch-spec.js +371 -0
- package/docs/TECHNICAL.md +480 -0
- package/examples/README.md +29 -0
- package/examples/launch/assets/feed4x5.png +0 -0
- package/examples/launch/assets/story9x16.png +0 -0
- package/examples/launch/multi-format-launch.json +90 -0
- package/examples/single-object/ad.json +6 -0
- package/examples/single-object/adset.json +30 -0
- package/examples/single-object/campaign.json +6 -0
- package/examples/single-object/creative.json +19 -0
- package/package.json +62 -0
- package/skills/meta-cli-operator/SKILL.md +105 -0
- package/skills/meta-cli-operator/agents/openai.yaml +4 -0
- package/skills/meta-cli-operator/references/update-matrix.md +117 -0
package/README.md
ADDED
|
@@ -0,0 +1,590 @@
|
|
|
1
|
+
# CLI-meta-ads
|
|
2
|
+
|
|
3
|
+
Agent-ready CLI for Meta Ads built on top of the Meta Marketing API. The project is designed for safe reads, draft-first mutations, and approval-gated sensitive writes, with a clear separation between CLI entrypoints, config/auth, provider client, domain logic, validators, and output rendering.
|
|
4
|
+
|
|
5
|
+
## Further documentation
|
|
6
|
+
|
|
7
|
+
- [Technical documentation](./docs/TECHNICAL.md)
|
|
8
|
+
- [AI agent quick context](./AI_CONTEXT.md)
|
|
9
|
+
- [Claude guide](./CLAUDE.md)
|
|
10
|
+
- [Codex / agents guide](./AGENTS.md)
|
|
11
|
+
- [Bundled skill: `meta-cli-operator`](./skills/meta-cli-operator/SKILL.md)
|
|
12
|
+
- [Requirements snapshot](./REQUIREMENTS.md)
|
|
13
|
+
|
|
14
|
+
## Status
|
|
15
|
+
|
|
16
|
+
The CLI is implemented, locally verified, and ready for repo publication and package publication. This repository intentionally does not contain live credentials, a production Meta app setup, or a production approval webhook.
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
### From npm
|
|
21
|
+
|
|
22
|
+
Global install:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm install -g cli-meta-ads
|
|
26
|
+
meta-ads --help
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Without a global install:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npx -y cli-meta-ads@latest --help
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Notes:
|
|
36
|
+
|
|
37
|
+
- The package exposes both `meta` and `meta-ads`.
|
|
38
|
+
- `meta-ads` is the safer binary name for shared shells because `meta` is short and can collide with other tools.
|
|
39
|
+
- The examples below use `meta`, but every command can be run as `meta-ads ...`.
|
|
40
|
+
|
|
41
|
+
### From this repository
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
npm install
|
|
45
|
+
npm run build
|
|
46
|
+
node dist/index.js --help
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
If you are running directly from the repo, replace `meta ...` in the examples with `node dist/index.js ...`.
|
|
50
|
+
|
|
51
|
+
Suggested local verification before publishing or releasing:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
npm run lint
|
|
55
|
+
npm run typecheck
|
|
56
|
+
npm run test
|
|
57
|
+
npm run build
|
|
58
|
+
npm pack --dry-run
|
|
59
|
+
node dist/index.js doctor
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Example specs
|
|
63
|
+
|
|
64
|
+
Validated example specs are included under [`./examples`](./examples):
|
|
65
|
+
|
|
66
|
+
- [`./examples/single-object/campaign.json`](./examples/single-object/campaign.json) for `campaigns create`
|
|
67
|
+
- [`./examples/single-object/adset.json`](./examples/single-object/adset.json) for `adsets create`
|
|
68
|
+
- [`./examples/single-object/creative.json`](./examples/single-object/creative.json) for `creatives create`
|
|
69
|
+
- [`./examples/single-object/ad.json`](./examples/single-object/ad.json) for `ads create`
|
|
70
|
+
- [`./examples/launch/multi-format-launch.json`](./examples/launch/multi-format-launch.json) for `launch validate|plan|apply`
|
|
71
|
+
|
|
72
|
+
Important notes:
|
|
73
|
+
|
|
74
|
+
- The single-object examples contain placeholder Meta IDs and asset hashes that must be replaced before live use.
|
|
75
|
+
- The launch example demonstrates the current `formats.feed4x5|story9x16` flow and includes tiny placeholder PNGs so `launch validate` works locally out of the box.
|
|
76
|
+
- See [`./examples/README.md`](./examples/README.md) for example commands and usage details.
|
|
77
|
+
|
|
78
|
+
## Bundled agent skill
|
|
79
|
+
|
|
80
|
+
The repo and npm package include a bundled operator skill:
|
|
81
|
+
|
|
82
|
+
- Skill: [`./skills/meta-cli-operator/SKILL.md`](./skills/meta-cli-operator/SKILL.md)
|
|
83
|
+
- OpenAI/Codex descriptor: [`./skills/meta-cli-operator/agents/openai.yaml`](./skills/meta-cli-operator/agents/openai.yaml)
|
|
84
|
+
- Update reference matrix: [`./skills/meta-cli-operator/references/update-matrix.md`](./skills/meta-cli-operator/references/update-matrix.md)
|
|
85
|
+
|
|
86
|
+
Recommended starting prompt:
|
|
87
|
+
|
|
88
|
+
```text
|
|
89
|
+
Use $meta-cli-operator to inspect, verify, and operate the Meta Ads CLI safely.
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## What the CLI currently covers
|
|
93
|
+
|
|
94
|
+
- Insights-based performance reads
|
|
95
|
+
- Campaign reads plus approval-gated `pause`, `enable`, and `budget`
|
|
96
|
+
- Campaign, ad set, creative, and ad creation from JSON specs
|
|
97
|
+
- `launch validate|plan|apply|resume` for resumable multi-object runs
|
|
98
|
+
- Ad listing, ad performance, fatigue analysis, and previews
|
|
99
|
+
- Image and video asset uploads, including optional video readiness polling
|
|
100
|
+
- Anomaly detection
|
|
101
|
+
- Pixel visibility and best-effort CAPI visibility
|
|
102
|
+
- Audience listing and size estimates
|
|
103
|
+
- Daily, weekly, and monthly reports
|
|
104
|
+
- Account discovery, default account management, `auth login|logout|status`, `whoami`, `doctor`, and `verify-api`
|
|
105
|
+
- JSON output for agents and automation
|
|
106
|
+
|
|
107
|
+
## Deliberately out of scope for now
|
|
108
|
+
|
|
109
|
+
- Carousel, catalog, or dynamic creative flows
|
|
110
|
+
- A direct CAPI event-log API client; `capi` is based on documented pixel/server-event fields
|
|
111
|
+
- Delete, archive, or broader admin workflows
|
|
112
|
+
- Direct ad set budget mutations; `campaigns budget` only works on campaign `daily_budget`
|
|
113
|
+
- Automatic refresh-token handling or a hosted auth broker; the current CLI uses Facebook Login for Business plus a locally stored user token, or a pre-generated token for automation
|
|
114
|
+
|
|
115
|
+
## Recommended auth model for teams
|
|
116
|
+
|
|
117
|
+
For an agency or shared internal team, the recommended setup is:
|
|
118
|
+
|
|
119
|
+
- publish a Meta Business app
|
|
120
|
+
- configure [Facebook Login for Business](https://developers.facebook.com/docs/facebook-login/facebook-login-for-business) for `User access tokens`
|
|
121
|
+
- request the business permissions your app actually needs, such as `ads_read`, `ads_management`, and `business_management`
|
|
122
|
+
- let each operator run `meta auth login`
|
|
123
|
+
|
|
124
|
+
This keeps permissions user-scoped: the CLI inherits the Business Manager and asset access that the logged-in Meta user already has.
|
|
125
|
+
|
|
126
|
+
For non-interactive automation, the older pre-generated token path still works and remains useful for server jobs or shared backend processes.
|
|
127
|
+
|
|
128
|
+
## Setup checklist
|
|
129
|
+
|
|
130
|
+
These steps must be completed outside the repo for a real production setup.
|
|
131
|
+
|
|
132
|
+
| Task | Where to do it | Output used by this CLI |
|
|
133
|
+
| --- | --- | --- |
|
|
134
|
+
| Create a Meta app or choose an existing Business app | [Create an app](https://developers.facebook.com/docs/development/create-an-app/), [App Dashboard](https://developers.facebook.com/apps/) | App ID and optional App Secret |
|
|
135
|
+
| Configure Facebook Login for Business for `User access tokens` | [Facebook Login for Business](https://developers.facebook.com/docs/facebook-login/facebook-login-for-business), [Manual login flow](https://developers.facebook.com/docs/facebook-login/guides/advanced/manual-flow) | Login configuration ID and valid redirect URI |
|
|
136
|
+
| Verify app type, permissions, and access requirements | [Authorization](https://developers.facebook.com/docs/marketing-api/get-started/authorization), [Permissions overview](https://developers.facebook.com/docs/permissions), [Ads Management Standard Access](https://developers.facebook.com/docs/features-reference/ads-management-standard-access), [App Review](https://developers.facebook.com/docs/resp-plat-initiatives/individual-processes/app-review) | `ads_read`, optional `ads_management`, feature/review approvals |
|
|
137
|
+
| Add the redirect URI used by the CLI | [Manual login flow](https://developers.facebook.com/docs/facebook-login/guides/advanced/manual-flow) | Valid OAuth redirect URI, for example `https://www.facebook.com/connect/login_success.html` |
|
|
138
|
+
| Optional: create a system user for background automation | [System Users overview](https://developers.facebook.com/docs/business-management-apis/system-users), [Create / retrieve / update](https://developers.facebook.com/docs/business-management-apis/system-users/create-retrieve-update), [Install apps and generate tokens](https://developers.facebook.com/docs/business-management-apis/system-users/install-apps-and-generate-tokens) | `META_ACCESS_TOKEN` for non-interactive jobs |
|
|
139
|
+
| Verify permissions | [ads_read](https://developers.facebook.com/docs/permissions#ads_read), [ads_management](https://developers.facebook.com/docs/permissions#ads_management) | Read and optionally write capabilities |
|
|
140
|
+
| Provide an approval webhook | [n8n Webhook node](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.webhook/) or your own workflow infrastructure | `META_APPROVAL_WEBHOOK` with a production HTTPS URL |
|
|
141
|
+
|
|
142
|
+
## Values you actually need
|
|
143
|
+
|
|
144
|
+
### `META_APP_ID`
|
|
145
|
+
|
|
146
|
+
- Source: [App Dashboard](https://developers.facebook.com/apps/) > App Settings > Basic
|
|
147
|
+
- Required for `meta auth login`
|
|
148
|
+
- Also used by the client when you want `appsecret_proof`
|
|
149
|
+
|
|
150
|
+
### `META_AUTH_CONFIG_ID`
|
|
151
|
+
|
|
152
|
+
- Source: [Facebook Login for Business](https://developers.facebook.com/docs/facebook-login/facebook-login-for-business)
|
|
153
|
+
- Required for `meta auth login`
|
|
154
|
+
- This is the configuration ID for the user-token login experience, not an ad account id
|
|
155
|
+
|
|
156
|
+
### `META_AUTH_REDIRECT_URI`
|
|
157
|
+
|
|
158
|
+
- Source: [Manual login flow](https://developers.facebook.com/docs/facebook-login/guides/advanced/manual-flow)
|
|
159
|
+
- Optional; defaults to `https://www.facebook.com/connect/login_success.html`
|
|
160
|
+
- If you keep the default, `meta auth login` opens the browser, then asks you to paste the final redirect URL back into the CLI
|
|
161
|
+
- The pasted callback must match this configured redirect URI; mismatched hosts or paths are rejected before the token is stored
|
|
162
|
+
|
|
163
|
+
### `META_ACCESS_TOKEN`
|
|
164
|
+
|
|
165
|
+
- Source: either `meta auth login` or [Install apps and generate tokens](https://developers.facebook.com/docs/business-management-apis/system-users/install-apps-and-generate-tokens)
|
|
166
|
+
- Optional if you use `meta auth login`; required if you want to bypass login and inject a token directly
|
|
167
|
+
- Suitable for automation and system-user workflows
|
|
168
|
+
|
|
169
|
+
### `META_APP_SECRET`
|
|
170
|
+
|
|
171
|
+
- Source: [App Dashboard](https://developers.facebook.com/apps/) > App Settings > Basic
|
|
172
|
+
- Optional in code; if present, the client automatically computes `appsecret_proof`
|
|
173
|
+
- Only required for `auth login` if your Meta configuration returns an authorization code instead of the default user-token response
|
|
174
|
+
- Meta explicitly warns not to ship the app secret in client-side code or easily decompiled binaries, so it should not be the default team-login path
|
|
175
|
+
|
|
176
|
+
### `META_APPROVAL_WEBHOOK`
|
|
177
|
+
|
|
178
|
+
- Source: your workflow/webhook infrastructure, for example n8n or an internal approval service
|
|
179
|
+
- Expected by the code: a valid `https://...` URL
|
|
180
|
+
- Without it, approval-required mutations stay blocked by design
|
|
181
|
+
|
|
182
|
+
### Ad account IDs
|
|
183
|
+
|
|
184
|
+
- From the CLI after auth is set up: `meta accounts list`
|
|
185
|
+
- Or from Ads Manager / Business Manager
|
|
186
|
+
- For local convenience afterward: `meta accounts set-default <ad-account-id>`
|
|
187
|
+
|
|
188
|
+
## Setup by usage mode
|
|
189
|
+
|
|
190
|
+
### Interactive team login
|
|
191
|
+
|
|
192
|
+
Recommended for human operators who should inherit their existing Meta Business Manager rights:
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
export META_APP_ID="..."
|
|
196
|
+
export META_AUTH_CONFIG_ID="..."
|
|
197
|
+
export META_CLI_MODE="read"
|
|
198
|
+
|
|
199
|
+
meta auth login
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
Optional but useful:
|
|
203
|
+
|
|
204
|
+
```bash
|
|
205
|
+
export META_DEFAULT_ACCOUNT_ID="1234567890"
|
|
206
|
+
export META_OUTPUT_FORMAT="text"
|
|
207
|
+
export META_API_VERSION="v25.0"
|
|
208
|
+
export META_AUTH_REDIRECT_URI="https://www.facebook.com/connect/login_success.html"
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
Notes:
|
|
212
|
+
|
|
213
|
+
- `meta auth login` stores the resulting user token in the local config file with best-effort `0600` file permissions on Unix-like systems.
|
|
214
|
+
- By default the CLI uses Meta's standard user-token flow and does not require the app secret on each operator machine.
|
|
215
|
+
- If `META_ACCESS_TOKEN` is already set in the shell, it still overrides the stored login token.
|
|
216
|
+
|
|
217
|
+
### Non-interactive automation or system-user setup
|
|
218
|
+
|
|
219
|
+
Useful for server jobs, shared backend processes, or environments where a human browser login is not appropriate:
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
export META_ACCESS_TOKEN="..."
|
|
223
|
+
export META_CLI_MODE="read"
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
### Create and upload flows
|
|
227
|
+
|
|
228
|
+
In addition to either auth setup above:
|
|
229
|
+
|
|
230
|
+
```bash
|
|
231
|
+
export META_CLI_MODE="write"
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
Important:
|
|
235
|
+
|
|
236
|
+
- Mutations still remain drafts until `--apply` is passed explicitly.
|
|
237
|
+
- The current MVP only creates new objects in `PAUSED` status.
|
|
238
|
+
|
|
239
|
+
### Approval-gated writes
|
|
240
|
+
|
|
241
|
+
In addition to write mode:
|
|
242
|
+
|
|
243
|
+
```bash
|
|
244
|
+
export META_APPROVAL_WEBHOOK="https://your-workflow.example/webhook/..."
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
Required for:
|
|
248
|
+
|
|
249
|
+
- `campaigns pause`
|
|
250
|
+
- `campaigns enable`
|
|
251
|
+
- `campaigns budget` when the change is greater than `20%`
|
|
252
|
+
|
|
253
|
+
## Suggested first-time setup in the repo
|
|
254
|
+
|
|
255
|
+
1. Finish the Meta app and Business setup.
|
|
256
|
+
2. Configure Facebook Login for Business with a `User access token` configuration and note the configuration ID.
|
|
257
|
+
3. Ensure `ads_read`; for write flows also ensure `ads_management` and the correct asset permissions.
|
|
258
|
+
4. Create an approval workflow and expose a production HTTPS webhook URL.
|
|
259
|
+
5. Set your shell environment, for example:
|
|
260
|
+
|
|
261
|
+
```bash
|
|
262
|
+
export META_APP_ID="..."
|
|
263
|
+
export META_AUTH_CONFIG_ID="..."
|
|
264
|
+
export META_CLI_MODE="read"
|
|
265
|
+
export META_APPROVAL_WEBHOOK="https://your-workflow.example/webhook/..."
|
|
266
|
+
export META_API_VERSION="v25.0"
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
6. Log in:
|
|
270
|
+
|
|
271
|
+
```bash
|
|
272
|
+
meta auth login
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
7. Optionally set a default account:
|
|
276
|
+
|
|
277
|
+
```bash
|
|
278
|
+
meta accounts set-default 1234567890
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
8. Verify connectivity:
|
|
282
|
+
|
|
283
|
+
```bash
|
|
284
|
+
meta auth status
|
|
285
|
+
meta whoami
|
|
286
|
+
meta doctor --account 1234567890
|
|
287
|
+
meta verify-api --account 1234567890
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
9. Only then start real reads:
|
|
291
|
+
|
|
292
|
+
```bash
|
|
293
|
+
meta performance --account 1234567890 --last 7d
|
|
294
|
+
meta campaigns list --account 1234567890
|
|
295
|
+
meta pixel status --account 1234567890
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
## Runtime and config model
|
|
299
|
+
|
|
300
|
+
### Environment variables
|
|
301
|
+
|
|
302
|
+
```bash
|
|
303
|
+
META_ACCESS_TOKEN=
|
|
304
|
+
META_APP_ID=
|
|
305
|
+
META_AUTH_CONFIG_ID=
|
|
306
|
+
META_AUTH_REDIRECT_URI=https://www.facebook.com/connect/login_success.html
|
|
307
|
+
META_APP_SECRET=
|
|
308
|
+
META_CLI_MODE=read
|
|
309
|
+
META_APPROVAL_WEBHOOK=
|
|
310
|
+
META_API_VERSION=v25.0
|
|
311
|
+
META_DEFAULT_ACCOUNT_ID=
|
|
312
|
+
META_OUTPUT_FORMAT=text
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
### Local config file
|
|
316
|
+
|
|
317
|
+
Path:
|
|
318
|
+
|
|
319
|
+
```text
|
|
320
|
+
~/.config/cli-meta-ads/config.json
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
The local config mainly stores:
|
|
324
|
+
|
|
325
|
+
- `accessToken`
|
|
326
|
+
- `accessTokenExpiresAt`
|
|
327
|
+
- `appId`
|
|
328
|
+
- `authConfigId`
|
|
329
|
+
- `authRedirectUri`
|
|
330
|
+
- `defaultAccountId`
|
|
331
|
+
- `permissionMode`
|
|
332
|
+
- `outputFormat`
|
|
333
|
+
- `apiVersion`
|
|
334
|
+
- optional `approvalWebhook`
|
|
335
|
+
|
|
336
|
+
### Precedence
|
|
337
|
+
|
|
338
|
+
1. CLI flags
|
|
339
|
+
2. Environment
|
|
340
|
+
3. Local config
|
|
341
|
+
4. Built-in defaults
|
|
342
|
+
|
|
343
|
+
Only explicitly set process environment variables are read. The CLI does not auto-load hidden host-local env files such as `~/.claude/meta-ads-env`.
|
|
344
|
+
|
|
345
|
+
### Debug mode
|
|
346
|
+
|
|
347
|
+
- `--debug` writes a sanitized runtime summary to `stderr` in text mode
|
|
348
|
+
- in JSON mode the same debug context is embedded under `meta.debug`
|
|
349
|
+
- secrets and sensitive query parameters such as `access_token`, `code`, and `appsecret_proof` are redacted
|
|
350
|
+
|
|
351
|
+
## Safety model
|
|
352
|
+
|
|
353
|
+
- Read commands are read-only.
|
|
354
|
+
- Mutation commands stay in draft mode unless `--apply` is passed.
|
|
355
|
+
- `META_CLI_MODE` and `--mode` constrain what is even allowed.
|
|
356
|
+
- Create commands are intentionally limited to `PAUSED` objects and a narrow set of spec types in the current MVP.
|
|
357
|
+
- `campaigns pause` and `campaigns enable` never write directly to Meta; on apply they submit an approval request instead.
|
|
358
|
+
- `campaigns budget` writes directly only when the change is `<= 20%`.
|
|
359
|
+
- Changes above `20%` also go through approval.
|
|
360
|
+
- Without `META_APPROVAL_WEBHOOK`, approval-required writes remain blocked.
|
|
361
|
+
- Approval requests are only sent to HTTPS webhooks.
|
|
362
|
+
- Approval payloads contain only the minimized intended command form, not the full local CLI argv.
|
|
363
|
+
|
|
364
|
+
## First success path
|
|
365
|
+
|
|
366
|
+
For the first real credential check, this order is the most reliable:
|
|
367
|
+
|
|
368
|
+
```bash
|
|
369
|
+
meta auth login
|
|
370
|
+
meta auth status
|
|
371
|
+
meta accounts list
|
|
372
|
+
meta accounts set-default 1234567890
|
|
373
|
+
meta doctor --account 1234567890
|
|
374
|
+
meta verify-api --account 1234567890
|
|
375
|
+
meta performance --account 1234567890 --last 7d
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
If that works, the read-only setup is usually in good shape.
|
|
379
|
+
|
|
380
|
+
## Command overview
|
|
381
|
+
|
|
382
|
+
### Global options
|
|
383
|
+
|
|
384
|
+
```bash
|
|
385
|
+
meta --json ...
|
|
386
|
+
meta --config /path/to/config.json ...
|
|
387
|
+
meta --api-version v25.0 ...
|
|
388
|
+
meta --mode read|write|admin ...
|
|
389
|
+
meta --apply ...
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
### Read commands
|
|
393
|
+
|
|
394
|
+
```bash
|
|
395
|
+
meta auth status
|
|
396
|
+
meta auth logout
|
|
397
|
+
meta performance --account <id|all> --last 7d
|
|
398
|
+
meta performance --account <id|all> --from 2026-03-01 --to 2026-03-09
|
|
399
|
+
|
|
400
|
+
meta campaigns list --account <id>
|
|
401
|
+
meta campaigns get <campaign-id>
|
|
402
|
+
|
|
403
|
+
meta ads list --campaign <id>
|
|
404
|
+
meta ads performance --campaign <id> --last 30d --sort ctr
|
|
405
|
+
meta ads fatigue --campaign <id> --last 30d
|
|
406
|
+
meta ads preview <ad-id>
|
|
407
|
+
|
|
408
|
+
meta anomalies --account <id|all> --threshold 20
|
|
409
|
+
|
|
410
|
+
meta pixel status --account <id>
|
|
411
|
+
meta pixel events --account <id> --last 24h
|
|
412
|
+
|
|
413
|
+
meta capi status --account <id>
|
|
414
|
+
meta capi events --account <id> --last 24h
|
|
415
|
+
|
|
416
|
+
meta audiences list --account <id>
|
|
417
|
+
meta audiences size --audience <id>
|
|
418
|
+
|
|
419
|
+
meta assets videos status <video-id>
|
|
420
|
+
meta launch validate --account <id> --spec ./launch.json
|
|
421
|
+
meta launch plan --account <id> --spec ./launch.json
|
|
422
|
+
|
|
423
|
+
meta report daily --account <id>
|
|
424
|
+
meta report weekly --account <id>
|
|
425
|
+
meta report monthly --account <id>
|
|
426
|
+
|
|
427
|
+
meta accounts list
|
|
428
|
+
meta accounts set-default <id>
|
|
429
|
+
|
|
430
|
+
meta whoami
|
|
431
|
+
meta doctor [--account <id>]
|
|
432
|
+
meta verify-api [--account <id>]
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
### Auth commands
|
|
436
|
+
|
|
437
|
+
```bash
|
|
438
|
+
meta auth login
|
|
439
|
+
meta auth login --app-id <app-id> --config-id <config-id>
|
|
440
|
+
meta auth login --redirect-uri https://www.facebook.com/connect/login_success.html
|
|
441
|
+
meta auth login --no-open-browser
|
|
442
|
+
meta auth status
|
|
443
|
+
meta auth logout
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
Notes:
|
|
447
|
+
|
|
448
|
+
- `auth login` opens the browser and then asks for the final redirect URL so the CLI can extract the user access token without requiring a hosted callback service.
|
|
449
|
+
- The pasted callback must resolve to the configured redirect URI; the CLI rejects mismatched callback targets before persisting auth.
|
|
450
|
+
- If your Meta configuration returns an authorization code instead of a user token, `META_APP_SECRET` must be present for the exchange step.
|
|
451
|
+
- `auth logout` clears only the locally stored token; it does not revoke the login inside Meta.
|
|
452
|
+
|
|
453
|
+
Notes:
|
|
454
|
+
|
|
455
|
+
- `--account all` is only supported on explicit multi-account read surfaces such as `performance` and `anomalies`.
|
|
456
|
+
- Single-account commands intentionally reject `all`.
|
|
457
|
+
- Relative time windows such as `--last 7d` or `--last 24h` must be positive, and calendar dates are validated strictly as `YYYY-MM-DD`.
|
|
458
|
+
|
|
459
|
+
### Mutation commands
|
|
460
|
+
|
|
461
|
+
```bash
|
|
462
|
+
meta assets images upload --account <id> --file ./hero.png
|
|
463
|
+
meta assets videos upload --account <id> --file ./spot.mp4 --wait
|
|
464
|
+
|
|
465
|
+
meta campaigns create --account <id> --spec ./campaign.json
|
|
466
|
+
meta adsets create --account <id> --spec ./adset.json
|
|
467
|
+
meta creatives create --account <id> --spec ./creative.json
|
|
468
|
+
meta ads create --account <id> --spec ./ad.json
|
|
469
|
+
meta launch apply --account <id> --spec ./launch.json
|
|
470
|
+
meta launch resume --receipt ./.meta-launch/<execution-id>.json
|
|
471
|
+
|
|
472
|
+
meta campaigns pause <campaign-id>
|
|
473
|
+
meta campaigns enable <campaign-id>
|
|
474
|
+
meta campaigns budget <campaign-id> --daily 120
|
|
475
|
+
|
|
476
|
+
meta --mode write --apply assets images upload --account <id> --file ./hero.png
|
|
477
|
+
meta --mode write --apply assets videos upload --account <id> --file ./spot.mp4 --wait
|
|
478
|
+
meta --mode write --apply campaigns create --account <id> --spec ./campaign.json
|
|
479
|
+
meta --mode write --apply adsets create --account <id> --spec ./adset.json
|
|
480
|
+
meta --mode write --apply creatives create --account <id> --spec ./creative.json
|
|
481
|
+
meta --mode write --apply ads create --account <id> --spec ./ad.json
|
|
482
|
+
meta --mode write --apply launch apply --account <id> --spec ./launch.json
|
|
483
|
+
meta --mode write --apply launch resume --receipt ./.meta-launch/<execution-id>.json
|
|
484
|
+
meta --mode write --apply campaigns pause <campaign-id>
|
|
485
|
+
meta --mode write --apply campaigns enable <campaign-id>
|
|
486
|
+
meta --mode write --apply campaigns budget <campaign-id> --daily 120
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
### Create and launch notes
|
|
490
|
+
|
|
491
|
+
- `campaigns create`, `adsets create`, `creatives create`, and `ads create` read JSON specs via `--spec`.
|
|
492
|
+
- Valid starting points are included in `./examples/single-object/*.json` and `./examples/launch/multi-format-launch.json`.
|
|
493
|
+
- `launch validate` and `launch plan` validate and inspect a full launch spec without writing anything.
|
|
494
|
+
- `launch apply` persists a receipt when `--apply` is used; without `--apply` it only renders the draft plan.
|
|
495
|
+
- `launch resume` continues from a prior receipt; without `--apply` it previews the remaining steps.
|
|
496
|
+
- Asset uploads are also mutations and remain drafts without `--apply`.
|
|
497
|
+
- Videos only poll Meta processing when `--wait` is explicitly set.
|
|
498
|
+
- The current creative MVP supports `link-image` and `video-link`.
|
|
499
|
+
- `campaigns create` supports both non-CBO campaigns and campaign budget optimization via `dailyBudget` or `lifetimeBudget`.
|
|
500
|
+
- `adsets create` derives safe bid-strategy defaults from `bidAmount`.
|
|
501
|
+
- `adsets create` and `launch` normalize Advantage+ Audience age bounds before provider calls when `targeting.targeting_automation.advantage_audience = 1`.
|
|
502
|
+
- `creatives create` supports `formats.feed4x5`, `formats.square1x1`, and `formats.story9x16`, plus the legacy `platformCustomizations.instagram` path for backward compatibility.
|
|
503
|
+
- `launch` compiles placement-aware format slots to Meta `asset_feed_spec` plus `asset_customization_rules` when possible, so one ad can use different files per placement instead of forcing provider cropping.
|
|
504
|
+
- If a `launch` creative uses `formats.*` and also targets placements outside the current abstraction, such as `audience_network.*` or `messenger.sponsored_messages`, `assetRef` is required as the explicit fallback asset.
|
|
505
|
+
- Automatic placements without true format customization generate strong warnings in `launch validate|plan|apply`.
|
|
506
|
+
- Launch receipts default to `./.meta-launch/<execution-id>.json` and can be overridden with `--receipt`.
|
|
507
|
+
|
|
508
|
+
## Typical workflows
|
|
509
|
+
|
|
510
|
+
### Read-only operator flow
|
|
511
|
+
|
|
512
|
+
```bash
|
|
513
|
+
meta auth login
|
|
514
|
+
meta auth status
|
|
515
|
+
meta accounts list
|
|
516
|
+
meta doctor --account 1234567890
|
|
517
|
+
meta verify-api --account 1234567890
|
|
518
|
+
meta report weekly --account 1234567890
|
|
519
|
+
meta anomalies --account 1234567890 --threshold 20
|
|
520
|
+
```
|
|
521
|
+
|
|
522
|
+
### Create and launch flow
|
|
523
|
+
|
|
524
|
+
```bash
|
|
525
|
+
meta launch validate --account 1234567890 --spec ./examples/launch/multi-format-launch.json
|
|
526
|
+
meta launch plan --account 1234567890 --spec ./examples/launch/multi-format-launch.json
|
|
527
|
+
meta --mode write --apply launch apply --account 1234567890 --spec ./examples/launch/multi-format-launch.json
|
|
528
|
+
```
|
|
529
|
+
|
|
530
|
+
### Approval-gated change
|
|
531
|
+
|
|
532
|
+
```bash
|
|
533
|
+
meta campaigns pause 120000000000000000
|
|
534
|
+
meta --mode write --apply campaigns pause 120000000000000000
|
|
535
|
+
```
|
|
536
|
+
|
|
537
|
+
Without `--apply` you only see the draft or approval requirement. With `--apply`, the CLI still does not pause directly at Meta; it submits the approval request to the configured HTTPS webhook.
|
|
538
|
+
|
|
539
|
+
## Known limits
|
|
540
|
+
|
|
541
|
+
- `capi` is best-effort and not a dedicated CAPI inspector.
|
|
542
|
+
- Multi-account discovery depends on token type, asset permissions, and Meta response shape.
|
|
543
|
+
- Live end-to-end verification against real Meta credentials is intentionally not stored in this repo.
|
|
544
|
+
- The current launch formats abstraction covers feed, search/explore/right-column style surfaces, and story/reels style surfaces; `audience_network.*` and `messenger.sponsored_messages` currently fall back to the explicit base asset and generate warnings.
|
|
545
|
+
- Campaign budget updates fail intentionally if Meta does not expose campaign `daily_budget` for the campaign.
|
|
546
|
+
- Very large list and insights queries fail intentionally after the 100-page safety cap; the CLI does not silently truncate results.
|
|
547
|
+
|
|
548
|
+
## Publish and release checklist
|
|
549
|
+
|
|
550
|
+
Before publishing a package or cutting a release:
|
|
551
|
+
|
|
552
|
+
1. Run `npm run lint`
|
|
553
|
+
2. Run `npm run typecheck`
|
|
554
|
+
3. Run `npm run test`
|
|
555
|
+
4. Run `npm run build`
|
|
556
|
+
5. Run `npm pack --dry-run`
|
|
557
|
+
6. Confirm the tarball does not contain repo-local artifacts or accidental internal files
|
|
558
|
+
7. Re-check `meta --help` or `node dist/index.js --help`
|
|
559
|
+
|
|
560
|
+
## Verification in the current repo state
|
|
561
|
+
|
|
562
|
+
```bash
|
|
563
|
+
npm run lint
|
|
564
|
+
npm run typecheck
|
|
565
|
+
npm run test
|
|
566
|
+
npm run build
|
|
567
|
+
npm pack --dry-run
|
|
568
|
+
node dist/index.js --help
|
|
569
|
+
```
|
|
570
|
+
|
|
571
|
+
## Official source anchors for drift checks
|
|
572
|
+
|
|
573
|
+
- [Graph API Changelog](https://developers.facebook.com/docs/graph-api/changelog/)
|
|
574
|
+
- [Marketing API overview](https://developers.facebook.com/docs/marketing-api/)
|
|
575
|
+
- [Authorization](https://developers.facebook.com/docs/marketing-api/get-started/authorization)
|
|
576
|
+
- [Facebook Login for Business](https://developers.facebook.com/docs/facebook-login/facebook-login-for-business)
|
|
577
|
+
- [Manually Building the Login Flow](https://developers.facebook.com/docs/facebook-login/guides/advanced/manual-flow)
|
|
578
|
+
- [System Users overview](https://developers.facebook.com/docs/business-management-apis/system-users)
|
|
579
|
+
- [Install apps and generate tokens](https://developers.facebook.com/docs/business-management-apis/system-users/install-apps-and-generate-tokens)
|
|
580
|
+
- [System user permissions guide](https://developers.facebook.com/docs/business-management-apis/system-users/guides/permissions)
|
|
581
|
+
- [Permissions reference](https://developers.facebook.com/docs/permissions)
|
|
582
|
+
- [ads_read](https://developers.facebook.com/docs/permissions#ads_read)
|
|
583
|
+
- [ads_management](https://developers.facebook.com/docs/permissions#ads_management)
|
|
584
|
+
- [Ads Management Standard Access](https://developers.facebook.com/docs/features-reference/ads-management-standard-access)
|
|
585
|
+
- [App Review](https://developers.facebook.com/docs/resp-plat-initiatives/individual-processes/app-review)
|
|
586
|
+
- [Rate limiting](https://developers.facebook.com/docs/graph-api/overview/rate-limiting/)
|
|
587
|
+
- [Insights](https://developers.facebook.com/docs/marketing-api/reference/ad-account/insights/)
|
|
588
|
+
- [Campaigns](https://developers.facebook.com/docs/marketing-api/reference/ad-account/campaigns/)
|
|
589
|
+
- [Ads Pixel](https://developers.facebook.com/docs/marketing-api/reference/ads-pixel/)
|
|
590
|
+
- [Custom Audience](https://developers.facebook.com/docs/marketing-api/reference/custom-audience/)
|