# Natural Catch landing page API

Base URL: `https://offer-api.naturalcatchtuna.com`
Auth: every call except this page needs `Authorization: Bearer <your key>`.

You edit the ad landing pages on https://offer.naturalcatchtuna.com. You can only touch page
content: `pages/`, `blocks/`, `content/` and `img/`. Code, tracking and the Shopify store are out
of reach on purpose.

## How it works

1. Your edits go to your own workspace (a draft copy). The live site does not change yet.
2. After each edit, a preview builds in about a minute. `GET /v1/status` gives its link.
   The preview shows drafts too.
3. `POST /v1/publish` sends the workspace for checks. If every check passes, it goes live in
   2-3 minutes. If one fails, `GET /v1/status` links the publish PR, which shows the error. Fix it
   with more edits and the checks run again.
4. A page is live only when its `status: live`. Use `status: draft` while working. To take a page
   down, set `status: archived`: old ad links then redirect to the store instead of 404.

## Endpoints

| Call | What |
|---|---|
| `GET /v1/whoami` | Your name, workspace branch, preview link |
| `GET /v1/files` (`?kind=pages`) | List files (your workspace, or live if you have no edits) |
| `GET /v1/files/<kind>/<path>` | Read one file (YAML text) |
| `PUT /v1/files/<kind>/<path>` | Write one YAML file. Body = the YAML text. `?message=` optional |
| `POST /v1/changes` | Write several files in one change (preferred) |
| `GET /v1/products` | Every product, SKU, price, stock flag. Use real SKUs only |
| `GET /v1/status` | Unpublished changes, preview link and state, publish PR |
| `POST /v1/publish` | Send the workspace live (after checks) |
| `POST /v1/reset` | Throw away unpublished edits |

`kind` is `pages`, `blocks`, `content` or `img`. Paths are lowercase words joined by hyphens:
`pages/protein-lunch.yaml`, `content/faq/salmon.yaml`, `img/hero/protein-bowl.webp`.

```bash
KEY=...   # from 1Password, never paste it into a page or a commit
API=https://offer-api.naturalcatchtuna.com

curl -s $API/v1/files?kind=pages -H "Authorization: Bearer $KEY"
curl -s $API/v1/files/pages/pole-and-line-yellowfin.yaml -H "Authorization: Bearer $KEY"

curl -s -X POST $API/v1/changes -H "Authorization: Bearer $KEY" -H "Content-Type: application/json" \
  -d '{"message":"protein page v1","files":[{"kind":"pages","path":"protein-lunch.yaml","content":"slug: protein-lunch\nstatus: draft\n..."}]}'

# image: base64 in JSON, under 1.5 MB (aim under 300 KB, webp preferred)
curl -s -X POST $API/v1/changes -H "Authorization: Bearer $KEY" -H "Content-Type: application/json" \
  -d "{\"files\":[{\"kind\":\"img\",\"path\":\"hero/protein-bowl.webp\",\"content_base64\":\"$(base64 -i bowl.webp)\"}]}"

curl -s $API/v1/status -H "Authorization: Bearer $KEY"
curl -s -X POST $API/v1/publish -H "Authorization: Bearer $KEY" -d '{"message":"launch protein page"}'
```

Errors come back as `{"error": "..."}` with a 4xx status. Read the message; it says what to fix.

## Where to get facts, photos and data (do not guess)

Use these sources. They are public JSON, no key needed. If a fact is not in them, ask Ross
instead of making it up.

| Need | Source |
|---|---|
| SKUs, prices, stock | `GET /v1/products` (this API, live from Shopify) |
| Product facts: nutrition per serving, ingredients, allergens, catch method, fishing origin, omega-3 (EPA+DHA mg), net weight, certifications, badges, UPC | https://brand.naturalcatch.com/api/catalog.json (`products[]`, one per flavor; `key` like `yellowfin_evoo`, `shopify_handle` links it to the store) |
| Photos, lifestyle shots, logos, box flats, videos | https://brand.naturalcatch.com/api/assets (filter: `?kind=lifestyle`, `?kind=product_photo`, `?kind=logo`, `?tag=coho_teriyaki`). Each item has `blob_url`, `alt_text`, `tags`, `bytes` |
| Lab tests and certificates (mercury results, dates) | https://brand.naturalcatch.com/api/certifications.json |
| Browse everything by eye | https://brand.naturalcatch.com |

