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

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

  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.3.2.tar.gz (20.4 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.3.2-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for facebook_leads_cli-0.3.2.tar.gz
Algorithm Hash digest
SHA256 76df308d4a3748a42e46e52fbe39bce8dd207802e2893c713f23070e2c44d245
MD5 fa8aaf772e85d597982d0ac9b2703c8b
BLAKE2b-256 da1029c47b4bbf888fdf023cdf8b0cada5ac493fbb2dba7a274d83dd88f01e35

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for facebook_leads_cli-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1b58320ff00308c460de095824f5b55a00aec7c6887a91dbdb400572e26dc95d
MD5 7f3f999c0059eeb60c1b1ede0caf2050
BLAKE2b-256 4fc942efc81fa8d0899d1b279a616939afa3907b5e8431533a3c8138e8e065c3

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