# META_ADS

meta-ads endpoints.

**Base URL:** `https://api.trustpager.com/functions/v1/api/v1`

## Endpoints

### POST /meta-ads/copies

Duplicate a Meta ad, ad set or campaign (ad sets and campaigns with everything inside them), optionally into another ad set or campaign, and for a single ad optionally with a different creative (a quick way to test new words or a new picture). The result includes the copy's creative_id. The copy and everything in it is made paused, whatever the original is doing, and spends nothing until switched on with set_meta_ad_status. Needs the meta-ads-manage scope (admins only by default); with meta-ads-manage:write-approval the request waits for a person to approve it. Logged with who made it (list_meta_ad_changes). Returns the copy's id and the ids of everything copied inside it.

**Scopes:** `meta-ads-manage:write` — [full detail](./meta-ads/post-meta-ads-copies.md)

### POST /meta-ads/ads

Create a Meta ad: a creative placed in an ad set. It is created paused and spends nothing: switching it on is a separate step (set_meta_ad_status, which needs the meta-ads-spend permission). A status field anywhere in the request is refused. It appears in the Ad Manager straight away. To run it, the ad, its ad set and its campaign all need switching on with set_meta_ad_status. Needs the meta-ads-manage scope (admins only by default); with meta-ads-manage:write-approval the request waits for a person to approve it. Logged with who made it (list_meta_ad_changes). Returns the new ad id.

**Scopes:** `meta-ads-manage:write` — [full detail](./meta-ads/post-meta-ads-ads.md)

### POST /meta-ads/creatives

Create what an ad looks like: the Page (and Instagram account) it runs as, the picture or video, primary text, headline, description, link and button, or an instant lead form instead of a link. A creative does nothing until an ad uses it (create_meta_ad). Needs the meta-ads-manage scope (admins only by default); with meta-ads-manage:write-approval the request waits for a person to approve it. Logged with who made it (list_meta_ad_changes). Returns the creative id.

**Scopes:** `meta-ads-manage:write` — [full detail](./meta-ads/post-meta-ads-creatives.md)

### POST /meta-ads/ad-sets

Create an ad set inside a Meta campaign: who sees the ads (targeting: locations, age, gender, interests, custom audiences, placements or Advantage+ placements), what Meta optimises for, the budget (unless the campaign has one) and the schedule. For lead-form ads use optimization_goal LEAD_GENERATION, destination_type ON_AD and promoted_object { "page_id": ... }. It is created paused and spends nothing: switching it on is a separate step (set_meta_ad_status, which needs the meta-ads-spend permission). A status field anywhere in the request is refused. Needs the meta-ads-manage scope (admins only by default); with meta-ads-manage:write-approval the request waits for a person to approve it. Logged with who made it (list_meta_ad_changes). Returns the new ad set id.

**Scopes:** `meta-ads-manage:write` — [full detail](./meta-ads/post-meta-ads-ad-sets.md)

### POST /meta-ads/campaigns

Create a Meta campaign (Facebook and Instagram ads) in one of the workspace's ad accounts: name, objective, special ad categories and an optional campaign budget. It is created paused and spends nothing: switching it on is a separate step (set_meta_ad_status, which needs the meta-ads-spend permission). A status field anywhere in the request is refused. Then add an ad set (create_meta_ad_set). Needs the meta-ads-manage scope (admins only by default); with meta-ads-manage:write-approval the request waits for a person to approve it. Logged with who made it (list_meta_ad_changes). Returns the new campaign id.

**Scopes:** `meta-ads-manage:write` — [full detail](./meta-ads/post-meta-ads-campaigns.md)

### POST /meta-ads/pixels

Create a Meta pixel in one of this workspace's connected ad accounts (ad_account_id from list_meta_pixels). Name it after the website it goes on. Returns the new pixel's id and install_code to paste into the website's <head>. Check list_meta_pixels first: one pixel per website is usual, and Meta limits how many pixels an ad account can have.

**Scopes:** `meta-ads:write` — [full detail](./meta-ads/post-meta-ads-pixels.md)

### DELETE /meta-ads/objects/:id

Delete a draft from Meta: a paused campaign, ad set or ad that has never run (no spend, no impressions), or a creative or uploaded image. Anything switched on, or that has ever run, is refused: leave it paused instead, so its results stay. Deleting a campaign deletes everything in it. Needs the meta-ads-manage scope (admins only by default); with meta-ads-manage:write-approval the request waits for a person to approve it. Logged with who made it (list_meta_ad_changes).

