ocapi-shop Discounts API

Discount codes customers type at checkout or open as a link (`https:///d/CODE`, or any storefront page with `?discount=CODE`), and automatic discounts (`automatic: true`) that apply without a code when a cart meets their conditions: a minimum subtotal or number of units, some products or categories, buy X get Y, a date range. How they stack: a cart gets at most one automatic discount that changes prices (the one that takes the most off) plus one automatic free shipping. A code and an automatic discount don't add up: the customer gets the better of the two, unless the automatic one has `combines_with_codes`; then it applies first and the code takes its share of what's left. Free shipping combines with anything, and gift cards always pay what's left. Checkout enforces all of it, so the total charged, the order, its emails and its WhatsApp message agree.

GitHub OpenAPI

Operations 5

GET /api/v1/stores/{store_id}/discounts List discounts #
POST /api/v1/stores/{store_id}/discounts Create a discount #
GET /api/v1/stores/{store_id}/discounts/{discount_id} Get a discount #
PATCH /api/v1/stores/{store_id}/discounts/{discount_id} Update a discount #
DELETE /api/v1/stores/{store_id}/discounts/{discount_id} Delete a discount #

Work with this as data

Every API here is available over the APIs.io API and to AI agents over MCP.

MCP server

One button, every client — Claude, Cursor, VS Code and the rest.

https://apis.io/mcp

Tools for apis

7 MCP tools reach this
  • find_apisBrowse and filter every API in the catalog.
  • get_api_artifactsOne API's artifacts, grouped by type.
  • get_openapiThe primary OpenAPI for this API.
  • find_similar_apisAPIs that look like this one.
  • apis_io_searchSTART HERE — APIs, providers and tags for one query, each with its total.
  • resolveTurn a domain, URL or GitHub org into the provider it belongs to.
  • find_cohortsEvery scored population of providers in the catalog.
All 92 tools →

Call it yourself

curl for this page
This API
curl "https://apis.io/api/v1/apis/ocapi-shop:ocapi-shop-discounts-api"
All apis
curl "https://apis.io/api/v1/apis?limit=25"

Calls without X-API-Key need no key. Calls with it need a paid plan — get a key.

Get an API key

Free tier, no form to fill in. Signing in shares your email address with us — we store it to create your key and to recognise you if you sign in with another provider. By signing up you are subscribing to the APIs.io and API Evangelist newsletters — you can unsubscribe from any issue. See our Privacy Policy and Terms.

A second provider on the same verified email joins the account you already have.

OpenAPI Specification

ocapi-shop-discounts-api-openapi.yml Raw ↑
openapi: 3.2.0
info:
  title: Ocapi Discounts API
  version: '1'
  description: 'Manage Ocapi stores from your own code: the catalog, categories, orders, images, the storefront''s

    design and the store''s settings. It is the same API the Ocapi CLI, the iOS and Android apps and

    the MCP server use.


    Changes go live on the storefront as soon as a request succeeds. To prepare products before

    shoppers see them, create them with `hidden: true` and publish them later. The storefront''s

    design is the exception: changes to it go to a draft, which Publish storefront makes live.


    ## Authentication


    The API uses OAuth 2.1 with the authorization code flow and PKCE. Discovery metadata is at

    `/.well-known/oauth-authorization-server`, clients

    register themselves at `/oauth/register`, and tokens come from `/oauth/token`.


    Send the access token on every request:


    ```http

    Authorization: Bearer

    ```


    Access tokens last one hour; use the refresh token to get a new one. A token carries one or

    both scopes:


    - **`read`** allows `GET` requests.

    - **`write`** allows everything else: creating, updating, reordering and deleting.


    A request beyond the token''s scope gets `403 insufficient_scope`.


    ## Conventions


    - **IDs** are prefixed by type: `str_` stores, `prd_` products, `cat_` categories, `ord_` orders,

    `col_` collections, `pag_` pages, `lnk_` links, `dom_` domains, `usr_` users, `inv_` invitations, `whk_` webhooks.

    - **Prices** are plain numbers in the store''s currency (`currency` on the store), not cents.

    - **Timestamps** are ISO 8601 in UTC.

    - **Lists** return `{ "data": [...], "next_page": 2 }`. Pass `page` and `per_page` (up to 100,

    default 50); `next_page` is `null` on the last page.

    - **Updates** with `PATCH` change only the fields you send.


    ## Errors


    Every error has the same shape:


    ```json

    {

    "error": {

    "code": "invalid",

    "message": "Name can''t be blank",

    "details": { "name": ["can''t be blank"] }

    }

    }

    ```


    | Status | Code | Meaning |

    | --- | --- | --- |

    | 400 | `bad_request` | The body is malformed or a required parameter is missing |

    | 401 | `unauthorized` | The token is missing, invalid or expired |

    | 403 | `insufficient_scope` | The token can only read |

    | 402 | `plan_limit_reached` | The change would add more than the store''s plan allows (products, images per product or shoppable videos); `details` has `limit`, `plan`, `allowed`, `used`, `upgrade_plan` and `upgrade_url`, where the owner upgrades (both left out when no plan allows more) |

    | 404 | `not_found` | The resource doesn''t exist or belongs to a store you can''t reach |

    | 422 | `invalid` | Validation failed; `details` maps each field to its messages, with dotted keys for nested fields (`items.0.quantity`) |

    | 426 | `upgrade_required` | An Ocapi app build is too old; `details` has `min_version` and `update_url` |

    | 429 | `rate_limited` | Over 300 requests in a minute for one sign-in; retry after a minute |

    | 503 | `unavailable` | Uploads or image imports are temporarily unavailable |


    `message` is written to be shown to people as is.


    Plan limits only stop additions: a store over a limit after moving to a smaller plan keeps its

    products, images and videos, and can still edit or remove them. During the free trial a store has

    the Pro plan''s limits.'
