# MARKETING

marketing endpoints.

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

## Endpoints

### POST /marketing/plan/:plan_id/goals

Add a goal to the plan, e.g. { name: "Income $10,000 a month", metric: "revenue_monthly", target_value: 10000, unit: "AUD", deadline: "2027-01-30" }. Returns it with its progress straight away.

**Scopes:** `marketing:write` — [full detail](./marketing/post-marketing-plan-plan-id-goals.md)

### POST /marketing/snapshots/search

Read a site's Google Search Console numbers for a period and save them as snapshots: search_clicks, search_impressions and search_position, plus branded_clicks and branded_impressions when brand_terms are given (searches containing any of them, the clearest sign a brand is growing). Google keeps only 16 months, so saving monthly keeps the history. Needs the workspace's Google connection with Search Console access; otherwise it answers with the status and how to connect, and saves nothing.

**Scopes:** `marketing:write`, `websites:read` — [full detail](./marketing/post-marketing-snapshots-search.md)

### POST /marketing/campaigns/:campaign_id/tracked-links

Make a TrustPager Shortlink (trustpager.link/<name>) already tagged with the campaign (utm_campaign = its tag) and recording leads, and link it to the campaign. Use one per placement (a button, a video description, a post) with utm_source, utm_medium and utm_content saying where it sits, so results show which placement worked.

**Scopes:** `marketing:write`, `shortlinks:write` — [full detail](./marketing/post-marketing-campaigns-campaign-id-tracked-links.md)

### POST /marketing/campaigns

Start a campaign in the plan: one owner, one main measure (with baseline and target), a review date when it is fair to judge, a budget and a brand. It gets a campaign tag for its tracked links (made from the name unless given; fixed once created). Judge each campaign by its own measure: search work by search clicks over months, a video series by views then calls, ads by cost per client.

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

### POST /marketing/plan

Start the workspace's Marketing Plan: name, strategy summary, period and owner. A workspace has one active plan; this refuses (409) while one is active. Then add goals with add_marketing_goal, write each brand's strategy with update_marketing_brand, save starting numbers with record_marketing_snapshot (is_baseline) and start campaigns with create_marketing_campaign.

**Scopes:** `marketing:write` — [full detail](./marketing/post-marketing-plan.md)

### DELETE /marketing/campaigns/:campaign_id

Delete a campaign with its costs, links and snapshots. Its tracked links, tasks and decisions stay, no longer tied to it. To keep the history, archive it with update_marketing_campaign (archived: true) instead.

**Scopes:** `marketing:delete` — [full detail](./marketing/delete-marketing-campaigns-campaign-id.md)

### DELETE /marketing/costs/:cost_id

Remove a logged cost.

**Scopes:** `marketing:delete` — [full detail](./marketing/delete-marketing-costs-cost-id.md)

### DELETE /marketing/goals/:goal_id

Remove a goal from the plan.

**Scopes:** `marketing:delete` — [full detail](./marketing/delete-marketing-goals-goal-id.md)

### GET /marketing/campaigns/:campaign_id

One campaign with everything on it: what it is linked to (links of kinds this connection cannot read are counted in hidden_links, not shown), costs (cash spent, committed, staff hours against budget, latest entries), its next-step tasks (next_step_missing is true when a live campaign has none open), its decisions and its latest snapshots. For what it produced use get_marketing_campaign_results.

**Scopes:** `marketing:read` — [full detail](./marketing/get-marketing-campaigns-campaign-id.md)

### GET /marketing/campaigns/:campaign_id/results

What a campaign produced over a period (default its start date to today), counted on Lead Manager's rules: leads, booked, showed, proposals, clients and revenue won, from opportunities tied to it explicitly (linked directly, through its tracked links or any link tagged with its tag, arriving with its tag (utm_campaign) on a booking or form, leads from its linked Meta or outreach campaigns, or a linked named lead source; credited_by says which: linked, tracked_link, campaign_tag, meta_ad, cold_outreach or lead_source). Nothing is guessed. Also costs (cash spent, committed, imported Meta spend, staff hours, cost per lead and per client), activity (tracked link clicks, linked email blasts and social posts with their stats), results by brand ("Unknown brand" kept apart), progress on its main measure, budget used, and notes on anything missing.

**Scopes:** `marketing:read`, `opportunities:read` — [full detail](./marketing/get-marketing-campaigns-campaign-id-results.md)

### GET /marketing/plan

The workspace's Marketing Plan in one read: the plan (strategy summary, period, owner, revision), each goal with live progress (current value, gap, percent of target, days left; a revenue_monthly goal splits recurring income from one-off income spread over months), the brands with their strategy, the campaigns (counts by status, which are due for review, owner, brand or "Unknown brand", whether each has an open next step), open decisions, saved baselines and the open next-step tasks. With no plan yet it says so. plan_id reads a closed plan instead of the active one.

**Scopes:** `marketing:read` — [full detail](./marketing/get-marketing-plan.md)

### POST /marketing/campaigns/:campaign_id/links

Tie existing work to a campaign so its results count: a tracked link, social post, email blast, cold outreach campaign, Lead Gen initiative, Meta campaign, form, booking type, lead magnet, A/B test, Training Playbooks card, named lead source, opportunity or website. The record must be in this workspace and readable by this connection. Linking the same thing twice returns the existing link.

**Scopes:** `marketing:write` — [full detail](./marketing/post-marketing-campaigns-campaign-id-links.md)

