# LEAD_MAGNETS

lead-magnets endpoints.

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

## Endpoints

### POST /lead-magnets/:lead_magnet_id/gift-script/approve-code

Approve the gift script's current code so it makes real gifts (publishes it as part of approving). Admin only. Until approved, readers of a custom_script gift see nothing made for them and cold campaigns using this lead magnet cannot start.

**Scopes:** `admin` — [full detail](./lead-magnets/post-lead-magnets-lead-magnet-id-gift-script-approve-code.md)

### POST /lead-magnets

Create a lead magnet: a private page each person gets after signing up, with their own link emailed to them. Starts as a draft with a headline and a Downloadable files block. Set config to build the page (blocks and design), form_template_id to hand it out to everyone who completes a public form, then status live. The response carries page_guide: every block type, its fields, and the fonts.

**Scopes:** `lead_magnets:write` — [full detail](./lead-magnets/post-lead-magnets.md)

### DELETE /lead-magnets/:lead_magnet_id

Delete a lead magnet and every pass to it: everyone's link stops working and the open history is lost. Destructive. To stop handing it out but keep the history, set status to archived instead.

**Scopes:** `lead_magnets:delete` — [full detail](./lead-magnets/delete-lead-magnets-lead-magnet-id.md)

### DELETE /lead-magnets/:lead_magnet_id/gift-script/secrets/:secret_name

Remove a third-party secret from a lead magnet's gift script.

**Scopes:** `lead_magnets:write`, `automations:write` — [full detail](./lead-magnets/delete-lead-magnets-lead-magnet-id-gift-script-secrets-secret-name.md)

### POST /lead-magnets/:lead_magnet_id/gift-script/generate

Write (or rewrite) the Custom Script that makes a lead magnet's Made for you gift, from a plain-English description of the gift. The script gets the reader (first_name, business_name, industry, city, state, postcode, website, why_now) and returns { title, text, html, url, image_url }. New code needs approval (approve_lead_magnet_gift_script) before it makes real gifts; try it first with test_lead_magnet_gift_script.

**Scopes:** `lead_magnets:write`, `automations:write` — [full detail](./lead-magnets/post-lead-magnets-lead-magnet-id-gift-script-generate.md)

### GET /lead-magnets/:lead_magnet_id