servers:
- url: https://dashboard.ocapi.shop
security:
- bearer: []
tags:
- name: Discounts
  description: 'Discount codes customers type at checkout or open as a link (`https:///d/CODE`, or any storefront

    page with `?discount=CODE`), and automatic discounts (`automatic: true`) that apply without a code when a

    cart meets their conditions: a minimum subtotal or number of units, some products or categories, buy X get

    Y, a date range.


    How they stack: a cart gets at most one automatic discount that changes prices (the one that takes the most

    off) plus one automatic free shipping. A code and an automatic discount don''t add up: the customer gets the

    better of the two, unless the automatic one has `combines_with_codes`; then it applies first and the code

    takes its share of what''s left. Free shipping combines with anything, and gift cards always pay what''s left.

    Checkout enforces all of it, so the total charged, the order, its emails and its WhatsApp message agree.'
paths:
  /api/v1/stores/{store_id}/discounts:
    parameters:
    - $ref: '#/components/parameters/StoreId'
    get:
      operationId: listDiscounts
      tags:
      - Discounts
      summary: List discounts
      description: The store's discount codes and automatic discounts, oldest first, with how many orders used each.
      responses:
        '200':
          description: The store's discounts
          content:
            application/json:
              schema:
                type: object
                required:
                - data
                properties:
                  data:
                    type: array
                    items:
                      $ref: '#/components/schemas/Discount'
    post:
      operationId: createDiscount
      tags:
      - Discounts
      summary: Create a discount
      description: 'Creates a discount code (with `code`) or an automatic discount (`automatic: true`, with `title`). Whether a discount is automatic can''t change later.'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
              - $ref: '#/components/schemas/DiscountInput'
              required:
              - kind
              properties:
                automatic:
                  type: boolean
                  default: false
                  description: true for a discount that applies without a code; it needs a title instead
      responses:
        '201':
          description: The new discount
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Discount'
        '422':
          $ref: '#/components/responses/Invalid'
  /api/v1/stores/{store_id}/discounts/{discount_id}:
    parameters:
    - $ref: '#/components/parameters/StoreId'
    - name: discount_id
      in: path
      required: true
      schema:
        type: string
        pattern: ^dsc_[0-9a-z]{26}$
      description: The discount's ID
      example: dsc_01k70000000000000000000001
    get:
      operationId: getDiscount
      tags:
      - Discounts
      summary: Get a discount
      description: One discount code or automatic discount, with its conditions and how many orders used it.
      responses:
        '200':
          description: The discount
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Discount'
    patch:
      operationId: updateDiscount
      tags:
      - Discounts
      summary: Update a discount
      description: Changes the fields sent; pause it with `active` false. Fields set to null are cleared.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/DiscountInput'
      responses:
        '200':
          description: The updated discount
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Discount'
        '422':
          $ref: '#/components/responses/Invalid'
    delete:
      operationId: deleteDiscount
      tags:
      - Discounts
      summary: Delete a discount
      description: Deletes the discount. Orders already placed with it keep what it took off.
      responses:
        '204':
          description: The discount was deleted
