meta-ads-cli 0.1.0__tar.gz
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.
- meta_ads_cli-0.1.0/.env.example +9 -0
- meta_ads_cli-0.1.0/.gitignore +16 -0
- meta_ads_cli-0.1.0/LICENSE +21 -0
- meta_ads_cli-0.1.0/PKG-INFO +287 -0
- meta_ads_cli-0.1.0/README.md +258 -0
- meta_ads_cli-0.1.0/campaign.example.yaml +50 -0
- meta_ads_cli-0.1.0/examples/app-install.yaml +48 -0
- meta_ads_cli-0.1.0/examples/ecommerce.yaml +50 -0
- meta_ads_cli-0.1.0/meta_ads/__init__.py +3 -0
- meta_ads_cli-0.1.0/meta_ads/api.py +202 -0
- meta_ads_cli-0.1.0/meta_ads/campaign.py +112 -0
- meta_ads_cli-0.1.0/meta_ads/cli.py +192 -0
- meta_ads_cli-0.1.0/meta_ads/config.py +137 -0
- meta_ads_cli-0.1.0/pyproject.toml +45 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Meta Ads API credentials
|
|
2
|
+
# See README.md for setup instructions
|
|
3
|
+
|
|
4
|
+
META_ACCESS_TOKEN=your_access_token_here
|
|
5
|
+
META_AD_ACCOUNT_ID=your_ad_account_id_here
|
|
6
|
+
META_PAGE_ID=your_facebook_page_id_here
|
|
7
|
+
|
|
8
|
+
# Optional: override API version (default: v21.0)
|
|
9
|
+
# META_API_VERSION=v21.0
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Attainment Labs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: meta-ads-cli
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Create and manage Meta (Facebook/Instagram) ad campaigns from your terminal.
|
|
5
|
+
Project-URL: Homepage, https://github.com/attainmentlabs/meta-ads-cli
|
|
6
|
+
Project-URL: Issues, https://github.com/attainmentlabs/meta-ads-cli/issues
|
|
7
|
+
Author-email: Attainment Labs <hello@attainmentlabs.com>
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: ads,advertising,cli,facebook,instagram,marketing,meta
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Topic :: Internet
|
|
22
|
+
Classifier: Topic :: Office/Business
|
|
23
|
+
Requires-Python: >=3.9
|
|
24
|
+
Requires-Dist: click>=8.0
|
|
25
|
+
Requires-Dist: python-dotenv>=1.0
|
|
26
|
+
Requires-Dist: pyyaml>=6.0
|
|
27
|
+
Requires-Dist: requests>=2.28
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
# meta-ads-cli
|
|
31
|
+
|
|
32
|
+
Create and manage Meta (Facebook/Instagram) ad campaigns from your terminal.
|
|
33
|
+
|
|
34
|
+
> Built by [Attainment Labs](https://attainmentlabs.com)
|
|
35
|
+
|
|
36
|
+
## Why
|
|
37
|
+
|
|
38
|
+
Meta Ads Manager is slow. Clicking through 15 screens to launch a campaign is a waste of time when you already know what you want to run.
|
|
39
|
+
|
|
40
|
+
This tool lets you define a campaign in a YAML file and deploy it with one command.
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
meta-ads create --config campaign.yaml
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
One campaign. One ad set. Multiple ads. All created in seconds.
|
|
47
|
+
|
|
48
|
+
## Install
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
pip install meta-ads-cli
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Or install from source:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
git clone https://github.com/attainmentlabs/meta-ads-cli.git
|
|
58
|
+
cd meta-ads-cli
|
|
59
|
+
pip install -e .
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Quick Start
|
|
63
|
+
|
|
64
|
+
**1. Set up your credentials**
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
cp .env.example .env
|
|
68
|
+
# Edit .env with your Meta access token, ad account ID, and page ID
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
**2. Create your campaign config**
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
cp campaign.example.yaml campaign.yaml
|
|
75
|
+
# Edit campaign.yaml with your ad copy, images, targeting, and budget
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
**3. Validate your config**
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
meta-ads validate --config campaign.yaml
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
**4. Preview with dry run**
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
meta-ads create --config campaign.yaml --dry-run
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
**5. Deploy**
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
meta-ads create --config campaign.yaml
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Your campaign is created as PAUSED by default. Review it in Ads Manager, then activate it when ready.
|
|
97
|
+
|
|
98
|
+
## Configuration
|
|
99
|
+
|
|
100
|
+
### Environment Variables
|
|
101
|
+
|
|
102
|
+
Create a `.env` file in your project root (or export these in your shell):
|
|
103
|
+
|
|
104
|
+
| Variable | Required | Description |
|
|
105
|
+
|----------|----------|-------------|
|
|
106
|
+
| `META_ACCESS_TOKEN` | Yes | Your Meta API access token |
|
|
107
|
+
| `META_AD_ACCOUNT_ID` | Yes | Your ad account ID (numbers only, no `act_` prefix) |
|
|
108
|
+
| `META_PAGE_ID` | Yes | Your Facebook Page ID |
|
|
109
|
+
| `META_API_VERSION` | No | API version (default: `v21.0`) |
|
|
110
|
+
|
|
111
|
+
### Campaign Config (YAML)
|
|
112
|
+
|
|
113
|
+
Your campaign is defined in a single YAML file. Here is the full schema:
|
|
114
|
+
|
|
115
|
+
```yaml
|
|
116
|
+
campaign:
|
|
117
|
+
name: "My Campaign"
|
|
118
|
+
objective: OUTCOME_TRAFFIC # See objectives below
|
|
119
|
+
status: PAUSED # PAUSED or ACTIVE
|
|
120
|
+
special_ad_categories: [] # Leave empty unless required
|
|
121
|
+
|
|
122
|
+
ad_set:
|
|
123
|
+
name: "My Ad Set"
|
|
124
|
+
daily_budget: 1000 # In cents. 1000 = $10/day
|
|
125
|
+
optimization_goal: LINK_CLICKS # See optimization goals below
|
|
126
|
+
targeting:
|
|
127
|
+
age_min: 18
|
|
128
|
+
age_max: 65
|
|
129
|
+
genders: [0] # 0 = all, 1 = male, 2 = female
|
|
130
|
+
countries: ["US"]
|
|
131
|
+
interests: # Optional
|
|
132
|
+
- id: "6003139266461"
|
|
133
|
+
name: "Fitness and wellness"
|
|
134
|
+
platforms: ["facebook", "instagram"]
|
|
135
|
+
facebook_positions: ["feed"]
|
|
136
|
+
instagram_positions: ["stream", "story", "reels"]
|
|
137
|
+
|
|
138
|
+
ads:
|
|
139
|
+
- name: "My Ad"
|
|
140
|
+
image: ./images/ad.png # Path relative to YAML file
|
|
141
|
+
primary_text: "Your ad copy."
|
|
142
|
+
headline: "Your Headline"
|
|
143
|
+
description: "Short description"
|
|
144
|
+
cta: LEARN_MORE # See CTAs below
|
|
145
|
+
link: "https://example.com"
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
**Campaign Objectives:** `OUTCOME_TRAFFIC`, `OUTCOME_AWARENESS`, `OUTCOME_ENGAGEMENT`, `OUTCOME_LEADS`, `OUTCOME_SALES`, `OUTCOME_APP_PROMOTION`
|
|
149
|
+
|
|
150
|
+
**Optimization Goals:** `LINK_CLICKS`, `IMPRESSIONS`, `REACH`, `LANDING_PAGE_VIEWS`, `APP_INSTALLS`, `OFFSITE_CONVERSIONS`, `LEAD_GENERATION`
|
|
151
|
+
|
|
152
|
+
**CTA Options:** `LEARN_MORE`, `SIGN_UP`, `DOWNLOAD`, `SHOP_NOW`, `BOOK_NOW`, `GET_OFFER`, `SUBSCRIBE`, `CONTACT_US`, `APPLY_NOW`, `WATCH_MORE`
|
|
153
|
+
|
|
154
|
+
## Commands
|
|
155
|
+
|
|
156
|
+
### `meta-ads create`
|
|
157
|
+
|
|
158
|
+
Create a full campaign from your YAML config.
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
# Preview first
|
|
162
|
+
meta-ads create --dry-run
|
|
163
|
+
|
|
164
|
+
# Deploy (will ask for confirmation)
|
|
165
|
+
meta-ads create
|
|
166
|
+
|
|
167
|
+
# Deploy without confirmation
|
|
168
|
+
meta-ads create --yes
|
|
169
|
+
|
|
170
|
+
# Use a custom config file
|
|
171
|
+
meta-ads create --config path/to/campaign.yaml
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### `meta-ads status <campaign-id>`
|
|
175
|
+
|
|
176
|
+
Check the status of a campaign and all its ads.
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
meta-ads status 120243616427570285
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### `meta-ads pause <campaign-id>`
|
|
183
|
+
|
|
184
|
+
Pause a running campaign.
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
meta-ads pause 120243616427570285
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### `meta-ads activate <campaign-id>`
|
|
191
|
+
|
|
192
|
+
Activate a paused campaign. This starts spending your budget.
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
meta-ads activate 120243616427570285
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### `meta-ads delete <campaign-id>`
|
|
199
|
+
|
|
200
|
+
Permanently delete a campaign.
|
|
201
|
+
|
|
202
|
+
```bash
|
|
203
|
+
meta-ads delete 120243616427570285
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### `meta-ads validate`
|
|
207
|
+
|
|
208
|
+
Validate your YAML config without making any API calls.
|
|
209
|
+
|
|
210
|
+
```bash
|
|
211
|
+
meta-ads validate --config campaign.yaml
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
## Getting a Meta Access Token
|
|
215
|
+
|
|
216
|
+
This is the part most people get stuck on. Here is the short version:
|
|
217
|
+
|
|
218
|
+
1. Go to [Meta for Developers](https://developers.facebook.com/) and create an app (type: Business)
|
|
219
|
+
2. Open the [Graph API Explorer](https://developers.facebook.com/tools/explorer/)
|
|
220
|
+
3. Select your app, then request these permissions: `ads_management`, `pages_read_engagement`, `pages_show_list`
|
|
221
|
+
4. Click "Generate Access Token" and authorize
|
|
222
|
+
5. Copy the token to your `.env` file
|
|
223
|
+
|
|
224
|
+
**Important:** Graph API Explorer tokens expire after about 2 hours. For production use, exchange it for a long-lived token:
|
|
225
|
+
|
|
226
|
+
```bash
|
|
227
|
+
curl "https://graph.facebook.com/v21.0/oauth/access_token?\
|
|
228
|
+
grant_type=fb_exchange_token&\
|
|
229
|
+
client_id=YOUR_APP_ID&\
|
|
230
|
+
client_secret=YOUR_APP_SECRET&\
|
|
231
|
+
fb_exchange_token=YOUR_SHORT_LIVED_TOKEN"
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
Long-lived tokens last about 60 days.
|
|
235
|
+
|
|
236
|
+
## Finding Interest IDs
|
|
237
|
+
|
|
238
|
+
Interest targeting requires Meta's internal IDs. Search for them using the API:
|
|
239
|
+
|
|
240
|
+
```bash
|
|
241
|
+
curl "https://graph.facebook.com/v21.0/search?\
|
|
242
|
+
type=adinterest&\
|
|
243
|
+
q=fitness&\
|
|
244
|
+
access_token=YOUR_TOKEN"
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
This returns interest names and IDs you can use in your campaign YAML.
|
|
248
|
+
|
|
249
|
+
## Examples
|
|
250
|
+
|
|
251
|
+
See the [`examples/`](examples/) directory for ready-to-customize campaign configs:
|
|
252
|
+
|
|
253
|
+
- **[ecommerce.yaml](examples/ecommerce.yaml)**: Product launch targeting skincare enthusiasts
|
|
254
|
+
- **[app-install.yaml](examples/app-install.yaml)**: Mobile app install campaign for fitness users
|
|
255
|
+
|
|
256
|
+
## How It Works
|
|
257
|
+
|
|
258
|
+
This tool wraps the [Meta Marketing API](https://developers.facebook.com/docs/marketing-apis/) with `requests`. No heavy SDKs. The full chain:
|
|
259
|
+
|
|
260
|
+
1. Uploads your ad images to your ad account
|
|
261
|
+
2. Creates a campaign with your objective
|
|
262
|
+
3. Creates an ad set with your budget and targeting
|
|
263
|
+
4. Creates ad creatives linking your images and copy
|
|
264
|
+
5. Creates ads linking creatives to the ad set
|
|
265
|
+
|
|
266
|
+
Everything is created as `PAUSED` by default so you can review before spending.
|
|
267
|
+
|
|
268
|
+
## Want the Full Playbook?
|
|
269
|
+
|
|
270
|
+
We wrote a free guide covering Meta Ads automation end to end: OAuth setup walkthrough, audience segmentation strategy, budget allocation frameworks, creative testing, scaling rules, and common API errors with fixes.
|
|
271
|
+
|
|
272
|
+
**[Get the Guide: The Engineer's Playbook for Meta Ads](https://attainmentlabs.com/meta-ads-playbook)**
|
|
273
|
+
|
|
274
|
+
## Contributing
|
|
275
|
+
|
|
276
|
+
PRs welcome. Keep it simple. This tool is intentionally lightweight.
|
|
277
|
+
|
|
278
|
+
```bash
|
|
279
|
+
git clone https://github.com/attainmentlabs/meta-ads-cli.git
|
|
280
|
+
cd meta-ads-cli
|
|
281
|
+
pip install -e .
|
|
282
|
+
meta-ads --help
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
## License
|
|
286
|
+
|
|
287
|
+
MIT. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
# meta-ads-cli
|
|
2
|
+
|
|
3
|
+
Create and manage Meta (Facebook/Instagram) ad campaigns from your terminal.
|
|
4
|
+
|
|
5
|
+
> Built by [Attainment Labs](https://attainmentlabs.com)
|
|
6
|
+
|
|
7
|
+
## Why
|
|
8
|
+
|
|
9
|
+
Meta Ads Manager is slow. Clicking through 15 screens to launch a campaign is a waste of time when you already know what you want to run.
|
|
10
|
+
|
|
11
|
+
This tool lets you define a campaign in a YAML file and deploy it with one command.
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
meta-ads create --config campaign.yaml
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
One campaign. One ad set. Multiple ads. All created in seconds.
|
|
18
|
+
|
|
19
|
+
## Install
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pip install meta-ads-cli
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Or install from source:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
git clone https://github.com/attainmentlabs/meta-ads-cli.git
|
|
29
|
+
cd meta-ads-cli
|
|
30
|
+
pip install -e .
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Quick Start
|
|
34
|
+
|
|
35
|
+
**1. Set up your credentials**
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
cp .env.example .env
|
|
39
|
+
# Edit .env with your Meta access token, ad account ID, and page ID
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
**2. Create your campaign config**
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
cp campaign.example.yaml campaign.yaml
|
|
46
|
+
# Edit campaign.yaml with your ad copy, images, targeting, and budget
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
**3. Validate your config**
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
meta-ads validate --config campaign.yaml
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
**4. Preview with dry run**
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
meta-ads create --config campaign.yaml --dry-run
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
**5. Deploy**
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
meta-ads create --config campaign.yaml
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Your campaign is created as PAUSED by default. Review it in Ads Manager, then activate it when ready.
|
|
68
|
+
|
|
69
|
+
## Configuration
|
|
70
|
+
|
|
71
|
+
### Environment Variables
|
|
72
|
+
|
|
73
|
+
Create a `.env` file in your project root (or export these in your shell):
|
|
74
|
+
|
|
75
|
+
| Variable | Required | Description |
|
|
76
|
+
|----------|----------|-------------|
|
|
77
|
+
| `META_ACCESS_TOKEN` | Yes | Your Meta API access token |
|
|
78
|
+
| `META_AD_ACCOUNT_ID` | Yes | Your ad account ID (numbers only, no `act_` prefix) |
|
|
79
|
+
| `META_PAGE_ID` | Yes | Your Facebook Page ID |
|
|
80
|
+
| `META_API_VERSION` | No | API version (default: `v21.0`) |
|
|
81
|
+
|
|
82
|
+
### Campaign Config (YAML)
|
|
83
|
+
|
|
84
|
+
Your campaign is defined in a single YAML file. Here is the full schema:
|
|
85
|
+
|
|
86
|
+
```yaml
|
|
87
|
+
campaign:
|
|
88
|
+
name: "My Campaign"
|
|
89
|
+
objective: OUTCOME_TRAFFIC # See objectives below
|
|
90
|
+
status: PAUSED # PAUSED or ACTIVE
|
|
91
|
+
special_ad_categories: [] # Leave empty unless required
|
|
92
|
+
|
|
93
|
+
ad_set:
|
|
94
|
+
name: "My Ad Set"
|
|
95
|
+
daily_budget: 1000 # In cents. 1000 = $10/day
|
|
96
|
+
optimization_goal: LINK_CLICKS # See optimization goals below
|
|
97
|
+
targeting:
|
|
98
|
+
age_min: 18
|
|
99
|
+
age_max: 65
|
|
100
|
+
genders: [0] # 0 = all, 1 = male, 2 = female
|
|
101
|
+
countries: ["US"]
|
|
102
|
+
interests: # Optional
|
|
103
|
+
- id: "6003139266461"
|
|
104
|
+
name: "Fitness and wellness"
|
|
105
|
+
platforms: ["facebook", "instagram"]
|
|
106
|
+
facebook_positions: ["feed"]
|
|
107
|
+
instagram_positions: ["stream", "story", "reels"]
|
|
108
|
+
|
|
109
|
+
ads:
|
|
110
|
+
- name: "My Ad"
|
|
111
|
+
image: ./images/ad.png # Path relative to YAML file
|
|
112
|
+
primary_text: "Your ad copy."
|
|
113
|
+
headline: "Your Headline"
|
|
114
|
+
description: "Short description"
|
|
115
|
+
cta: LEARN_MORE # See CTAs below
|
|
116
|
+
link: "https://example.com"
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
**Campaign Objectives:** `OUTCOME_TRAFFIC`, `OUTCOME_AWARENESS`, `OUTCOME_ENGAGEMENT`, `OUTCOME_LEADS`, `OUTCOME_SALES`, `OUTCOME_APP_PROMOTION`
|
|
120
|
+
|
|
121
|
+
**Optimization Goals:** `LINK_CLICKS`, `IMPRESSIONS`, `REACH`, `LANDING_PAGE_VIEWS`, `APP_INSTALLS`, `OFFSITE_CONVERSIONS`, `LEAD_GENERATION`
|
|
122
|
+
|
|
123
|
+
**CTA Options:** `LEARN_MORE`, `SIGN_UP`, `DOWNLOAD`, `SHOP_NOW`, `BOOK_NOW`, `GET_OFFER`, `SUBSCRIBE`, `CONTACT_US`, `APPLY_NOW`, `WATCH_MORE`
|
|
124
|
+
|
|
125
|
+
## Commands
|
|
126
|
+
|
|
127
|
+
### `meta-ads create`
|
|
128
|
+
|
|
129
|
+
Create a full campaign from your YAML config.
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
# Preview first
|
|
133
|
+
meta-ads create --dry-run
|
|
134
|
+
|
|
135
|
+
# Deploy (will ask for confirmation)
|
|
136
|
+
meta-ads create
|
|
137
|
+
|
|
138
|
+
# Deploy without confirmation
|
|
139
|
+
meta-ads create --yes
|
|
140
|
+
|
|
141
|
+
# Use a custom config file
|
|
142
|
+
meta-ads create --config path/to/campaign.yaml
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### `meta-ads status <campaign-id>`
|
|
146
|
+
|
|
147
|
+
Check the status of a campaign and all its ads.
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
meta-ads status 120243616427570285
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### `meta-ads pause <campaign-id>`
|
|
154
|
+
|
|
155
|
+
Pause a running campaign.
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
meta-ads pause 120243616427570285
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### `meta-ads activate <campaign-id>`
|
|
162
|
+
|
|
163
|
+
Activate a paused campaign. This starts spending your budget.
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
meta-ads activate 120243616427570285
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### `meta-ads delete <campaign-id>`
|
|
170
|
+
|
|
171
|
+
Permanently delete a campaign.
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
meta-ads delete 120243616427570285
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### `meta-ads validate`
|
|
178
|
+
|
|
179
|
+
Validate your YAML config without making any API calls.
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
meta-ads validate --config campaign.yaml
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## Getting a Meta Access Token
|
|
186
|
+
|
|
187
|
+
This is the part most people get stuck on. Here is the short version:
|
|
188
|
+
|
|
189
|
+
1. Go to [Meta for Developers](https://developers.facebook.com/) and create an app (type: Business)
|
|
190
|
+
2. Open the [Graph API Explorer](https://developers.facebook.com/tools/explorer/)
|
|
191
|
+
3. Select your app, then request these permissions: `ads_management`, `pages_read_engagement`, `pages_show_list`
|
|
192
|
+
4. Click "Generate Access Token" and authorize
|
|
193
|
+
5. Copy the token to your `.env` file
|
|
194
|
+
|
|
195
|
+
**Important:** Graph API Explorer tokens expire after about 2 hours. For production use, exchange it for a long-lived token:
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
curl "https://graph.facebook.com/v21.0/oauth/access_token?\
|
|
199
|
+
grant_type=fb_exchange_token&\
|
|
200
|
+
client_id=YOUR_APP_ID&\
|
|
201
|
+
client_secret=YOUR_APP_SECRET&\
|
|
202
|
+
fb_exchange_token=YOUR_SHORT_LIVED_TOKEN"
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
Long-lived tokens last about 60 days.
|
|
206
|
+
|
|
207
|
+
## Finding Interest IDs
|
|
208
|
+
|
|
209
|
+
Interest targeting requires Meta's internal IDs. Search for them using the API:
|
|
210
|
+
|
|
211
|
+
```bash
|
|
212
|
+
curl "https://graph.facebook.com/v21.0/search?\
|
|
213
|
+
type=adinterest&\
|
|
214
|
+
q=fitness&\
|
|
215
|
+
access_token=YOUR_TOKEN"
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
This returns interest names and IDs you can use in your campaign YAML.
|
|
219
|
+
|
|
220
|
+
## Examples
|
|
221
|
+
|
|
222
|
+
See the [`examples/`](examples/) directory for ready-to-customize campaign configs:
|
|
223
|
+
|
|
224
|
+
- **[ecommerce.yaml](examples/ecommerce.yaml)**: Product launch targeting skincare enthusiasts
|
|
225
|
+
- **[app-install.yaml](examples/app-install.yaml)**: Mobile app install campaign for fitness users
|
|
226
|
+
|
|
227
|
+
## How It Works
|
|
228
|
+
|
|
229
|
+
This tool wraps the [Meta Marketing API](https://developers.facebook.com/docs/marketing-apis/) with `requests`. No heavy SDKs. The full chain:
|
|
230
|
+
|
|
231
|
+
1. Uploads your ad images to your ad account
|
|
232
|
+
2. Creates a campaign with your objective
|
|
233
|
+
3. Creates an ad set with your budget and targeting
|
|
234
|
+
4. Creates ad creatives linking your images and copy
|
|
235
|
+
5. Creates ads linking creatives to the ad set
|
|
236
|
+
|
|
237
|
+
Everything is created as `PAUSED` by default so you can review before spending.
|
|
238
|
+
|
|
239
|
+
## Want the Full Playbook?
|
|
240
|
+
|
|
241
|
+
We wrote a free guide covering Meta Ads automation end to end: OAuth setup walkthrough, audience segmentation strategy, budget allocation frameworks, creative testing, scaling rules, and common API errors with fixes.
|
|
242
|
+
|
|
243
|
+
**[Get the Guide: The Engineer's Playbook for Meta Ads](https://attainmentlabs.com/meta-ads-playbook)**
|
|
244
|
+
|
|
245
|
+
## Contributing
|
|
246
|
+
|
|
247
|
+
PRs welcome. Keep it simple. This tool is intentionally lightweight.
|
|
248
|
+
|
|
249
|
+
```bash
|
|
250
|
+
git clone https://github.com/attainmentlabs/meta-ads-cli.git
|
|
251
|
+
cd meta-ads-cli
|
|
252
|
+
pip install -e .
|
|
253
|
+
meta-ads --help
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
## License
|
|
257
|
+
|
|
258
|
+
MIT. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# meta-ads-cli campaign config
|
|
2
|
+
# Copy this file and customize for your campaign:
|
|
3
|
+
# cp campaign.example.yaml campaign.yaml
|
|
4
|
+
|
|
5
|
+
campaign:
|
|
6
|
+
name: "Spring Sale - March 2026"
|
|
7
|
+
objective: OUTCOME_TRAFFIC # OUTCOME_TRAFFIC | OUTCOME_AWARENESS | OUTCOME_ENGAGEMENT | OUTCOME_LEADS | OUTCOME_SALES
|
|
8
|
+
status: PAUSED # PAUSED (review first) or ACTIVE (start immediately)
|
|
9
|
+
special_ad_categories: [] # CREDIT | EMPLOYMENT | HOUSING | SOCIAL_ISSUES_ELECTIONS_POLITICS
|
|
10
|
+
|
|
11
|
+
ad_set:
|
|
12
|
+
name: "Broad Interest - 25-44 - US/CA"
|
|
13
|
+
daily_budget: 1000 # In cents. 1000 = $10/day, 5000 = $50/day
|
|
14
|
+
billing_event: IMPRESSIONS
|
|
15
|
+
optimization_goal: LINK_CLICKS # LINK_CLICKS | IMPRESSIONS | REACH | LANDING_PAGE_VIEWS
|
|
16
|
+
bid_strategy: LOWEST_COST_WITHOUT_CAP
|
|
17
|
+
targeting:
|
|
18
|
+
age_min: 25
|
|
19
|
+
age_max: 44
|
|
20
|
+
genders: [0] # 0 = all, 1 = male, 2 = female
|
|
21
|
+
countries: ["US", "CA"]
|
|
22
|
+
interests:
|
|
23
|
+
- id: "6003139266461" # Find IDs via Meta Ad Targeting Search API
|
|
24
|
+
name: "Fitness and wellness"
|
|
25
|
+
- id: "6003107902433"
|
|
26
|
+
name: "Nutrition"
|
|
27
|
+
platforms: ["facebook", "instagram"]
|
|
28
|
+
facebook_positions: ["feed"]
|
|
29
|
+
instagram_positions: ["stream", "story", "reels"]
|
|
30
|
+
|
|
31
|
+
ads:
|
|
32
|
+
- name: "Feed Ad - V1"
|
|
33
|
+
image: ./images/feed-1080x1080.png # Relative to this YAML file
|
|
34
|
+
primary_text: |
|
|
35
|
+
Your primary ad text goes here.
|
|
36
|
+
|
|
37
|
+
This is the main copy your audience will see.
|
|
38
|
+
Use line breaks for readability.
|
|
39
|
+
headline: "Your Headline Here"
|
|
40
|
+
description: "Short description text."
|
|
41
|
+
cta: LEARN_MORE # LEARN_MORE | SIGN_UP | DOWNLOAD | SHOP_NOW | BOOK_NOW | GET_OFFER
|
|
42
|
+
link: "https://example.com"
|
|
43
|
+
|
|
44
|
+
- name: "Story Ad - V1"
|
|
45
|
+
image: ./images/story-1080x1920.png
|
|
46
|
+
primary_text: "Shorter copy works better for stories. Keep it punchy."
|
|
47
|
+
headline: "Your Headline Here"
|
|
48
|
+
description: "Short description."
|
|
49
|
+
cta: LEARN_MORE
|
|
50
|
+
link: "https://example.com"
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Mobile app install campaign
|
|
2
|
+
# Target: US/CA/UK fitness enthusiasts 18-34
|
|
3
|
+
|
|
4
|
+
campaign:
|
|
5
|
+
name: "App Launch - Q1 2026"
|
|
6
|
+
objective: OUTCOME_TRAFFIC # Use OUTCOME_APP_PROMOTION if your app is registered in Meta
|
|
7
|
+
status: PAUSED
|
|
8
|
+
|
|
9
|
+
ad_set:
|
|
10
|
+
name: "Fitness Enthusiasts - 18-34"
|
|
11
|
+
daily_budget: 1500 # $15/day
|
|
12
|
+
optimization_goal: LINK_CLICKS
|
|
13
|
+
targeting:
|
|
14
|
+
age_min: 18
|
|
15
|
+
age_max: 34
|
|
16
|
+
genders: [0]
|
|
17
|
+
countries: ["US", "CA", "GB"]
|
|
18
|
+
interests:
|
|
19
|
+
- id: "6003139266461"
|
|
20
|
+
name: "Fitness and wellness"
|
|
21
|
+
- id: "6003384248805"
|
|
22
|
+
name: "Physical fitness"
|
|
23
|
+
- id: "6003659420716"
|
|
24
|
+
name: "Weight training"
|
|
25
|
+
platforms: ["facebook", "instagram"]
|
|
26
|
+
facebook_positions: ["feed"]
|
|
27
|
+
instagram_positions: ["stream", "story", "reels"]
|
|
28
|
+
|
|
29
|
+
ads:
|
|
30
|
+
- name: "App Screenshot - Feed"
|
|
31
|
+
image: ./images/app-screenshot-1080x1080.png
|
|
32
|
+
primary_text: |
|
|
33
|
+
Track your workouts in 30 seconds.
|
|
34
|
+
|
|
35
|
+
No complicated setup. Open the app, tap your exercises, done.
|
|
36
|
+
Free for 7 days. $4.99/mo after that.
|
|
37
|
+
headline: "The Workout App That Gets Out of Your Way"
|
|
38
|
+
description: "Free 7-day trial."
|
|
39
|
+
cta: DOWNLOAD
|
|
40
|
+
link: "https://apps.apple.com/app/your-app-name/id1234567890"
|
|
41
|
+
|
|
42
|
+
- name: "Feature Highlight - Story"
|
|
43
|
+
image: ./images/feature-highlight-1080x1920.png
|
|
44
|
+
primary_text: "Finally, a workout tracker that takes 30 seconds. Try free."
|
|
45
|
+
headline: "Track Workouts in 30 Seconds"
|
|
46
|
+
description: "Free 7-day trial."
|
|
47
|
+
cta: DOWNLOAD
|
|
48
|
+
link: "https://apps.apple.com/app/your-app-name/id1234567890"
|