**Scopes:** `meta-ads-manage:write` — [full detail](./meta-ads/delete-meta-ads-objects-id.md)

### GET /meta-ads/objects/:id

Read one Meta campaign, ad set, ad or creative straight from Meta, with its full settings: status, budgets (normal amounts), objective; for ad sets the targeting, optimisation goal, schedule and promoted object; for ads and creatives the text, link and picture. Use it before update_meta_ad_object or copy_meta_ad_object.

**Scopes:** `meta-ads:read` — [full detail](./meta-ads/get-meta-ads-objects-id.md)

### GET /meta-ads/report

Ad Manager report for Meta ads over a date range (the Meta tab at /growth/ad-manager): what the workspace's Meta ads (Facebook, Instagram, Messenger and Meta's partner apps) cost and what they earned. Returns totals (spend, impressions, clicks, Meta-counted leads, leads received in TrustPager, booked appointments, showed, proposals sent, won opportunities and their value, cost per lead, cost per appointment, cost per sale, return on ad spend), a split of spend and leads by where the ad ran (platforms), and one row per ad with its campaign, picture and the same numbers. Bookings and sales are counted for leads that arrived in the range. missing_leads flags form leads Meta counted that never reached TrustPager. Meta's numbers are updated every night; pass refresh=true to load the last few days from Meta now. Cost per sale counts won opportunities. unattributed counts Meta leads no ad can be tied to (opportunities with lead source Meta, Facebook or Instagram that came through no lead form, e.g. saw the ad then booked on the website, plus form leads Meta sent without an ad id); they are included in totals but in no ad row. Each ad row also carries its adset_id, campaign_id and configured_status (what the ad itself is set to: ACTIVE or PAUSED), the ids set_meta_ad_status and set_meta_ad_budget take.

**Scopes:** `meta-ads:read` — [full detail](./meta-ads/get-meta-ads-report.md)

### GET /meta-ads/accounts

List the Meta ad accounts this workspace's Meta connection can see, and which ones the Meta tab of the Ad Manager reports on (enabled). On first use the accounts that this workspace's leads came from are switched on automatically.

**Scopes:** `meta-ads:read` — [full detail](./meta-ads/get-meta-ads-accounts.md)

### GET /meta-ads/changes

The log of pauses, resumes and budget changes made to Meta ads from TrustPager (the Ad Manager page or the API), newest first: what changed, the value before and after, whether Meta applied it, who made it, and whether it went through an approval.

**Scopes:** `meta-ads:read` — [full detail](./meta-ads/get-meta-ads-changes.md)

### GET /meta-ads/campaigns

List the campaigns in one of the workspace's Meta ad accounts, straight from Meta, each with its ad sets: id, name, status (what it is set to), effective_status (what Meta is doing), objective, budgets as normal amounts, and ad set goals and schedules. Includes paused drafts that have no ads yet (which get_meta_ads_report does not show).

**Scopes:** `meta-ads:read` — [full detail](./meta-ads/get-meta-ads-campaigns.md)

### GET /meta-ads/audiences

List the custom and lookalike audiences in one of the workspace's Meta ad accounts: id, name, type and approximate size. Use the id in an ad set's targeting: "custom_audiences": [{ "id": "..." }] (or "excluded_custom_audiences").

**Scopes:** `meta-ads:read` — [full detail](./meta-ads/get-meta-ads-audiences.md)

### GET /meta-ads/pages/:page_id/lead-forms

List a Page's Meta instant lead forms: id, name, status (ACTIVE forms can be used), language and lead count. Use the id as lead_form_id in create_meta_ad_creative.

**Scopes:** `meta-ads:read` — [full detail](./meta-ads/get-meta-ads-pages-page-id-lead-forms.md)

### GET /meta-ads/pages

List the Facebook Pages the workspace's Meta connection manages, with the Instagram account linked to each. An ad runs as one of these Pages (page_id in create_meta_ad_creative) and, on Instagram, as its linked account (instagram_account_id).

**Scopes:** `meta-ads:read` — [full detail](./meta-ads/get-meta-ads-pages.md)

### GET /meta-ads/pixels