Flavor tags used in the asset library: `yellowfin_evoo`, `spicy_yellowfin`, `white_albacore_evoo`,
`white_albacore_water`, `sardines_evoo`, `mackerel_evoo`, `coho_lemon`, `coho_spicy`,
`coho_teriyaki`, `sweet_bean`, `fiesta_salad`.

**Images on a page:**
- Product pack shot: `image: product:12tuna` (Shopify, already sized).
- Brand Hub photo: Brand Hub originals are often 3-6 MB. Do not link them straight into a page.
  Download the `blob_url`, resize to at most 1600 px wide as WebP under 300 KB, upload it with
  `POST /v1/changes` (`kind: img`), then use `img/<path>` in the page. Keep the `alt_text`.
- Every claim on a page (nutrition, omega, "pole & line", mercury) must match `catalog.json` or
  `certifications.json`. If they disagree with your copy, the catalog wins.

## A page file

Start from an existing page (`GET /v1/files/pages/pole-and-line-yellowfin.yaml`). The shape:

```yaml
slug: protein-lunch            # must equal the file name
status: draft                  # draft | live | archived
template: advertorial          # advertorial | listicle | offer | compare (label only)
owner: ross
angle: protein                 # for reporting
advertorial: true              # adds the "Advertisement" label; use on story-style pages
title: "Browser tab title, under 70 characters"
description: "One sentence for link previews"
featured_sku: 12tuna           # tracked as the product viewed
header_cta: { label: Shop, sku: 12tuna }

variants:                      # copy versions, each its own URL: /protein-lunch/ and /protein-lunch/gym/
  default: { headline: "...", sub: "..." }
  gym:     { headline: "..." } # missing values fall back to default
rules:                         # pick a version from the ad: Meta utm_content={{ad.name}}
  - { param: utm_content, contains: gym, variant: gym }

sections:
  - type: hero
    headline: $headline        # "$name" reads from the active variant
    sub: $sub
    image: product:12tuna      # Shopify image, or img/<file>
    cta: { label: "Shop 12-Packs", sku: 12tuna }
  - use: why-pole-and-line     # shared block
  - use: offer-packs
    with: { items: { ref: offers/yellowfin-packs#items } }
  - use: faq-tuna-basics
```

**Section types:** `hero` (eyebrow, headline, sub, badges, image, cta, note), `text`
(heading, body), `image` (src, alt, caption), `bullets` (heading, items: title/text/image),
`listicle` (heading, items, cta), `compare` (heading, columns, rows, footnote), `reviews`
(heading, items: quote/name/stars), `offer` (heading, sub, discount, items: sku/badge/note/label),
`faq` (items: q/a), `cta` (headline, sub, button), `video` (src, poster).

**Buttons:** `{ label, sku, mode: pdp | checkout, discount: CODE, qty }`. `pdp` (default) opens
the product page with that pack picked. A discount code must exist and be active in Shopify or
publish fails.

**Text:** `**bold**`, `*italic*`, `[link](https://naturalcatchtuna.com/...)`. Live prices:
`{price:12tuna}`, `{per_can:12tuna}`, `{compare:12tuna}`.

**Shared library:** `blocks/<name>.yaml` is a reusable section (`- use: name`, change fields
with `with:`). `content/<path>.yaml` is reusable data (`{ ref: path#key }`). Editing a shared
file changes every page that uses it, so check which pages use it first (search the pages for
`use: <name>` or `ref: <path>`).

## Copy rules (publish fails or the page is wrong otherwise)

- No `TODO` text on a live page.
- Reviews are real and word for word. Never invent one.
- Claims must match the box: nutrition, "pole & line caught", omega numbers. Do not invent
  health claims or comparisons you cannot prove.
- Spelling and wording: "filets" (one l). Coho salmon is "sustainable", not "wild".
  Teriyaki is "light", never "rich".
- Not allowed through this API: `type: html` sections, `<script>` or other markup in copy, links
  off naturalcatchtuna.com. Tracking is automatic; do not add pixels or tags.
