A command-line interface for the Meta (Facebook) Ads API, enabling programmatic access to campaigns, ad sets, ads, and insights. Built with Node.js and TypeScript.
- 🔐 OAuth 2.0 Authentication - Secure authentication with long-lived tokens
- 📊 Campaign Management - List and view campaigns, ad sets, and ads
- 📈 Insights & Reporting - Access performance metrics and campaign insights
- 👥 Multi-Profile Support - Manage multiple Meta Ads accounts
- 🎨 Rich Output - Table formatting and JSON export options
- 💾 Secure Storage - Encrypted credential storage with 0600 file permissions
- 🔄 Multiple Ad Accounts - Support for managing multiple ad accounts per profile
Before using this CLI, you need:
- Meta Developer Account with an app created
- App ID and App Secret from your Meta app
- Ad Account Access - You must have access to at least one Meta Ads account
- Go to Meta for Developers
- Click My Apps > Create App
- Choose Business as the app type
- Fill in the app details and create the app
- In your app dashboard, go to Settings > Basic
- Copy your App ID and App Secret
- Add Product: Select Facebook Login
- Under Facebook Login > Settings:
- Add Valid OAuth Redirect URIs:
http://localhost:3000/oauth/callback - Save changes
- Add Valid OAuth Redirect URIs:
- In your app, go to Add Products
- Click Set Up on Marketing API
- Request Standard Access if needed (for production use)
- Go to Meta Ads Manager
- Your Ad Account ID is visible in the URL:
act_XXXXXXXXXX - Copy this ID (including the
act_prefix)
npm install -g meta-ads-cligit clone https://github.com/hcassar93/meta-ads-cli.git
cd meta-ads-cli
npm install
npm run build
npm link # Install globallymeta-ads-cli --version
meta-ads-cli --helpConfigure your credentials:
meta-ads-cli setupYou'll be prompted for:
- Profile name - a local nickname for this saved config (examples:
default,client1). This is just for your machine. - Meta App ID - from Meta Developer Dashboard → Settings → Basic.
- Meta App Secret - from the same place (Settings → Basic).
- Ad Account ID (optional) - from Ads Manager URL, format:
act_XXXXXXXXXX.
If you're unsure about Profile name, keep default.
Run the OAuth flow to get access tokens:
meta-ads-cli authThis will:
- Open your browser for Meta authentication
- Prompt you to authorize the application
- Store long-lived access tokens securely (~60 days)
List your ad accounts:
meta-ads-cli accountsList campaigns:
meta-ads-cli campaigns -a act_123456789meta-ads-cli setupConfigure API credentials for a new profile.
meta-ads-cli auth [-p <profile>]Authenticate and obtain access tokens.
meta-ads-cli logout [-p <profile>]Clear stored credentials.
meta-ads-cli config [-p <profile>]Display current configuration.
# List all profiles
meta-ads-cli profiles --list
# Switch active profile
meta-ads-cli profiles --switchmeta-ads-cli accounts [--json]Shows all ad accounts you have access to.
meta-ads-cli account <account-id> [--json]Example:
meta-ads-cli account act_123456789meta-ads-cli campaigns [-a <account-id>] [-l <limit>] [--json]Options:
-a, --account-id <id>- Ad Account ID (required if not set in profile)-l, --limit <number>- Maximum campaigns to return (default: 50)--json- Output as JSON
Example:
meta-ads-cli campaigns -a act_123456789 -l 10meta-ads-cli campaign <campaign-id> [--insights] [--json]Options:
--insights- Include performance insights (last 30 days)
Example:
meta-ads-cli campaign 120213377777777 --insightsmeta-ads-cli adsets <campaign-id> [-l <limit>] [--json]Example:
meta-ads-cli adsets 120213377777777Credentials are stored in:
~/.meta-ads-cli/config.json
File permissions are automatically set to 0600 (owner read/write only).
Manage multiple Meta Ads accounts:
# Create additional profiles during setup
meta-ads-cli setup
# Enter a unique profile name when prompted
# List profiles
meta-ads-cli profiles --list
# Switch active profile
meta-ads-cli profiles --switch
# Use specific profile for a command
meta-ads-cli campaigns -p my-other-account -a act_123456789meta-ads-cli campaigns -a act_123456789
┌──────────────────┬────────────────────────────┬────────┬──────────────┬───────────────┬────────────┐
│ ID │ Name │ Status │ Objective │ Daily Budget │ Start Time │
├──────────────────┼────────────────────────────┼────────┼──────────────┼───────────────┼────────────┤
│ 120213377777777 │ Summer Sale Campaign │ ACTIVE │ CONVERSIONS │ $50.00 │ 1/15/2024 │
└──────────────────┴────────────────────────────┴────────┴──────────────┴───────────────┴────────────┘meta-ads-cli campaigns -a act_123456789 --json[
{
"id": "120213377777777",
"name": "Summer Sale Campaign",
"status": "ACTIVE",
"objective": "CONVERSIONS",
"daily_budget": "5000",
"start_time": "2024-01-15T08:00:00+0000"
}
]Run the auth command:
meta-ads-cli authCreate a profile first:
meta-ads-cli setupEither:
- Provide
--account-idflag:meta-ads-cli campaigns -a act_123456789 - Or set it during setup:
meta-ads-cli setupand enter your Ad Account ID
Tokens are long-lived (~60 days) but do expire. Re-authenticate:
meta-ads-cli authThe OAuth callback uses port 3000. Close conflicting applications or modify src/auth/oauth.ts to use a different port.
Your access token may be invalid or expired. Try:
- Re-authenticating:
meta-ads-cli auth - Creating a new profile:
meta-ads-cli setup
- Marketing API: Rate-limited per app and user
- Test Mode: Limited to accounts you own or manage
- Standard Access: Required for production use with broader access
npm run buildnpm run dev -- <command>
# Examples
npm run dev -- setup
npm run dev -- campaigns -a act_123456789
npm run dev -- campaign 120213377777777 --insightsmeta-ads-cli/
├── src/
│ ├── index.ts # CLI entry point
│ ├── cli.ts # Commander setup
│ ├── auth/ # Authentication logic
│ │ ├── oauth.ts
│ │ └── setup.ts
│ ├── api/
│ │ └── meta-ads.ts # Meta Ads API wrapper
│ ├── commands/ # CLI command implementations
│ │ ├── accounts.ts
│ │ └── campaigns.ts
│ └── utils/ # Utilities
│ └── config.ts
├── dist/ # Compiled JavaScript
├── package.json
└── tsconfig.json
- Meta Marketing API Documentation
- Meta Graph API Explorer
- OAuth Documentation
- Meta Business SDK for Node.js
MIT License - see LICENSE file for details.
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
Hayden Cassar
Note: This tool requires proper Meta app setup and API access. It is designed for developers and marketers with technical knowledge of APIs.