A command-line interface for the Google Ads API, enabling programmatic access to campaigns, ad groups, keywords, and the Keyword Planner tool. Built with Node.js and TypeScript.
- 🔐 OAuth 2.0 Authentication - Secure authentication with automatic token refresh
- 📊 Campaign Management - List and view campaigns, ad groups, and performance metrics
- 🔍 Keyword Planner - Generate keyword ideas with search volume and competition data
- 📈 Custom Reports - Execute GAQL (Google Ads Query Language) queries
- 👥 Multi-Profile Support - Manage multiple Google Ads accounts
- 🎨 Rich Output - Table formatting and JSON export options
- 💾 Secure Storage - Encrypted credential storage with 0600 file permissions
Before using this CLI, you need:
- Google Cloud Project with Google Ads API enabled
- OAuth 2.0 Credentials (Desktop application type)
- Developer Token from Google Ads API Center
- Google Ads Customer ID (10-digit account ID)
- Go to Google Cloud Console
- Create a new project or select an existing one
- Enable the Google Ads API:
- Navigate to APIs & Services > Library
- Search for "Google Ads API"
- Click Enable
- Go to APIs & Services > OAuth consent screen
- Choose External user type
- Fill in the required fields:
- App name:
Google Ads CLI - User support email: Your email
- Developer contact: Your email
- App name:
- Click Save and Continue
- Add scopes:
https://www.googleapis.com/auth/adwords - Add Test Users: Add your Google account email
- Complete the setup
- Go to APIs & Services > Credentials
- Click Create Credentials > OAuth client ID
- Choose Desktop app as application type
- Name it (e.g., "Google Ads CLI Desktop")
- Click Create
- Download or copy the Client ID and Client Secret
- Sign in to your Google Ads account
- Click Tools & Settings (wrench icon)
- Under Setup, click API Center
- Copy your Developer Token
Note: New developer tokens start in "Test" mode, which limits API access to accounts you own or manage. To access other accounts, you'll need to apply for Standard Access (requires a review process).
- In Google Ads, look at the top right corner
- Your Customer ID is the 10-digit number (format: XXX-XXX-XXXX)
- Remove dashes when entering it (e.g.,
1234567890)
Install globally from npm:
npm install -g google-ads-cliClone the repository and build locally:
git clone https://github.com/hcassar93/google-ads-cli.git
cd google-ads-cli
npm install
npm run build
npm link # Install globallygoogle-ads-cli --version
google-ads-cli --helpConfigure your credentials:
google-ads-cli setupYou'll be prompted for:
- OAuth Client ID
- OAuth Client Secret
- Developer Token
- Customer ID (10 digits, no dashes)
- Login Customer ID (optional, for MCC accounts)
Run the OAuth flow to get access tokens:
google-ads-cli authThis will:
- Open your browser for Google authentication
- Prompt you to authorize the application
- Store access and refresh tokens securely
List your campaigns:
google-ads-cli campaignsGenerate keyword ideas:
google-ads-cli keyword-ideas "seo tools" "digital marketing"google-ads-cli setupConfigure API credentials for a new profile.
google-ads-cli auth [-p <profile>]Authenticate and obtain access tokens.
google-ads-cli logout [-p <profile>]Clear stored credentials.
google-ads-cli config [-p <profile>]Display current configuration.
# List all profiles
google-ads-cli profiles --list
# Switch active profile
google-ads-cli profiles --switchgoogle-ads-cli accounts [--json]google-ads-cli campaigns [-l <limit>] [--json]Options:
-l, --limit <number>- Maximum campaigns to return (default: 50)--json- Output as JSON
Example:
google-ads-cli campaigns -l 10google-ads-cli campaign <campaign-id> [--json]Example:
google-ads-cli campaign 1234567890google-ads-cli ad-groups -c <campaign-id> [-l <limit>] [--json]Options:
-c, --campaign-id <id>- Campaign ID (required)-l, --limit <number>- Maximum ad groups to return (default: 50)
Example:
google-ads-cli ad-groups -c 1234567890google-ads-cli keyword-ideas [keywords...] [options]Options:
-u, --url <url>- URL to get keyword ideas from-l, --language <code>- Language code (default: 1000 for English)--location <codes...>- Location codes (e.g., 2840 for USA)--limit <number>- Maximum ideas to return (default: 50)--json- Output as JSON
Examples:
# From seed keywords
google-ads-cli keyword-ideas "seo tools" "content marketing"
# From URL
google-ads-cli keyword-ideas -u https://example.com
# With location targeting (USA)
google-ads-cli keyword-ideas "digital marketing" --location 2840
# Multiple locations (USA and UK)
google-ads-cli keyword-ideas "software" --location 2840 2826Common Language Codes:
1000- English1003- Spanish1005- French1001- German- Full list
Common Location Codes:
2840- United States2826- United Kingdom2036- Australia2124- Canada- Search locations
google-ads-cli locations <search> [-l <limit>] [--json]Options:
-l, --limit <number>- Maximum results (default: 20)
Examples:
google-ads-cli locations "New York"
google-ads-cli locations "California"
google-ads-cli locations "United"google-ads-cli query <gaql> [-f <file>] [--json]Options:
-f, --file <path>- Read query from file--json- Output as JSON
Examples:
# Inline query
google-ads-cli query "SELECT campaign.id, campaign.name FROM campaign WHERE campaign.status = 'ENABLED' LIMIT 10"
# From file
google-ads-cli query "" -f query.gaqlExample GAQL queries:
Top performing campaigns:
SELECT
campaign.id,
campaign.name,
metrics.impressions,
metrics.clicks,
metrics.cost_micros
FROM campaign
WHERE campaign.status = 'ENABLED'
AND metrics.impressions > 0
ORDER BY metrics.clicks DESC
LIMIT 10Keyword performance:
SELECT
ad_group_criterion.keyword.text,
metrics.impressions,
metrics.clicks,
metrics.ctr,
metrics.cost_micros
FROM keyword_view
WHERE segments.date DURING LAST_30_DAYS
ORDER BY metrics.impressions DESC
LIMIT 20Credentials are stored in:
~/.google-ads-cli/config.json
File permissions are automatically set to 0600 (owner read/write only).
Manage multiple Google Ads accounts:
# Create additional profiles during setup
google-ads-cli setup
# Enter a unique profile name when prompted
# List profiles
google-ads-cli profiles --list
# Switch active profile
google-ads-cli profiles --switch
# Use specific profile for a command
google-ads-cli campaigns -p my-other-accountgoogle-ads-cli campaigns
┌────────────┬─────────────────┬──────────┬────────┬─────────────┬────────┬──────────┐
│ ID │ Name │ Status │ Type │ Impressions │ Clicks │ Cost │
├────────────┼─────────────────┼──────────┼────────┼─────────────┼────────┼──────────┤
│ 1234567890 │ My Campaign │ ENABLED │ SEARCH │ 10000 │ 150 │ $123.45 │
└────────────┴─────────────────┴──────────┴────────┴─────────────┴────────┴──────────┘google-ads-cli campaigns --json[
{
"campaign": {
"id": "1234567890",
"name": "My Campaign",
"status": "ENABLED",
"advertising_channel_type": "SEARCH"
},
"metrics": {
"impressions": "10000",
"clicks": "150",
"cost_micros": "123450000"
}
}
]Run the auth command:
google-ads-cli authYour developer token is in test mode. You can only access accounts you own or manage. For broader access, apply for Standard Access in the Google Ads API Center.
Verify your Customer ID:
- Should be 10 digits (no dashes)
- Check in Google Ads top-right corner
- Update if needed:
google-ads-cli setup
Tokens are automatically refreshed. If this persists, re-authenticate:
google-ads-cli authThe OAuth callback uses port 3000. Close conflicting applications or modify src/auth/oauth.ts to use a different port.
Ensure:
- Your email is added as a test user
- Required scopes are added (
https://www.googleapis.com/auth/adwords) - Consent screen is published (at least in testing mode)
- Keyword Planner API: Rate-limited, cache results when possible
- Test Developer Token: Limited to 15,000 operations per day
- Standard Access: Higher limits after approval
npm run buildnpm run dev -- <command>
# Examples
npm run dev -- setup
npm run dev -- campaigns
npm run dev -- keyword-ideas "test"google-ads-cli/
├── src/
│ ├── index.ts # CLI entry point
│ ├── cli.ts # Commander setup
│ ├── auth/ # Authentication logic
│ │ ├── oauth.ts
│ │ ├── credentials.ts
│ │ └── setup.ts
│ ├── api/
│ │ └── google-ads.ts # Google Ads API wrapper
│ ├── commands/ # CLI command implementations
│ │ ├── auth.ts
│ │ ├── accounts.ts
│ │ ├── campaigns.ts
│ │ ├── keywords.ts
│ │ └── reports.ts
│ └── utils/ # Utilities
│ ├── config.ts
│ ├── profiles.ts
│ ├── validation.ts
│ └── formatting.ts
├── dist/ # Compiled JavaScript
├── package.json
└── tsconfig.json
MIT License - see LICENSE file for details.
This is an internal tool for OpenClaw. For issues or feature requests, please open an issue on GitHub.
Hayden Cassar
Note: This tool is designed for programmatic access and requires technical setup. It is not intended for end-users without API knowledge.