### GET /marketing/brands/:brand_kit_id/versions

A brand's strategy as it read after each change, newest first, with who changed it, how (screen, api, mcp) and why.

**Scopes:** `marketing:read` — [full detail](./marketing/get-marketing-brands-brand-kit-id-versions.md)

### GET /marketing/brands

The workspace's brands (its brand kits) with their strategy: domains, positioning, audience, offer, ticket size, the one goal action, when the strategy last changed, and how many campaigns each has. A workspace with one brand needs nothing more.

**Scopes:** `marketing:read` — [full detail](./marketing/get-marketing-brands.md)

### GET /marketing/campaigns

The plan's campaigns, newest first: brand (or "Unknown brand"), channel, hypothesis, main measure with baseline and target, dates, review date, budget, status, assessment, owner, tag and revision. Filter by status, channel, brand_kit_id ("unknown" for none) or plan_id; archived ones only with include_archived=true. with_results=true adds the results of each campaign (main measure against target, with tracked false when nothing can credit a lead to it yet, so a 0 means not tracked rather than failed; leads, clients, value won, spend against budget) and next_step_missing.

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

### GET /marketing/costs

Logged marketing costs, newest first. Filter by campaign_id, from / to (YYYY-MM-DD), kind (cash, staff_time) or status (actual, committed).

**Scopes:** `marketing:read` — [full detail](./marketing/get-marketing-costs.md)

### GET /marketing/decisions

The decisions log, newest first: question, decision, reason, status (open, decided, revisit), who decided and when, review date and evidence. Filter by status or campaign_id.

**Scopes:** `marketing:read` — [full detail](./marketing/get-marketing-decisions.md)

### GET /marketing/snapshots

Saved baselines and measurements, newest period first: metric, value, unit, the exact period, source and evidence, and whether it is a baseline, approximate or a part period. Corrected numbers are hidden unless include_replaced=true. Filter by metric, campaign_id, brand_kit_id, baselines_only, from / to.

**Scopes:** `marketing:read` — [full detail](./marketing/get-marketing-snapshots.md)

### POST /marketing/campaigns/:campaign_id/costs

Log a cost against a campaign: cash (amount) or staff time (hours, with an optional estimated value kept apart from cash), actual or committed, with a category. Meta spend of linked Meta campaigns is imported on its own, so only log ads paid elsewhere; a warning says when an ads cost may double count.

**Scopes:** `marketing:write` — [full detail](./marketing/post-marketing-campaigns-campaign-id-costs.md)

### POST /marketing/decisions

Record a marketing decision (question, decision, reason, evidence) or an open question still to decide (leave decision out). Who decided and when are recorded from this connection.

**Scopes:** `marketing:write` — [full detail](./marketing/post-marketing-decisions.md)

### POST /marketing/snapshots

Save a number with the exact period it covers, where it came from and how to check it: a baseline (is_baseline) or a later measurement, for the plan, a brand or a campaign. Mark estimates is_approximate and unfinished periods is_partial. To correct a number, pass supersedes_id: the old one is kept and marked as replaced. Recurring income billed outside this workspace (such as platform subscriptions) goes in as metric "other_recurring_monthly" so the revenue goal counts it.

**Scopes:** `marketing:write` — [full detail](./marketing/post-marketing-snapshots.md)

### DELETE /marketing/campaigns/:campaign_id/links/:link_id

Untie a record from a campaign (the link id from get_marketing_campaign). The record itself is unchanged.

**Scopes:** `marketing:write` — [full detail](./marketing/delete-marketing-campaigns-campaign-id-links-link-id.md)

### PATCH /marketing/brands/:brand_kit_id

Write or change a brand's strategy: domains, positioning, audience, offer, ticket size and goal action (and its name, shared with Studio). Every change is kept as a dated version (list_marketing_brand_versions), so old results keep the strategy they ran under.

**Scopes:** `marketing:write` — [full detail](./marketing/patch-marketing-brands-brand-kit-id.md)

### PATCH /marketing/campaigns/:campaign_id

Change a campaign: status, assessment, learnings, dates, measure, budget, brand, owner, or archive it. The tag cannot change (links already carry it). Send base_revision from your last read so you never overwrite someone else's change (409 if it moved on).

**Scopes:** `marketing:write` — [full detail](./marketing/patch-marketing-campaigns-campaign-id.md)

### PATCH /marketing/costs/:cost_id

Change a logged cost, e.g. mark a committed cost as actual once paid.

**Scopes:** `marketing:write` — [full detail](./marketing/patch-marketing-costs-cost-id.md)

### PATCH /marketing/decisions/:decision_id

Decide an open question, mark a decision to revisit, or change one. Send base_revision from your last read so you never overwrite someone else's decision (409 if it moved on).

**Scopes:** `marketing:write` — [full detail](./marketing/patch-marketing-decisions-decision-id.md)

### PATCH /marketing/goals/:goal_id

Change a goal: its target, deadline, counting rule, brand or measure. Returns it with fresh progress.

**Scopes:** `marketing:write` — [full detail](./marketing/patch-marketing-goals-goal-id.md)

### PATCH /marketing/plan/:plan_id

Change the plan's name, strategy summary, period or owner, or close it (status "closed"). Send base_revision from your last read to avoid overwriting someone else's change (409 if it moved on).

**Scopes:** `marketing:write` — [full detail](./marketing/patch-marketing-plan-plan-id.md)
