Skip to main content
Languages: every operation supports cURL, Node.js (TypeScript), Python, Go, Ruby, and PHP. The first 15 operations on this page show all six languages; the remaining 6 show cURL and TypeScript — the two most-used.

Ads API

Ads endpoints exposed by the Devotel CPaaS API Base path: /api/v1/ads Endpoint count: 19

title: “Errors worth branching on” description: “Per-endpoint failure templates matching the envelope — what actually fires, what to retry, what to surface to the operator.”

Errors worth branching on

These five failures cover the ads stats sync (POST /api/v1/ads/sync), on every stats pull from the account linker. Each block below is a full { error, meta } envelope as the API returns it, and the matrix at the bottom answers retry vs surface for the same five classes. For the platform-wide decision table these branches plug into, see the error handling guide.

401 — Unauthorized

A 401 on this page is the bearer key failing before the route ran — it never means the resource is wrong. Rotate the key or re-mint the scoped token; retrying the same request changes nothing.

403 — Forbidden

A 403 means the key authenticated but the operation is gated by scope — check the key’s scopes on the developer page; a 403 is never a data-not-found shape.

422 — Schema

A 422 means the payload did not match the request schema — branch on error.details.field and list campaigns first and resend with an existing campaign id instead of blind-retrying the same body.

429 — Rate

The Retry-After header and error.details.retry_after are both set on every 429 — resend the SAME request after the lower of the two.

402 — Feature gate

Surface the connect-account screen — the stats/read endpoints still return data; only mutation is gated.

60-second retry matrix

Worked samples — ads audiences, campaigns, attribution

Copy a request as written, substitute your own ids, and compare the response envelope — a success in the same { data, meta } shape the numbered error sections spell out. Every operation below supports cURL, Node.js (TypeScript), Python, Go, Ruby, and PHP; for brevity each sample shows cURL and TypeScript — the two most-used — and a link to the per-operation block further down the page carries the other four languages. The sequence at the end (create an audience → bind it to a campaign → read back insights → export attribution) is the path most workspaces take from segment to measured spend.

1. Create a custom audience

POST /api/v1/ads/audiences
Creates a Meta Custom Audience on the connected ad account, optionally linked to a CDP segment so its membership can be synced later. Pass name, an optional description, and an optional segment_id to bind the audience to a segment on creation; leave segment_id out and bind it later at sync time. Request
Response
The persisted record carries the Meta-assigned audience_id plus the segment_id link you sent. last_synced_at and last_sync_count stay null until the first /sync run pushes membership; read the audience back any time with GET /api/v1/ads/audiences to see those two fields fill in. The audience is available for targeting on Meta as soon as it is created — there is no separate status poll on Orbit’s side.

2. List ad campaigns

GET /api/v1/ads/campaigns
Returns the click-to-chat campaigns on the connected Meta ad account as a cursor-paginated list. When no ad account is connected the list is empty rather than an error, so the dashboard renders cleanly before setup. Request
Response
Page forward with ?cursor=1202103894124 until has_more is false. Budget strings come straight from Meta in the account’s currency — surface GET /api/v1/ads/status to read what that currency is.

3. Read one campaign with its insights

GET /api/v1/ads/campaigns/{id}
Returns one campaign plus a flattened insights summary (impressions, reach, clicks, CTR, spend, CPC, and conversations started) for the details view. The insights block is always included — no query param is needed. Request
Response
All metric fields are flattened onto one object (not the one-element array Meta’s Graph returns), so the details read is a single top-level insights.

4. Read attribution rollups per channel

GET /api/v1/ads/ctwa/attribution
Rolls up Click-to-WhatsApp (and RCS) entry points captured on inbound messages by ad: entry volume, distinct first-touched contacts, first-touch attributed revenue from local WhatsApp catalog orders, and — when a Meta ad account is connected — ad-spend-overlaid ROAS/ROI per ad. window_days (default 30, max 365) sets the look-back for both sides of the ratio. Request
Response
When no ad account is connected the same shape comes back with spend_available: false, roas: null, and cost_status: "no_spend" — entry counts and attributed revenue still roll up, only the spend overlay degrades.

5. Read audience status transitions

GET /api/v1/ads/audiences and GET /api/v1/ads/status
There are two status surfaces. GET /api/v1/ads/audiences is the per-audience view — the sync metadata on each stored audience tells you whether it has ever pushed membership and when. GET /api/v1/ads/status is the connection-level view the dashboard polls — whether a Meta ad account is linked, which ad_account_id, the currency, and whether a Conversions API dataset is set. Request — per-audience sync state
Response
last_synced_at: null marks an audience that has not yet synced — the empty state before the first POST .../sync. A filled pair means the last push completed and carried last_sync_count members. Request — connection status
Response
Before any account is linked the same endpoint answers 200 with connected: false, ad_account_id: null, and currency: null — a clean pre-setup state, not an error.

6. A 4-op sequence: audience → campaign → insights → attribution

The path from a CDP segment to a measured ROAS. Run the four operations in order; the id from step 1 feeds step 2, the campaign id from step 2 feeds step 3, and step 4 closes the loop.
Sequence
The attribution export in step 4 attributes local WhatsApp catalog revenue first-touch to the entry ad and overlays Meta ad spend for ROAS — the report the dashboard’s ads console renders.

