For end users
Meta Marketing API integration
Connects Pectus to a Meta Business Manager so it can pull Facebook + Instagram ad performance — daily spend, impressions, clicks, conversions per campaign.
Approval delay: none for Development-mode access against ad accounts the Business Manager owns. Standard access (which lets the app read accounts outside the BM) requires app review and takes 2–6 weeks. For most installs, Development access is sufficient.
Env vars set by this flow:
META_APP_ID=
META_APP_SECRET=
META_ACCESS_TOKEN=
META_AD_ACCOUNT_ID=
Prerequisite: the user installing Pectus must have admin access to their Meta Business Manager. Only an admin can mint a System User token.
1. Create a Meta Developer App
- Go to https://developers.facebook.com/apps
- Click Create app
- Use case: Other → Business
- App name: e.g.
Pectus Marketing API - Business Manager: pick the user’s BM
- Click Create app
You’ll land on the app dashboard.
2. Add the Marketing API product
- From the app dashboard, scroll to Add products to your app (or click Products in the left nav)
- Find Marketing API in the list
- Click Set up
Marketing API now appears in the left sidebar.
3. Grab the App ID + App Secret
- Left sidebar → App settings → Basic
- App ID is at the top — copy it →
META_APP_ID - App secret is below — click Show, copy it →
META_APP_SECRET
4. Create a System User in Business Manager
System User tokens don’t expire (unlike User tokens, which expire in 60 days). This is the right pattern for server-side integrations.
- Go to https://business.facebook.com
- Click the gear icon (top right) — Business settings
- Left nav → Users → System users
- Click Add (top right)
- Name:
Pectus API Reader(or similar) - Role: Employee (NOT Admin — we only need read access)
- Click Create system user
5. Link the app to the Business Manager
The “no permissions available” error in the next step is usually because the app isn’t linked to the BM. Do this preemptively.
- Business Settings → Accounts → Apps
- If the app you created isn’t listed, click Add → Add an app and paste the App ID
- Save
6. Assign the Ad Account to the System User
- Business Settings → Users → System users → [the user you created]
- Click Add assets
- Choose Ad accounts
- Tick the ad account(s) Pectus should read
- Permission: tick View performance (read-only). Leave Manage campaigns OFF.
- Save
7. Assign the App to the System User
- Same System User → Add assets
- Choose Apps this time
- Tick the Pectus app you created
- Toggle Develop app on
- Save
8. Generate the access token
- Same System User → Generate new token
- App: pick the Pectus app
- Token expiration: Never
- Available scopes — tick:
ads_readbusiness_management
- Click Generate token
You’ll see the token once. Copy it → META_ACCESS_TOKEN.
If ads_read isn’t shown in the available scopes, the app isn’t linked to the System User properly. Go back to step 7.
9. Get the Ad Account ID
The Ad Account ID has the prefix act_ when used in API calls. You can find it in the Ads Manager URL:
https://adsmanager.facebook.com/adsmanager/manage/...?act=123456789012345
The number after act= is the Ad Account ID. Save it as META_AD_ACCOUNT_ID=act_123456789012345 (with the act_ prefix).
10. Verify
Once your credentials are saved, open the per-app page in the CMS at /apps/meta and click Test connection. Pectus runs a small probe call against the API and surfaces the response inline.
Common errors
(#100) Tried accessing nonexisting field "..." — the API version specified in the SDK is no longer supported. Meta deprecates major versions on a rolling basis. Update the SDK and the version pinned in apps/meta/client.ts.
(#10) Application does not have permission for this action — the System User doesn’t have the app assigned with develop permission, OR the app doesn’t have the Marketing API product enabled. Check steps 2 and 7.
Invalid OAuth access token — token was revoked. System User tokens can be revoked if the user is removed from the BM, the app is unlinked, or someone explicitly invalidates it. Re-do step 8.
Empty response with no error — usually means the System User doesn’t have access to the ad account you’re querying. Re-check step 6 and the act_ prefix on the ad account ID.
Why Development-mode access is fine for most users
Meta apps in Development mode can read any ad account that the Business Manager owns or has been granted access to. The “Standard Access” review tier is only needed if the app needs to read ad accounts that aren’t in the user’s BM (e.g. a SaaS product that connects multiple customers’ BMs through one Meta app). Pectus is self-hosted, so each install only needs to read its own BM.