{
  "openapi": "3.1.1",
  "info": {"title": "Cast Motive Product API integration contract", "version": "1.0.0", "description": "Schema for a website-owned product read operation. The /products path identifies the operation in this schema. Use the actual HTTPS host and route supplied by the website owner. This schema describes a third-party integration contract."},
  "security": [{"readOnlyToken": []}, {}],
  "paths": {
    "/products": {
      "get": {
        "operationId": "readProducts",
        "summary": "List products or refresh requested products using the same endpoint",
        "description": "Catalog pagination starts at page 1 and counts products. Use ids for a parent or standalone product and variant_ids for an exact variant. 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.",
        "parameters": [
          {"name": "page", "in": "query", "description": "Catalog page number, starting at 1.", "schema": {"type": "integer", "minimum": 1}},
          {"name": "per_page", "in": "query", "description": "Number of parent products per catalog page. For exact lookup use the count of requested IDs.", "schema": {"type": "integer", "minimum": 1, "maximum": 100}},
          {"name": "ids", "in": "query", "description": "Comma-separated parent or standalone product IDs from resource[].id. A matching parent can include its published variants. Use only one lookup filter.", "style": "form", "explode": false, "schema": {"type": "array", "minItems": 1, "maxItems": 100, "uniqueItems": true, "items": {"type": "string", "minLength": 1, "maxLength": 200, "pattern": "^[^,]+$"}}},
          {"name": "variant_ids", "in": "query", "description": "Comma-separated variant IDs from variants[].id. Return only the requested variants under their matching parents. Use only one lookup filter.", "style": "form", "explode": false, "schema": {"type": "array", "minItems": 1, "maxItems": 100, "uniqueItems": true, "items": {"type": "string", "minLength": 1, "maxLength": 200, "pattern": "^[^,]+$"}}}
        ],
        "responses": {
          "200": {"description": "Product collection. An empty collection does not confirm stock.", "headers": {"Cache-Control": {"description": "Required for ids and variant_ids lookups, which must query current provider data.", "schema": {"type": "string", "const": "no-store"}}}, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ResourceProductPage"}, "examples": {"simpleProduct": {"value": {"resource": [{"id": 10345, "name": "Wireless Headphones", "url": "https://your-website.example/products/10345", "description": "Wireless headphones with a foldable design.", "image": {"url": "https://your-website.example/media/10345.jpg"}, "current_stock": 12, "price": "24.90", "currency": "USD", "variants": []}], "meta": {"current_page": 1, "last_page": 1, "per_page": 1}}, "summary": "Simple product with an empty variants array"}, "productWithVariants": {"value": {"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}}, "summary": "Catalog response or exact lookup for page=1, per_page=1 and ids=product:48"}, "exactVariantLookup": {"summary": "Response for page=1, per_page=1 and variant_ids=variant:481", "value": {"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"}]}], "meta": {"current_page": 1, "last_page": 1, "per_page": 1}}}}}}},
          "400": {"$ref": "#/components/responses/BadRequest"},
          "401": {"description": "Missing or invalid read-only credential", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}},
          "403": {"description": "Read access denied", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}},
          "404": {"description": "Endpoint not found; an individual missing ID is normally omitted from a 200 collection", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}},
          "429": {"description": "Rate limited. Retry the same page after Retry-After.", "headers": {"Retry-After": {"description": "Delay in seconds or HTTP date", "schema": {"type": "string"}}}, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}},
          "default": {"description": "Provider failure; never treat as fresh stock or successful import", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}}
        }
      }
    }
  },
  "components": {
    "securitySchemes": {"readOnlyToken": {"type": "http", "scheme": "bearer", "description": "Private providers require a product-read-only token. Never use customer/order/write/admin permission."}},
    "responses": {"BadRequest": {"description": "Invalid ids, variant_ids, page or per_page", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}}},
    "schemas": {
      "ResourceProductPage": {
        "type": "object",
        "required": ["resource", "meta"],
        "description": "A standard response supports at most 1,000 sellable items across its parent rows.",
        "properties": {
          "resource": {"type": "array", "maxItems": 100, "items": {"$ref": "#/components/schemas/ResourceProduct"}},
          "meta": {
            "type": "object",
            "required": ["current_page", "last_page", "per_page"],
            "properties": {
              "current_page": {"type": "integer", "minimum": 1},
              "last_page": {"type": "integer", "minimum": 1, "maximum": 999999999},
              "per_page": {"type": "integer", "minimum": 1, "maximum": 100}
            }
          }
        }
      },
      "ProviderImageUrl": {"type": "string", "maxLength": 4096, "pattern": "^[Hh][Tt][Tt][Pp][Ss]?://[^/?#\\u0000-\\u0020\\u007f]+(?:[/?][^#\\u0000-\\u001f\\u007f]*)?(?:#[^\\u0000-\\u0020\\u007f]*)?(?![\\s\\S])", "description": "Absolute public HTTP(S) image URL. Literal spaces in its path or query are encoded as %20 before standard URL validation. Send the encoded URL if available."},
      "ProviderImages": {"type": "array", "maxItems": 50, "uniqueItems": true, "items": {"$ref": "#/components/schemas/ProviderImageUrl"}, "description": "Original public image URLs. The URLs must be distinct after space encoding. An empty list is incomplete for preparation or publication."},
      "ResourceProduct": {
        "type": "object",
        "required": ["id"],
        "anyOf": [{"required": ["title"]}, {"required": ["name"]}],
        "if": {"required": ["variants"], "properties": {"variants": {"contains": {"required": ["price"], "properties": {"price": {"type": "string"}}}}}},
        "then": {"required": ["currency"]},
        "description": "Use one resource row per parent product. Set shared currency here when a variant has a price. For catalog and ids lookup, a simple product can omit variants or send variants: []. Use its own price and stock. Include a public URL and original images. The existing Shope route also accepts url_slug or id.",
        "properties": {
          "id": {"oneOf": [{"type": "string", "minLength": 1, "maxLength": 200, "pattern": "^[^,]+$"}, {"type": "integer", "minimum": 1}]},
          "name": {"type": "string", "minLength": 1, "maxLength": 1000},
          "title": {"type": "string", "minLength": 1, "maxLength": 1000},
          "url": {"type": "string", "format": "uri", "pattern": "^https?://"},
          "url_slug": {"type": "string"},
          "image": {"type": ["object", "null"], "properties": {"url": {"$ref": "#/components/schemas/ProviderImageUrl"}}},
          "category": {"oneOf": [{"type": "string"}, {"type": "object", "properties": {"name": {"type": "string"}}}]},
          "status": {"type": "boolean", "description": "Publication eligibility. False excludes the item from import. The supported Shope route may omit parent status when enforcing its published and approved status=true filter."},
          "availability": {"type": "string", "enum": ["in_stock", "out_of_stock", "unknown"], "description": "Stock availability. A published product can be out of stock."},
          "current_stock": {"type": ["integer", "null"], "minimum": 0, "maximum": 9007199254740991, "description": "Authoritative count of sellable units when provided. The importer derives stock quantity and availability."},
          "description": {"$ref": "#/components/schemas/Product/properties/description"},
          "images": {"$ref": "#/components/schemas/ProviderImages"},
          "price": {"$ref": "#/components/schemas/Product/properties/price"},
          "currency": {"$ref": "#/components/schemas/Product/properties/currency"},
          "stock_quantity": {"$ref": "#/components/schemas/Product/properties/stock_quantity"},
          "variants": {"type": "array", "maxItems": 100, "description": "Omit or return an empty array for a simple product in catalog and ids lookups. For variant_ids, each matching parent contains only the requested variants.", "items": {"$ref": "#/components/schemas/ResourceVariant"}}
        }
      },
      "ResourceVariant": {
        "type": "object",
        "required": [
          "id",
          "price",
          "current_stock"
        ],
        "description": "One sellable variant. Label and options are optional. Cast Motive uses the parent title when neither is supplied. Set currency on the parent product. 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 public URL and images can override those on the parent.",
        "properties": {
          "id": {
            "$ref": "#/components/schemas/ResourceProduct/properties/id"
          },
          "label": {
            "type": "string",
            "minLength": 1,
            "maxLength": 500,
            "pattern": "\\S"
          },
          "options": {
            "type": "object",
            "maxProperties": 10,
            "propertyNames": {
              "minLength": 1,
              "maxLength": 100,
              "pattern": "\\S"
            },
            "additionalProperties": {
              "type": "string",
              "minLength": 1,
              "maxLength": 100,
              "pattern": "\\S"
            }
          },
          "price": {
            "$ref": "#/components/schemas/Product/properties/price"
          },
          "current_stock": {
            "$ref": "#/components/schemas/ResourceProduct/properties/current_stock"
          },
          "url": {
            "$ref": "#/components/schemas/ResourceProduct/properties/url"
          },
          "images": {
            "$ref": "#/components/schemas/ProviderImages"
          },
          "status": {
            "$ref": "#/components/schemas/ResourceProduct/properties/status"
          }
        },
        "not": {
          "anyOf": [
            {
              "required": [
                "currency"
              ]
            },
            {
              "required": [
                "variants"
              ]
            }
          ]
        }
      },
      "Product": {
        "type": "object",
        "required": ["id", "title", "url", "description", "images", "availability"],
        "dependentRequired": {"price": ["currency"]},
        "properties": {
          "id": {"type": "string", "minLength": 1, "maxLength": 200, "pattern": "^[^,]+$", "description": "Stable ID unique across sellable products and variants in the same catalog. Use each variant ID for exact variant lookup."},
          "title": {"type": "string", "minLength": 1, "maxLength": 1000},
          "url": {"type": "string", "format": "uri", "pattern": "^https?://", "maxLength": 4096},
          "description": {"type": "string", "maxLength": 100000, "description": "Empty allowed for incomplete import; do not fabricate. Sanitize HTML before use."},
          "images": {"type": "array", "maxItems": 50, "uniqueItems": true, "items": {"type": "string", "format": "uri", "pattern": "^https?://", "maxLength": 4096}, "description": "Original public image URLs. Empty is incomplete and cannot qualify preparation/publication."},
          "availability": {"type": "string", "enum": ["in_stock", "out_of_stock", "unknown"]},
          "price": {"type": ["string", "null"], "pattern": "^[0-9]+(?:\\.[0-9]+)?$", "maxLength": 40, "description": "Optional decimal amount. Null/absent is unknown, never free."},
          "currency": {"type": "string", "pattern": "^[A-Z]{3}$"},
          "stock_quantity": {"type": ["integer", "null"], "minimum": 0, "description": "Optional catalog fallback for current_stock. Exact ID lookups use fresh current_stock."},
          "category": {"type": "string", "maxLength": 500},
          "updated_at": {"type": "string", "format": "date-time", "description": "Optional; not a substitute for a fresh stock check."}
        }
      },
      "Error": {"type": "object", "required": ["error"], "properties": {"error": {"type": "object", "required": ["code", "message"], "properties": {"code": {"type": "string"}, "message": {"type": "string"}}}}}
    }
  }
}