Get one lead magnet: its page (config: hero, blocks and theme), the linked form, email, link security, how many people have a pass and how many opened it, gift (when the page has a Made for you block: the Gift it gives with what it makes and its price, use_quiz_score, how many readers' gifts are waiting for their answers, ready, being made or failed, and for a script gift whether the script can run), and page_guide: every block type, its fields, how gifts and quizzes work, and the fonts.

**Scopes:** `lead_magnets:read` — [full detail](./lead-magnets/get-lead-magnets-lead-magnet-id.md)

### GET /lead-magnets/:lead_magnet_id/gift-script

Get the Custom Script that makes a lead magnet's Made for you gift (when its gift maker is custom_script): id, description, code, approval and publish state (live_ready, live_block_reason), secret names, last test result. 404 until the script is first written.

**Scopes:** `lead_magnets:read` — [full detail](./lead-magnets/get-lead-magnets-lead-magnet-id-gift-script.md)

### GET /lead-magnets/:lead_magnet_id/install

How to show the page of a lead magnet on the business website. Recommended: custom_design, where the website draws the page of each reader in its own design from data TrustPager hands it (custom_design.guide has every state, field and block; sites made from a TrustPager design have it built in at /guide). The quick way, also returned, frames the page in its own header and footer: the HTML code to paste (snippet_html), the steps for whoever looks after the website, and whether page_url is set. After the code is on a page, set page_url to the address of that page with update_lead_magnet so emailed links open it.

**Scopes:** `lead_magnets:read` — [full detail](./lead-magnets/get-lead-magnets-lead-magnet-id-install.md)

### GET /lead-magnets/:lead_magnet_id/access

List who has a pass to a lead magnet: the contact (or, for a cold email campaign lead who is not in the CRM, cold_lead and the reader snapshot: name, business, trade, area, website, why now), how they got it (form, automation, api, blast, manual, cold_campaign), their free gift when the page has a Made for you block (gift: status waiting|queued|researching|making|ready|failed, their answers to the gift's questions, error, credits_charged, and items: each thing made with its kind pdf|plan|image|video|audit|website|script, status and content; get_gift_run gives the PDF link), their answers on the page ({block id: option id for Pick one, option ids for Tick all that apply}) and answered_at, when it was sent, first and last opened, how many times, whether the link is turned off or expired, and pin_locked_at when it locked after 30 wrong PINs (locked for good: send_lead_magnet again makes a new link and PIN). opened=true or false filters by whether they opened it.

**Scopes:** `lead_magnets:read` — [full detail](./lead-magnets/get-lead-magnets-lead-magnet-id-access.md)

### GET /lead-magnets

List the lead magnets in this workspace: private pages each sign-up gets (downloadable files plus optional text, images, video, slides, booking, an offer and questions). Filter by status (draft, live, archived).

**Scopes:** `lead_magnets:read` — [full detail](./lead-magnets/get-lead-magnets.md)

### POST /lead-magnets/:lead_magnet_id/gift-preview

Make one free gift from the lead magnet's Made for you block (its Gift) for a sample business, to see what readers will get: each thing the gift makes (items: the PDF as a link kept for a day, the plan, the website design picture). A gift with research, a made picture, a badge, a video, an audit or a rebuilt website is made in the background instead (queued true, gift_id, run_id: follow it with get_gift_run). Charged like a real gift (get_lead_magnet shows gift.price_credits); nothing is saved on a reader. A gift made by a script is tried with test_gift_script instead. preview_gift does the same from the gift itself.

**Scopes:** `lead_magnets:write` — [full detail](./lead-magnets/post-lead-magnets-lead-magnet-id-gift-preview.md)

### DELETE /lead-magnets/:lead_magnet_id/access/:access_id

Turn off one person's link to a lead magnet. Their open history is kept. Sending the lead magnet to them again gives them a new working link.

**Scopes:** `lead_magnets:write` — [full detail](./lead-magnets/delete-lead-magnets-lead-magnet-id-access-access-id.md)

### PATCH /lead-magnets/:lead_magnet_id/gift-script/code

Save hand-written code for a lead magnet's gift script, exactly as given (it must export async function runScript(ctx, tools) and return { title, text, html, url, image_url }). Saved code needs approval again before it makes real gifts.

**Scopes:** `lead_magnets:write`, `automations:write` — [full detail](./lead-magnets/patch-lead-magnets-lead-magnet-id-gift-script-code.md)

### POST /lead-magnets/:lead_magnet_id/access

Give a contact their pass to a lead magnet and email them their private link (and PIN, when link security is on). Each contact has one pass per lead magnet: sending again emails a fresh link and the old one stops working, unless it was sent in the last 10 minutes. send=false returns the link (url), and the PIN when link security is on, instead of emailing them; they are shown only once. Works on draft lead magnets too, for testing.

**Scopes:** `lead_magnets:write` — [full detail](./lead-magnets/post-lead-magnets-lead-magnet-id-access.md)

### PUT /lead-magnets/:lead_magnet_id/gift-script/secrets/:secret_name

Add or replace a third-party secret the gift script needs (write-only, the value is never returned). The script reads it as secrets.NAME.

**Scopes:** `lead_magnets:write`, `automations:write` — [full detail](./lead-magnets/put-lead-magnets-lead-magnet-id-gift-script-secrets-secret-name.md)

### POST /lead-magnets/:lead_magnet_id/gift-script/test

Try the gift script on a sample reader (or one you describe) without approving it. Runs in the background: read the outcome with get_lead_magnet_gift_script (last_test_status, last_test_result) a few seconds later. Charged like one Custom Script run.

**Scopes:** `lead_magnets:write`, `automations-trigger:trigger` — [full detail](./lead-magnets/post-lead-magnets-lead-magnet-id-gift-script-test.md)

### PATCH /lead-magnets/:lead_magnet_id

Update a lead magnet. Pass only what changes. config.hero and config.theme merge field by field; config.blocks replaces the whole list, so send every block in page order (keep the id of each existing block). Example: {"config": {"theme": {"heading_font": "cormorant", "background": "#f3efe8"}, "blocks": [{"id": "files1", "type": "files", "heading": "Your guide", "files": [{"file_id": "...", "label": "The guide"}]}, {"type": "faq", "heading": "FAQ", "items": [{"q": "...", "a": "..."}]}]}}. Changes show straight away to everyone who opens their link. status live hands it out from the linked form and automations; archived turns off every link.

**Scopes:** `lead_magnets:write` — [full detail](./lead-magnets/patch-lead-magnets-lead-magnet-id.md)
