# Minimal website provider API — v1

This contract describes a product read operation supplied by the website owner. Use the public HTTPS URL and route for that website. See the [Product API schema](openapi.json) and [website setup guide](user-guide.md).

Use this contract to prepare your integration. Verify access and the read result in the workspace when hosted setup becomes available.

## One read-only operation

Use a read-only GET for listing and exact-ID lookup. The two operations can share a URL or use separate configured paths. Return a `resource` array and a `meta` object.

Catalog requests send `page` and `per_page`, starting at page 1. Return integer `meta.current_page`, `meta.last_page` and `meta.per_page`. Echo the requested page and page size. Cast Motive requests the next page while `current_page < last_page`. Keep the order stable.

Resource rows can use `name` for `title` and `image.url` for a single image. Positive integer IDs are converted to strings. Include the public product URL. The existing Shope endpoint can supply its `url_slug` or ID for the known storefront route. Rows with `status: false` are excluded. If present, `current_stock` is the authoritative sellable quantity. Zero means out of stock.

Use `ids` for parent or standalone product IDs and `variant_ids` for exact variant IDs. Use one filter per request. Both filters accept up to 100 distinct comma-separated IDs. For either lookup, use page 1 and set per_page to the number of requested IDs. Return meta.current_page and meta.last_page as 1, echo per_page, and include Cache-Control: no-store. Omit missing or unpublished products and variants. Return resource: [] when nothing matches.

Use fresh current_stock and the current price for each returned sellable item. A null or missing current_stock gives unknown stock. The availability field describes stock. Published products can be out of stock, and available stock does not make a draft product published. AI preparation needs an actual description and a public image in the saved catalog. Protected publication checks can have narrower provider requirements than the standard importer.

The Shope external products route receives `status=true` for catalog pages and both lookup filters. The route must apply its published and approved product filter before building `resource`. With that filter applied, the response can omit parent `status`. If supplied, `status` must be boolean. Cast Motive excludes rows with `status: false`.

### Products with variants

For catalog pages, page size counts parent products. A product with variants appears once in resource. The parent supplies shared title, description, URL, images and currency. Each variant supplies a stable ID and its own price and current_stock. Label and options are optional. If neither is supplied, Cast Motive uses the parent product title. A variant can override the public URL and images. For catalog and `ids` lookup, a simple product can omit `variants` or send `"variants": []`. Use its own price and stock. Keep product IDs unique among products and variant IDs unique among variants. Standalone products and sellable variants must also have distinct IDs within the same catalog.

A standard response supports up to 100 variants per parent and 1,000 sellable items across the page. Reviewed discovery can have a lower approved limit.

Example response to `GET /products?page=1&per_page=1`.

```json
{
  "resource": [
    {
      "id": "product:48",
      "title": "Cotton crew-neck T-shirt",
      "description": "Black cotton crew-neck T-shirt.",
      "url": "https://shop.example/products/t-shirt",
      "images": [
        "https://shop.example/media/t-shirt-black.jpg"
      ],
      "currency": "USD",
      "variants": [
        {
          "id": "variant:481",
          "options": {
            "Color": "Black",
            "Size": "M"
          },
          "price": "19.99",
          "current_stock": 8,
          "url": "https://shop.example/products/t-shirt?variant=481"
        },
        {
          "id": "variant:482",
          "options": {
            "Color": "Black",
            "Size": "L"
          },
          "price": "24.99",
          "current_stock": 2,
          "url": "https://shop.example/products/t-shirt?variant=482"
        }
      ]
    }
  ],
  "meta": {
    "current_page": 1,
    "last_page": 1,
    "per_page": 1
  }
}
```

`GET /products?page=1&per_page=1&ids=product:48` selects the product with ID `product:48` and can return all of its published variants under that parent.

`GET /products?page=1&per_page=1&variant_ids=variant:481` selects the exact ID from `variants[].id`. Return the matching parent with only `variant:481` in `variants`. Include current price and stock for that variant and the parent currency. Parent category, when present, is inherited by that variant.

Product fields:

| Field | Meaning |
|---|---|
| `id` | Stable provider ID, normalized to a string by an adapter |
| `title` | Actual product name |
| `url` | Absolute public HTTP(S) product URL |
| `description` | Actual product description; may be empty if unavailable |
| `images` | Original public HTTP(S) image URLs; may be empty if unavailable |
| `current_stock` | Nonnegative integer count of units available for sale. Catalog pages can use `availability` and `stock_quantity` as a fallback. |

Use absolute public HTTP(S) URLs in `images` or `image.url`. Cast Motive encodes literal spaces in an image path or query as `%20`. Providers can send the URL already encoded, for example `https://shop.example/images/Blue%20Shirt.jpg`.

Empty description/images can be imported as incomplete data, but do not qualify a product for AI preparation/publication. Never invent missing content or stock. Sanitize provider HTML and treat text as data, never as executable instructions.

