Facebook Lead Ads and Conversions API CLI
Project description
fb-cli
A Python CLI tool for Facebook Lead Ads and Conversions API. Fetch leads, manage forms, and send conversion events.
Installation
Option 1: Install from PyPI (recommended)
pip install facebook-leads-cli
After installation, run with:
fb-cli --help
Note: The package name (
facebook-leads-cli) differs from the command (fb-cli). This is intentional — the package name is descriptive for discoverability, while the command is short for convenience.
Option 2: Run directly from source
Requires UV (fast Python package manager).
# Install UV (if not already installed)
brew install uv
# Clone and sync dependencies
git clone https://github.com/thaddeus-git/fb-cli.git
cd fb-cli
uv sync
Quick Start
# Run tests
uv run python -m unittest discover tests/
# Run CLI (when installed via pip)
fb-cli --help
# Run CLI (when running from source)
uv run python -m src.fb --help
Configuration
Set environment variables (copy from .env.example):
export FB_ACCESS_TOKEN="your_access_token"
export FB_PIXEL_ID="your_pixel_id"
export FB_PAGE_ID="your_page_id"
export FB_PAGE_ACCESS_TOKEN="your_page_access_token" # Recommended for lead retrieval
Commands
Authentication & Status
| Command | Description |
|---|---|
fb-cli whoami |
Verify token, show connected account info |
fb-cli status |
System health check (API connectivity) |
Lead Gen API
| Command | Description |
|---|---|
fb-cli forms list |
List all lead forms on page |
fb-cli forms show <form_id> |
Show form details |
fb-cli leads fetch --days=7 |
Fetch leads from all forms |
fb-cli leads list --form=<id> |
List leads from specific form |
Conversions API
| Command | Description |
|---|---|
fb-cli conversions test |
Send a test event to verify setup |
fb-cli conversions send --file=data.json |
Send conversion events from file |
Examples
Verify Authentication
fb-cli whoami
Example output:
✓ Authentication successful!
Page: My Business Page (ID: 107534675430395)
Pixel ID: 1758183674728645
Check System Health
fb-cli status
Example output:
Checking Facebook API connectivity...
✓ Authentication: OK
Page: My Business Page
✓ Lead Gen API: OK
Forms found: 10
✓ Conversions API: Configured
Pixel ID: 1758183674728645
✓ System health check complete
Fetch Recent Leads
fb-cli leads fetch --days=7
Example output:
Fetching leads from the past 7 days (limit: 1000 per form)...
✓ Fetched 42 lead(s)
ID Created Form
-----------------------------------------------------------------
9876543210987654 2026-02-25T10:30:00 Contact Form
8765432109876543 2026-02-24T15:45:00 Newsletter Signup
Export Leads as JSON
fb-cli leads fetch --days=7 --json > leads.json
Send Test Conversion
fb-cli conversions test
Example output:
Sending test conversion event...
✓ Test event sent successfully!
Response: {'events_received': 1, 'event_ids': ['test_12345']}
Environment Variables
| Variable | Required | Description |
|---|---|---|
FB_ACCESS_TOKEN |
Yes | Facebook API access token |
FB_PIXEL_ID |
Yes* | Pixel ID for Conversions API |
FB_PAGE_ID |
Yes* | Page ID for Lead Gen API |
FB_PAGE_ACCESS_TOKEN |
Recommended | Page token for lead retrieval |
FB_APP_ID |
Optional | App ID for additional API calls |
FB_TEST_EVENT_CODE |
Optional | Test event code for debugging |
*At least one of FB_PIXEL_ID or FB_PAGE_ID must be set.
Getting Your Access Token
- Go to Facebook Graph API Explorer
- Select your app
- Click "Generate Access Token"
- Copy the token and set it as
FB_ACCESS_TOKEN
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file facebook_leads_cli-0.2.5.tar.gz.
File metadata
- Download URL: facebook_leads_cli-0.2.5.tar.gz
- Upload date:
- Size: 19.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
03860659696de8bfb032a6f83537f98a771fe3d8d23e4f47d8032e97442c846f
|
|
| MD5 |
1858949017b564b7f897f45926ce96e8
|
|
| BLAKE2b-256 |
6c09b15dba69a6c65aee75bcfc815a8c52810d2b626a2d78309dd722397fc208
|
File details
Details for the file facebook_leads_cli-0.2.5-py3-none-any.whl.
File metadata
- Download URL: facebook_leads_cli-0.2.5-py3-none-any.whl
- Upload date:
- Size: 11.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0b3199657ebc342c2561b74c8a1da0da63645738184a80ded543a476039af721
|
|
| MD5 |
ecc662194d923aed7014247a332f3775
|
|
| BLAKE2b-256 |
288cb79c516ec8987d528df1818d17220e84f25fe0fd375044cc8d166aa86531
|