List the Meta pixels in this workspace's connected ad accounts. A pixel is the snippet on a website that tells Meta who visited and what they did. For each pixel: its id, name, ad account, when it last fired, state ('active' fired in the last 24 hours, 'quiet' fired before that, 'never' has never fired), the events Meta received in the last 7 days (PageView, Lead, Schedule and so on) and install_code ready to paste into a website's <head>. Also returns the ad accounts a pixel can be created in.

**Scopes:** `meta-ads:read` — [full detail](./meta-ads/get-meta-ads-pixels.md)

### GET /meta-ads/targeting-search

Search Meta's targeting options. type 'interest' finds interests by name (id, name, audience size) for targeting.flexible_spec; type 'location' finds countries, regions, cities and postcodes (key, name, type) for targeting.geo_locations. Each result says how to use it.

**Scopes:** `meta-ads:read` — [full detail](./meta-ads/get-meta-ads-targeting-search.md)

### POST /meta-ads/budget

Change the daily or lifetime budget of a Meta ad set or campaign. Amounts are normal amounts in the ad account's currency, like 25 or 25.50 for $25.50 a day, never cents. Send daily_budget when it has a daily budget and lifetime_budget when it has a lifetime budget. When a campaign's budget is set on its ad sets (details.campaign_daily_budget is null), change each ad set instead, and the other way round. A new budget more than 3 times, or less than a third of, the current one is refused unless confirm_large_change is true (this catches dollars-vs-cents mistakes). Needs the meta-ads-spend scope; with meta-ads-spend:write-approval the change waits for a person to approve it. Every change is logged (list_meta_ad_changes). Returns the budget before and after.

**Scopes:** `meta-ads-spend:write` — [full detail](./meta-ads/post-meta-ads-budget.md)

### POST /meta-ads/status

Pause or resume a Meta ad, ad set or campaign (Facebook and Instagram ads) from the Ad Manager. status 'paused' stops it spending; status 'active' switches it back on and starts spending its budget again (an ad only runs when its ad set and campaign are on too). Ids come from get_meta_ads_report (ad_id, adset_id, campaign_id). Only ads, ad sets and campaigns in this workspace's Ad Manager can be changed. Needs the meta-ads-spend scope; with meta-ads-spend:write-approval the change waits for a person to approve it. Every change is logged with who made it (list_meta_ad_changes). Returns the status before and after.

**Scopes:** `meta-ads-spend:write` — [full detail](./meta-ads/post-meta-ads-status.md)

### PATCH /meta-ads/accounts

Choose which Meta ad accounts the Meta tab of the Ad Manager reports on. Pass accounts as a list of { ad_account_id, enabled }. Only accounts listed by list_meta_ad_accounts can be changed.

**Scopes:** `meta-ads:write` — [full detail](./meta-ads/patch-meta-ads-accounts.md)

### PATCH /meta-ads/objects/:id

Edit an existing Meta campaign, ad set or ad: rename any of them, change an ad set's targeting or schedule, or switch an ad to a different creative. Status and budget can't be changed here (a request carrying either is refused): use set_meta_ad_status and set_meta_ad_budget. Editing something that is running changes it live. Needs the meta-ads-manage scope (admins only by default); with meta-ads-manage:write-approval the request waits for a person to approve it. Logged with who made it (list_meta_ad_changes). Returns the values before and after.

**Scopes:** `meta-ads-manage:write` — [full detail](./meta-ads/patch-meta-ads-objects-id.md)

### POST /meta-ads/images

Add a picture to a Meta ad account's image library from a public link (JPG or PNG, up to 8 MB; 1080x1080 or 1080x1350 work best). Returns image_hash for create_meta_ad_creative. Needs the meta-ads-manage scope (admins only by default); with meta-ads-manage:write-approval the request waits for a person to approve it. Logged with who made it (list_meta_ad_changes).

**Scopes:** `meta-ads-manage:write` — [full detail](./meta-ads/post-meta-ads-images.md)

### POST /meta-ads/videos

Add a video to a Meta ad account from a public link to the video file (MP4 or MOV). Meta fetches and processes it, which takes a few minutes; then use video_id in create_meta_ad_creative. Needs the meta-ads-manage scope (admins only by default); with meta-ads-manage:write-approval the request waits for a person to approve it. Logged with who made it (list_meta_ad_changes).

**Scopes:** `meta-ads-manage:write` — [full detail](./meta-ads/post-meta-ads-videos.md)