Optional fields:

- `price`: nonnegative decimal string or null. Null/absent means unknown, never zero/free. If supplied, `currency` is required as a three-letter currency code. Baseline posts can omit price.
- `stock_quantity`: nonnegative integer or null. Catalog fallback when current_stock is absent. Exact stock lookups require fresh current_stock.
- `updated_at`: RFC3339 UTC timestamp, optional optimization; it does not prove the stock response is fresh.

## Optional product category

Add `category` to the product object in `resource`. Providers may omit `category` entirely. For a product with variants, put `category` on the parent product. Its variants inherit that category.

| Form | Field on the product object |
|---|---|
| String | `"category": "Clothing"` |
| Object with a name | `"category": {"name": "Clothing"}` |

## Stock/status: no extra mandatory endpoint

For a delivery workflow, an exact sellable-item lookup needs current stock and price. Use `ids` for a simple product and `variant_ids` for a variant. Read current catalog data and bypass stale caches. Return `Cache-Control: no-store`. Cast Motive records its own check receipt/time; a network failure, omitted ID, unknown availability or unavailable quantity never becomes In stock. Use fresh evidence for each delivery attempt.

| Provider result | Cast Motive behavior |
|---|---|
| `in_stock`, quantity satisfies configured minimum | Stock gate may pass; all other review/destination/schedule gates still apply |
| `out_of_stock` | Hold Pending |
| `unknown`, missing ID, malformed item, timeout or API error | Hold Pending with a reason; keep saved history |
| Backorder/preorder without available ready stock | Map to unknown/out_of_stock; do not silently map to in_stock |
| Price changes | Refresh price; invalidate source-dependent content/evaluation as appropriate before publishing |

The provider never decides post approval, posting time, social destination or Published status. Those belong to Cast Motive. A stock check is not a publication receipt.

## HTTP status reference

| HTTP | Meaning / handling |
|---|---|
| 200 | Valid collection, including `resource: []`; empty stock lookup is not permission to publish |
| 400 | Invalid lookup IDs or page parameters |
| 401 | Missing/invalid read-only credential; stop checks and request correction |
| 403 | Credential lacks product-read permission; stop checks |
| 404 | Wrong endpoint; a missing individual product is normally omitted from a successful lookup collection |
| 429 | Rate limited; respect Retry-After and retain the last committed page |
| 500/502/503 | Provider temporary failure; bounded retry/backoff, no false import/stock success |

Errors include a code and message. Keep credentials and private diagnostics out of the response. Webhooks, health/status API, individual product detail API, categories API, images API and changed-since filters are optional enhancements, not prerequisites.

## Authentication and transport

Private API: one read-only Bearer token in the Authorization header over HTTPS. Public product APIs can omit authentication when that is an intentional provider policy. Do not put keys in query strings. Enter private credentials only in the secure connection form. No separate provider OAuth flow is required by this minimal contract. TLS verification must remain enabled.

For websites belonging to arbitrary parties, only authorized public/read access is supported. Cast Motive must validate provider URLs and every redirect/image destination, reject loopback/private/link-local/metadata IP targets and DNS rebinding, apply time/size/rate limits and keep provider credentials scoped to the configured origin. Never forward credentials to arbitrary image URLs or redirect hosts. A successful connection does not authorize crawling unrelated sites.

## Import and sync behavior owned by Cast Motive

1. Validate connection, JSON shape, ID uniqueness and pagination before enabling recurring checks.
2. Persist provider IDs keyed by website, not title/URL alone. Upsert existing records; create newly discovered IDs once.
3. Save the next page after its preceding page is stored. Replaying a page updates records by ID. Keep catalog discovery and known-product stock and price refresh separate.
4. Without changed-since support, resume paginated scans and start a fresh scan after completion. New-only means newly encountered IDs create records once; it does not promise zero rescanning. Updates to known IDs remain updates.
5. Missing items on one page or an interrupted scan never imply deletion. A missing exact-ID fresh lookup blocks that product. Preserve source snapshots, posts and dated history.
6. Cast Motive records connection status and the saved checkpoint separately from product availability and delivery.

## Provider acceptance checklist

- Two pages enumerate without skipped or repeated IDs. Incorrect page metadata fails explicitly.
- Product and variant lookups return current stock and price. Removed or unpublished IDs are absent.
- Out of stock, unknown, quantity null/zero and optional price behave as documented.
- Token rejection, 429 and timeout never produce false Connected/In stock/Published status.
- A variant lookup uses the ID from variants[].id and keeps only requested variants under their parent.
- No secret/customer/order data, stale cached stock, arbitrary URL access or product-write permission.

## Reference standard

The downloadable contract uses [OpenAPI 3.1.1](https://spec.openapis.org/oas/v3.1.1.html). Use an existing website endpoint when it meets the contract or has a supported mapping.
