Skip to main content

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

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)
facebook-leads-cli --help

# Run CLI (when running from source)
uv run python src/fb.py --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
facebook-leads-cli whoami Verify token, show connected account info
facebook-leads-cli status System health check (API connectivity)

Lead Gen API

Command Description
facebook-leads-cli forms list List all lead forms on page
facebook-leads-cli forms show <form_id> Show form details
facebook-leads-cli leads fetch --days=7 Fetch leads from all forms
facebook-leads-cli leads list --form=<id> List leads from specific form

Conversions API

Command Description
facebook-leads-cli conversions test Send a test event to verify setup
facebook-leads-cli conversions send --file=data.json Send conversion events from file

Examples

Verify Authentication

facebook-leads-cli whoami

Example output:

✓ Authentication successful!

Page: My Business Page (ID: 107534675430395)
Pixel ID: 1758183674728645

Check System Health

facebook-leads-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

facebook-leads-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

facebook-leads-cli leads fetch --days=7 --json > leads.json

Send Test Conversion

facebook-leads-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

  1. Go to Facebook Graph API Explorer
  2. Select your app
  3. Click "Generate Access Token"
  4. Copy the token and set it as FB_ACCESS_TOKEN

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

facebook_leads_cli-0.2.2.tar.gz (16.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

facebook_leads_cli-0.2.2-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file facebook_leads_cli-0.2.2.tar.gz.

File metadata

  • Download URL: facebook_leads_cli-0.2.2.tar.gz
  • Upload date:
  • Size: 16.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.22

File hashes

Hashes for facebook_leads_cli-0.2.2.tar.gz
Algorithm Hash digest
SHA256 e0d5907f8825aec4d2e24d8fceecbbaa355f56aa728be5aada3f72ed868734b7
MD5 2b9ddf54c1e991285a5a9516cbac9511
BLAKE2b-256 435d6815ca4fcebf0ebc4d75a4e7a5f5657861c52ab850947c436e88f6d61436

See more details on using hashes here.

File details

Details for the file facebook_leads_cli-0.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for facebook_leads_cli-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 91cc4fe0ea280ae60bf82ad895ab2aae5dd4a8aca94ca40118c123b3609ec62e
MD5 ac087c11ad234cd0aee95ce7f43a266e
BLAKE2b-256 792ed010beaa93d5b0d691208a61c338d504e7b74e2e661b53f17d08de75ba71

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page