Skip to content
BlokloDocumentation

Meta ads

Facebook and Instagram ad campaigns: ad accounts, campaigns and insights (Marketing API).

Connection type: For the app and the agent. Credentials: System user access token.

How it works

The app and the agent never see the credentials. They call the Meta ads API through the Bloklo gateway, for example fetch("/gw/<connection id>/me/adaccounts"). The gateway appends the path to the address https://graph.facebook.com/v27.0, adds an Authorization: Bearer … header with the key from the connection, and passes the service's response back to the app.

  • Reads (GET) go through at once. Writes (POST, PUT, PATCH, DELETE) go through at once only when the connection is set to Always allow; otherwise the gateway returns status 202 with an approval_id and the write waits for approval in the panel (see Agent permissions).
  • The Test button sends GET /me?fields=id,name and checks that the service accepted the credentials.

The Marketing API on the Graph API (version v27.0) with JSON responses; numeric insight values come back as text. Ad objects have an /insights edge; reports can use date_preset or time_range with level and breakdowns. Cursor pagination through paging.cursors.after while paging.next exists.

Before you start

  • An account with Meta ads with permission to create API keys or tokens.

Where to get the credentials

  1. In Meta Business Suite, open Business settings → Users → System users and add a system user (Admin or Employee role).
  2. Assign assets to it: the ad accounts (Assign assets).
  3. Click Generate token, choose the app, the expiry and the ads_read (insights) and ads_management (campaign changes) permissions, then copy the token (shown once).
Note

A system user token does not expire by default. The Meta app needs Standard Access to the Marketing API.

Meta ads documentation

Connecting in Bloklo

  1. Open Connectors in the sidebar and find Meta ads.
  2. Click Connect and enter a connection name in Details.
  3. In Configure connection, fill in: System user access token.
  4. Click Connect. Bloklo saves the credentials encrypted and sends a test request; the message shows whether the service responded.
  5. Attach the connection to a project: Attach to a project… on the connection page, or describe the task in the project chat and pick the connection the agent suggests.

Form fields

  • System user access token: A Business Manager token with ads_read (insights) and ads_management (campaign changes) permissions.
Important

Never paste credentials into the chat with the agent. Enter them only in the connection form.

Example prompts

Prompts to type in the chat of a project with the connection attached:

  • “Build a dashboard of Meta campaign spend, clicks and CTR for the last 30 days.”
  • “Add a campaigns view with a button that pauses the selected campaign.”
  • “Email a weekly summary of ad spend.”

API methods

The most commonly used Meta ads API methods. The path goes after /gw/<connection id>; parts in braces, such as {id}, are replaced with values. The gateway treats every request other than GET as a write, including queries sent with POST (such as search or GraphQL), so they need approval unless the connection is set to Always allow. The full list of methods is in the provider's documentation.

MethodPathWhat it doesIn the gateway
GET/me/adaccountsList the user's ad accountsread
GET/act_{ad_account_id}/campaignsList an account's campaignsread
POST/act_{ad_account_id}/campaignsCreate a campaignwrite (approval)
GET/act_{ad_account_id}/adsetsList ad setsread
GET/act_{ad_account_id}/adsList adsread
GET/act_{ad_account_id}/insightsAd account insightsread
GET/{campaign_id}/insightsCampaign insightsread
POST/act_{ad_account_id}/insightsAsynchronous report (returns report_run_id)write (approval)
GET/{report_run_id}Asynchronous report statusread
POST/{campaign_id}Update a campaign, e.g. pause (status)write (approval)

Service limits

Limits per ad account, 300 s decay window: a read scores 1 point, a write 3; Development tier maxes at 60 points (blocked 300 s), Full Access at 9,000 (blocked 60 s). Creating and editing campaigns, ad sets and ads: 100 requests per second. One edit per object every 30 s. Hourly pools: ads_management (100,000/300) + 40 per active ad, ads_insights (190,000/600) + 400 per active ad. Ad set budget changes: 4 per hour. Headers X-Business-Use-Case, X-Ad-Account-Usage, X-FB-Ads-Insights-Throttle; codes 4, 17, 613, 80000–80014. Reads reach back up to 37 months.

Meta ads API reference

Agent actions and permissions

ActionTypeWhat the agent uses it for
Read datareadFetches data from the service, such as a list of records, to build and check the app. Examples: list the user's ad accounts; list an account's campaigns; list ad sets.
Write datawriteRequests other than GET: creating, changing or deleting data in the service, and also queries sent with POST (such as search). Examples: create a campaign; asynchronous report (returns report_run_id); update a campaign, e.g. pause (status).
Tip

By default, reads run without asking and writes need approval in the chat. Change this on the connector page or in Settings → Agent permissions (see Agent permissions).

Troubleshooting

The connection test shows “Invalid key” (HTTP 401)

The service did not recognise the credentials: the value is wrong, expired, revoked or was copied with a space. Create a new key at the provider and enter it on the connection page under Change credentials. Empty fields stay unchanged.

The connection test shows “Invalid key” (HTTP 403)

The credentials are rejected or lack the needed permissions, or the service only accepts requests from selected IP addresses. Check the key, extend its permissions at the provider or add the Bloklo gateway IP address (shown in Settings → Privacy & security) to the allowlist.

The test returns another HTTP code

The Test button sends the service a read request that requires valid credentials. A code other than 401 and 403 usually means a temporary problem at the service or a restriction on the account at the provider; include the error code shown with the result in a problem report.

Limits and security

  • One connection can make up to 1,000 requests per minute; the service's own limits also apply.
  • Credentials are encrypted and not shown in the browser after saving; only the names of stored fields are visible.
  • A published app works for every visitor: protect the data the connection gives access to with sign-in in the app.

Something unclear or out of date? Contact us