components:
  schemas:
    Discount:
      type: object
      required:
      - id
      - automatic
      - code
      - title
      - kind
      - value
      - active
      - minimum_subtotal
      - minimum_quantity
      - usage_limit
      - used_count
      - buy_quantity
      - get_quantity
      - combines_with_codes
      - starts_at
      - ends_at
      - product_ids
      - category_ids
      - link
      - created_at
      - updated_at
      properties:
        id:
          type: string
          examples:
          - dsc_01k70000000000000000000001
          description: The discount's ID
        automatic:
          type: boolean
          description: Whether it applies without a code
        code:
          type:
          - string
          - 'null'
          description: What customers type; null for an automatic discount
        title:
          type:
          - string
          - 'null'
          description: An automatic discount's name
        kind:
          type: string
          description: percentage, fixed, free_shipping or buy_x_get_y (see DiscountInput); more values may be added
        value:
          type:
          - number
          - 'null'
          description: 'The percentage or amount off (in the store''s currency); for buy_x_get_y, the percent off the free units (null: free)'
        active:
          type: boolean
          description: false while paused. A live discount is also started, not ended and not used up
        minimum_subtotal:
          type:
          - number
          - 'null'
          description: 'Minimum subtotal of the eligible items; null: none'
        minimum_quantity:
          type:
          - integer
          - 'null'
          description: 'Minimum number of eligible units; null: none'
        usage_limit:
          type:
          - integer
          - 'null'
          description: 'How many orders can use it; null: no limit'
        used_count:
          type: integer
          description: Orders placed with it
        buy_quantity:
          type:
          - integer
          - 'null'
          description: 'buy_x_get_y: units to buy'
        get_quantity:
          type:
          - integer
          - 'null'
          description: 'buy_x_get_y: units that come free or discounted'
        combines_with_codes:
          type: boolean
          description: 'Automatic discounts: whether a code adds on top instead of the customer getting the better of the two'
        starts_at:
          type:
          - string
          - 'null'
          format: date-time
          description: 'When it starts applying; null: already applies'
        ends_at:
          type:
          - string
          - 'null'
          format: date-time
          description: 'When it stops applying; null: never'
        product_ids:
          type: array
          items:
            type: string
          description: 'The products it''s limited to (prd_...); empty with no category_ids: every product'
        category_ids:
          type: array
          items:
            type: string
          description: The categories it's limited to (cat_...), those inside them included
        link:
          type:
          - string
          - 'null'
          description: 'A code''s shareable link: opening it applies the code; null for an automatic discount'
        created_at:
          type: string
          format: date-time
          description: When it was created
        updated_at:
          type: string
          format: date-time
          description: When it last changed
    Error:
      type: object
      description: The body of every error response
      required:
      - error
      properties:
        error:
          type: object
          required:
          - code
          - message
          properties:
            code:
              type: string
              description: unauthorized, insufficient_scope, not_found, invalid, bad_request, rate_limited, unavailable, upgrade_required or plan_limit_reached
            message:
              type: string
              description: Readable by people and models
            details:
              type: object
              description: 'Field errors ({ field: [messages] }), min_version and update_url for upgrade_required, or for plan_limit_reached limit (products, images_per_product, videos or social_posts_per_day), plan (basic is Starter, plus is Pro), allowed, used, upgrade_plan and upgrade_url (both left out when no plan allows more)'
    DiscountInput:
      type: object
      properties:
        code:
          type: string
          pattern: ^\s*[A-Za-z0-9_\-]{2,30}\s*$
          description: What customers type, stored uppercase (VERANO20); unique in the store. Required unless automatic
        title:
          type:
          - string
          - 'null'
          maxLength: 60
          description: The name customers see for an automatic discount (Promo 2x1); required when automatic
        kind:
          type: string
          enum:
          - percentage
          - fixed
          - free_shipping
          - buy_x_get_y
          description: 'percentage: value percent off the items; fixed: value off the items, in the store''s currency; free_shipping: no shipping cost; buy_x_get_y: for every buy_quantity units the next get_quantity cheapest are free (2x1 is buy 1 get 1, 3 for the price of 2 is buy 2 get 1), or value percent off when set. More values may be added.'
        value:
          type:
          - number
          - 'null'
          exclusiveMinimum: 0
          description: 'The percentage (up to 100) or amount off; for buy_x_get_y, the percent off the free units (null: free)'
        buy_quantity:
          type:
          - integer
          - 'null'
          minimum: 1
          maximum: 100
          description: 'buy_x_get_y: units to buy'
        get_quantity:
          type:
          - integer
          - 'null'
          minimum: 1
          maximum: 100
          description: 'buy_x_get_y: units that come free or discounted'
        active:
          type: boolean
          description: false pauses the discount
        minimum_subtotal:
          type:
          - number
          - 'null'
          exclusiveMinimum: 0
          description: Minimum subtotal of the eligible items
        minimum_quantity:
          type:
          - integer
          - 'null'
          minimum: 1
          description: Minimum number of eligible units
        product_ids:
          type:
          - array
          - 'null'
          items:
            type: string
          description: Limits the discount to these products (prd_...); with category_ids, to either
        category_ids:
          type:
          - array
          - 'null'
          items:
            type: string
          description: Limits the discount to these categories (cat_...) and those inside them
        usage_limit:
          type:
          - integer
          - 'null'
          minimum: 1
          description: How many orders can use it
        starts_at:
          type:
          - string
          - 'null'
          format: date-time
          description: 'When it starts applying; null: now'
        ends_at:
          type:
          - string
          - 'null'
          format: date-time
          description: 'When it stops applying; null: never'
        combines_with_codes:
          type: boolean
          description: 'Automatic discounts: true adds a code on top; false (default) gives the customer the better of the two'
  responses:
    Invalid:
      description: Validation failed; details lists the problems by field
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  parameters:
    StoreId:
      name: store_id
      in: path
      required: true
      schema:
        type: string
        pattern: ^str_[0-9a-z]{26}$
      description: The store's ID, from List stores
      example: str_01k70000000000000000000001
  securitySchemes:
    bearer:
      type: http
      scheme: bearer
      description: An OAuth access token. See Authentication above for how to get one.