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

**Resource:** [LEAD_MAGNETS](./lead-magnets.md)  
**MCP tool:** `save_lead_magnet_gift_script_code`  
**Scopes:** `lead_magnets:write`, `automations:write`  
**Write operation:** yes

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.

## Parameters

| Name | In | Type | Required | Description |
|------|----|------|----------|-------------|
| `lead_magnet_id` | path | string | yes | The lead magnet whose Made for you gift the script makes. |
| `code` | body | string | yes | The full script source, saved exactly as given. It must export async function runScript(ctx, tools). |
| `description` | body | string | no | Optional plain-English description to keep with the code. |
| `require_approval` | body | boolean | no | Optional. Set true to route this write into the approval queue for human review instead of executing it immediately (returns 202 + an approval_id). Works even when your key/token has permission to execute directly. |

## Request example

```bash
curl -X PATCH   "https://api.trustpager.com/functions/v1/api/v1/lead-magnets/:lead_magnet_id/gift-script/code"   -H "Authorization: Bearer YOUR_API_KEY"   -H "Content-Type: application/json"   -d '{"code":"...","description":"...","require_approval":"..."}'
```

---
Base URL: `https://api.trustpager.com/functions/v1/api/v1` — Auth: `Authorization: Bearer YOUR_API_KEY`