Vacuum shells resolved

The six operations below previously rendered an empty data object on this page because their OpenAPI 2xx responses carry no JSON schema. Each envelope here mirrors the shape the route actually returns — attribution rollups, connection status, conversion receipts, lead-ingest counters, the OAuth exchange token store, and the auto-forward toggle ack — so what you see is what your code receives.

List attribution

GET /api/v1/ads/ctwa/attribution

List status

GET /api/v1/ads/status

Conversions ads

POST /api/v1/ads/conversions

Ingest leads

POST /api/v1/ads/leads/ingest

Exchange oauth

POST /api/v1/ads/oauth/exchange

Update auto-forward

PUT /api/v1/ads/conversions/auto-forward

List custom audiences

GET /api/v1/ads/audiences
Returns the Meta Custom Audiences this workspace has created, each with its linked CDP segment (if any) and last-sync metadata. Read-only; returns an empty list when no audiences exist or no ad account is connected.

List ad campaigns

GET /api/v1/ads/campaigns
Returns the click-to-chat ad campaigns on the connected Meta ad account as a cursor-paginated list. When no ad account is connected the list is empty rather than an error, so the dashboard renders cleanly before setup. Page with the limit and cursor query parameters.

Get an ad campaign with insights

GET /api/v1/ads/campaigns/{id}
Returns one campaign together with a flattened insights summary (impressions, reach, clicks, CTR, spend, CPC, and conversations started) for the campaign details view. The path parameter is the Meta campaign id.
string
required
—

List attribution

GET /api/v1/ads/ctwa/attribution

List status

GET /api/v1/ads/status

Create a custom audience

POST /api/v1/ads/audiences
Creates a Meta Custom Audience on the connected ad account, optionally linked to a CDP segment so its membership can be synced later. The Meta-assigned audience id and the segment link are stored on the connection. Owner or admin only.

Sync a segment to a custom audience

POST /api/v1/ads/audiences/{audienceId}/sync
Uploads a CDP segment’s current membership to a Meta Custom Audience so it can be targeted (mode add, the default) or suppressed (mode remove) in ads. The segment id comes from the body, falling back to the link recorded when the audience was created. Owner or admin only.
string
required
—

Create an ad campaign

POST /api/v1/ads/campaigns
Creates a click-to-chat ad campaign on the connected Meta ad account that routes taps into WhatsApp, Messenger, or Instagram Direct. Provide the name, objective, daily budget, destination, ad copy, and optional targeting; the campaign is created PAUSED so you can review it before launching. Owner or admin only.

Connect a Meta ad account

POST /api/v1/ads/connect
Links a Meta (Facebook) ad account to this workspace by storing an OAuth access token and the selected ad account id. Call it once after the user authorizes in Facebook; the token is encrypted at rest and reused by the campaigns, audiences, and Conversions API endpoints. The response warns when no Conversions API dataset id is configured yet. Owner or admin only.

Conversions ads

POST /api/v1/ads/conversions

Send a test conversion event

POST /api/v1/ads/conversions/test
Sends a test event to the Meta Conversions API to verify that the connected ad account and its dataset id are wired correctly. Use it after setting a dataset id to confirm CAPI delivery before posting real conversions. Requires a connected account with a dataset id. Owner or admin only.

Ingest leads

POST /api/v1/ads/leads/ingest

Exchange oauth

POST /api/v1/ads/oauth/exchange

Update an ad campaign

PUT /api/v1/ads/campaigns/{id}
Updates a campaign on the connected Meta ad account — for example to change its status (pause or resume), rename it, or adjust the daily budget. Only the fields you send are changed. Owner or admin only.
string
required
—

Update auto-forward

PUT /api/v1/ads/conversions/auto-forward

Set the Conversions API dataset

Need this flow in Python, Go, Ruby, or PHP? The Worked sequences section renders this surface’s hero flows in the full six-language group.
PUT /api/v1/ads/conversions/dataset
Sets or replaces the Meta Conversions API (CAPI) dataset id on the connected ad account so server-side conversion events can be posted. The id is written in place without disturbing the stored access token or ad account id. A dataset id must be set before the test-conversion and conversion-posting endpoints will work. Owner or admin only.

Delete a custom audience

DELETE /api/v1/ads/audiences/{audienceId}
Deletes a Meta Custom Audience at Meta and drops its stored mapping from the connection. This cannot be undone. Owner or admin only. Returns 204 No Content on success.
string
required
—
Response: 204 No Content

Delete an ad campaign

DELETE /api/v1/ads/campaigns/{id}
Permanently deletes a campaign from the connected Meta ad account. This removes the campaign at Meta, not just its local reference, and cannot be undone. Owner or admin only. Returns 204 No Content on success.
string
required
—
Response: 204 No Content

Delete disconnect

DELETE /api/v1/ads/disconnect

Worked sequences

The page above trims every operation past the fifteenth to cURL plus TypeScript. This section renders the first hero flow(s) past the cut in the full six-language group, so the operation a pipeline reaches next is copy-paste complete.

Set the Conversions API dataset

Delete a custom audience