> ## Documentation Index
> Fetch the complete documentation index at: https://developers-docs.easyorders.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Create a coupon

> **Scope:** [`write_discounts`](/scopes)

Creates a coupon. Only `method` and `discount_type` are required;
every other field takes its default. The whole coupon must then
follow the [coupon rules](/api-reference/coupons/overview#rules):
a `code` coupon needs a `code`, an `automatic` one needs a `title`
and no code, and so on.

- The code is trimmed and saved lowercased. Another live coupon of
  the store with the same code answers `409 code_taken`.
- Each applicable item must be a product, variant or category of
  this store; one that is not answers `422` on its `item_id`, with
  its type as the rule.

Send an `Idempotency-Key` to retry safely.




## OpenAPI

````yaml /openapi.json post /coupons
openapi: 3.1.0
info:
  title: EasyOrders Admin API
  version: v1
  summary: Read and write a merchant's store data from your app.
  description: |
    The EasyOrders Admin API lets an installed app work with one merchant's
    store: its orders, shipping settings and shipping areas, within the
    scopes the merchant approved.

    - Every request needs an access token (`Authorization: Bearer eo_at_...`)
      from the OAuth flow. A token works on one store only.
    - Request and response bodies are JSON. Unknown fields and query
      parameters are refused.
    - Errors share one shape: `{"error": {"code", "message", "details"}}`.
    - `v1` is stable: new fields and endpoints are added to it; a breaking
      change ships as a new version.
  contact:
    name: EasyOrders developers
    url: https://easyorders.eg
servers:
  - url: https://api.easy-orders.net/api/partners-apps/v1
    description: Production
security:
  - accessToken: []
tags:
  - name: Article categories
    description: >-
      The categories of the store's blog, which articles name in their
      `category_ids`.
  - name: Articles
    description: The articles of the store's blog, with HTML content, tags and categories.
  - name: Billing
    description: >-
      Your app's plan subscription and usage wallet on the store, and debiting
      the wallet by usage.
  - name: Categories
    description: The store's product categories and subcategories.
  - name: Checkout fields
    description: >-
      The fields of the store's checkout form, their labels, order, and whether
      they show and are required.
  - name: Coupons
    description: >-
      The store's coupons, by code or automatic, and the products, variants and
      categories they apply to.
  - name: Labels
    description: >-
      Your app's short colored words on orders and products, shown in the
      merchant's orders and products tables.
  - name: Missed orders
    description: >-
      Checkouts the shopper started and did not finish, to follow up and
      recover.
  - name: Orders
    description: The store's orders, their status, payment status and notes.
  - name: Pages
    description: >-
      The store's pages, such as About us or the return policy, with HTML
      content.
  - name: Products
    description: The store's products, their options, variants and stock.
  - name: Reviews
    description: >-
      The reviews of the store's products, and which of them the product page
      shows.
  - name: Shipping
    description: The store's shipping settings and shipping areas (governorates).
  - name: Store
    description: >-
      The store the access token belongs to, its addresses, currency, language
      and plan.
paths:
  /coupons:
    post:
      tags:
        - Coupons
      summary: Create a coupon
      description: |
        **Scope:** [`write_discounts`](/scopes)

        Creates a coupon. Only `method` and `discount_type` are required;
        every other field takes its default. The whole coupon must then
        follow the [coupon rules](/api-reference/coupons/overview#rules):
        a `code` coupon needs a `code`, an `automatic` one needs a `title`
        and no code, and so on.

        - The code is trimmed and saved lowercased. Another live coupon of
          the store with the same code answers `409 code_taken`.
        - Each applicable item must be a product, variant or category of
          this store; one that is not answers `422` on its `item_id`, with
          its type as the rule.

        Send an `Idempotency-Key` to retry safely.
      operationId: createCoupon
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CouponCreate'
            example:
              method: code
              code: SUMMER15
              discount_type: amount_off_products
              value_type: percentage
              value: 15
              max_discount_amount: 200
              usage_limit: 500
              expires_at: '2027-09-01T00:00:00Z'
              applies_to: specific_categories
              applicable_items:
                - item_type: category
                  item_id: 8d2f4b6a-1c3e-4a5b-9d7f-0e1a2b3c4d5e
      responses:
        '201':
          description: The coupon created. `Location` is its path.
          headers:
            Location:
              schema:
                type: string
            Idempotent-Replayed:
              description: >-
                `true` when this is the saved answer of an earlier request with
                the same `Idempotency-Key`.
              schema:
                type: string
          content:
            application/json:
              schema:
                type: object
                required:
                  - coupon
                properties:
                  coupon:
                    $ref: '#/components/schemas/Coupon'
              example:
                coupon:
                  id: 4b7e2c1a-9d3f-4e6b-8a5c-2f1d0e9c8b7a
                  method: code
                  code: summer15
                  title: ''
                  discount_type: amount_off_products
                  value_type: percentage
                  value: 15
                  min_order_amount: 0
                  min_quantity: 0
                  max_discount_amount: 200
                  usage_limit: 500
                  usage_count: 37
                  is_active: true
                  starts_at: null
                  expires_at: '2027-09-01T00:00:00Z'
                  applies_to: specific_categories
                  buy_quantity: 0
                  buy_requirement_type: quantity
                  buy_amount: 0
                  get_quantity: 0
                  get_value_type: free
                  get_value: 0
                  max_uses_per_order: 0
                  max_shipping_discount: 0
                  exclude_shipping_over: 0
                  combines_with_product: false
                  combines_with_order: false
                  combines_with_shipping: true
                  applicable_items:
                    - item_type: category
                      item_id: 8d2f4b6a-1c3e-4a5b-9d7f-0e1a2b3c4d5e
                      is_buy_item: false
                  created_at: '2026-12-01T09:00:00Z'
                  updated_at: '2026-12-03T14:30:00Z'
        '400':
          $ref: '#/components/responses/InvalidRequest'
        '401':
          $ref: '#/components/responses/Unauthenticated'
        '402':
          $ref: '#/components/responses/PaymentRequired'
        '403':
          $ref: '#/components/responses/InsufficientScope'
        '409':
          description: '`code_taken` or `idempotency_in_progress`.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  code: code_taken
                  message: Another coupon of the store has this code
        '422':
          $ref: '#/components/responses/ValidationFailed'
        '429':
          $ref: '#/components/responses/RateLimited'
      x-codeSamples:
        - lang: bash
          label: cURL
          source: >-
            curl -X POST
            "https://api.easy-orders.net/api/partners-apps/v1/coupons" \
              -H "Authorization: Bearer $EASYORDERS_ACCESS_TOKEN" \
              -H "Idempotency-Key: promo-summer-2027" \
              -H "Content-Type: application/json" \
              -d '{
              "method": "code",
              "code": "SUMMER15",
              "discount_type": "amount_off_products",
              "value_type": "percentage",
              "value": 15,
              "max_discount_amount": 200,
              "usage_limit": 500,
              "expires_at": "2027-09-01T00:00:00Z",
              "applies_to": "specific_categories",
              "applicable_items": [
                {
                  "item_type": "category",
                  "item_id": "8d2f4b6a-1c3e-4a5b-9d7f-0e1a2b3c4d5e"
                }
              ]
            }'
        - lang: typescript
          label: TypeScript
          source: >-
            const response = await
            fetch('https://api.easy-orders.net/api/partners-apps/v1/coupons', {
              method: 'POST',
              headers: {
                Authorization: `Bearer ${process.env.EASYORDERS_ACCESS_TOKEN}`,
                'Idempotency-Key': 'promo-summer-2027',
                'Content-Type': 'application/json',
              },
              body: JSON.stringify({
                method: 'code',
                code: 'SUMMER15',
                discount_type: 'amount_off_products',
                value_type: 'percentage',
                value: 15,
                max_discount_amount: 200,
                usage_limit: 500,
                expires_at: '2027-09-01T00:00:00Z',
                applies_to: 'specific_categories',
                applicable_items: [
                  {
                    item_type: 'category',
                    item_id: '8d2f4b6a-1c3e-4a5b-9d7f-0e1a2b3c4d5e',
                  },
                ],
              }),
            })


            const json = await response.json()

            if (!response.ok) {
              throw new Error(`${json.error.code}: ${json.error.message}`)
            }

            const { coupon } = json
        - lang: go
          label: Go
          source: "package main\n\nimport (\n\t\"bytes\"\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"net/http\"\n\t\"os\"\n)\n\nfunc main() {\n\tbody := []byte(`{\n\t  \"method\": \"code\",\n\t  \"code\": \"SUMMER15\",\n\t  \"discount_type\": \"amount_off_products\",\n\t  \"value_type\": \"percentage\",\n\t  \"value\": 15,\n\t  \"max_discount_amount\": 200,\n\t  \"usage_limit\": 500,\n\t  \"expires_at\": \"2027-09-01T00:00:00Z\",\n\t  \"applies_to\": \"specific_categories\",\n\t  \"applicable_items\": [\n\t    {\n\t      \"item_type\": \"category\",\n\t      \"item_id\": \"8d2f4b6a-1c3e-4a5b-9d7f-0e1a2b3c4d5e\"\n\t    }\n\t  ]\n\t}`)\n\n\treq, err := http.NewRequest(\"POST\", \"https://api.easy-orders.net/api/partners-apps/v1/coupons\", bytes.NewReader(body))\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\treq.Header.Set(\"Authorization\", \"Bearer \"+os.Getenv(\"EASYORDERS_ACCESS_TOKEN\"))\n\treq.Header.Set(\"Idempotency-Key\", \"promo-summer-2027\")\n\treq.Header.Set(\"Content-Type\", \"application/json\")\n\n\tres, err := http.DefaultClient.Do(req)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tdefer res.Body.Close()\n\n\tvar answer map[string]any\n\tif err := json.NewDecoder(res.Body).Decode(&answer); err != nil {\n\t\tpanic(err)\n\t}\n\tif res.StatusCode >= 300 {\n\t\tpanic(fmt.Sprint(res.Status, answer[\"error\"]))\n\t}\n\tfmt.Println(answer[\"coupon\"])\n}"
        - lang: php
          label: PHP
          source: >-
            <?php


            $ch =
            curl_init('https://api.easy-orders.net/api/partners-apps/v1/coupons');

            curl_setopt_array($ch, [
                CURLOPT_CUSTOMREQUEST => 'POST',
                CURLOPT_RETURNTRANSFER => true,
                CURLOPT_HTTPHEADER => [
                    'Authorization: Bearer ' . getenv('EASYORDERS_ACCESS_TOKEN'),
                    'Idempotency-Key: promo-summer-2027',
                    'Content-Type: application/json',
                ],
                CURLOPT_POSTFIELDS => json_encode([
                    'method' => 'code',
                    'code' => 'SUMMER15',
                    'discount_type' => 'amount_off_products',
                    'value_type' => 'percentage',
                    'value' => 15,
                    'max_discount_amount' => 200,
                    'usage_limit' => 500,
                    'expires_at' => '2027-09-01T00:00:00Z',
                    'applies_to' => 'specific_categories',
                    'applicable_items' => [
                        [
                            'item_type' => 'category',
                            'item_id' => '8d2f4b6a-1c3e-4a5b-9d7f-0e1a2b3c4d5e',
                        ],
                    ],
                ]),
            ]);


            $answer = json_decode(curl_exec($ch), true);

            $status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);

            curl_close($ch);


            if ($status >= 300) {
                throw new RuntimeException($answer['error']['code'] . ': ' . $answer['error']['message']);
            }

            $coupon = $answer['coupon'];
        - lang: python
          label: Python
          source: |-
            import os

            import requests

            response = requests.post(
                "https://api.easy-orders.net/api/partners-apps/v1/coupons",
                headers={
                    "Authorization": f"Bearer {os.environ['EASYORDERS_ACCESS_TOKEN']}",
                    "Idempotency-Key": "promo-summer-2027",
                },
                json={
                    "method": "code",
                    "code": "SUMMER15",
                    "discount_type": "amount_off_products",
                    "value_type": "percentage",
                    "value": 15,
                    "max_discount_amount": 200,
                    "usage_limit": 500,
                    "expires_at": "2027-09-01T00:00:00Z",
                    "applies_to": "specific_categories",
                    "applicable_items": [
                        {
                            "item_type": "category",
                            "item_id": "8d2f4b6a-1c3e-4a5b-9d7f-0e1a2b3c4d5e",
                        },
                    ],
                },
                timeout=30,
            )
            answer = response.json()
            if not response.ok:
                raise RuntimeError(f"{answer['error']['code']}: {answer['error']['message']}")
            coupon = answer["coupon"]
components:
  parameters:
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      description: |
        A unique key (up to 255 printable ASCII characters). The same key
        from your app within 24 hours answers the first result again, with
        `Idempotent-Replayed: true`, instead of creating twice.
      schema:
        type: string
        maxLength: 255
  schemas:
    CouponCreate:
      type: object
      required:
        - method
        - discount_type
      additionalProperties: false
      description: Only `starts_at` and `expires_at` take `null`.
      properties:
        method:
          $ref: '#/components/schemas/CouponMethod'
        code:
          type: string
          maxLength: 64
          description: >-
            Letters of any language, digits, `-` and `_`. Trimmed and saved
            lowercased. Required on a `code` coupon; `""` (or left out) on an
            `automatic` one.
        title:
          type: string
          maxLength: 255
          description: One line, trimmed, no `<`. Required on an `automatic` coupon.
        discount_type:
          $ref: '#/components/schemas/CouponDiscountType'
        value_type:
          type: string
          default: fixed
          enum:
            - fixed
            - percentage
        value:
          allOf:
            - $ref: '#/components/schemas/CouponMoney'
          description: >-
            Above 0 for `amount_off_products` and `amount_off_order`; at most
            100 as a percentage.
        min_order_amount:
          $ref: '#/components/schemas/CouponMoney'
        min_quantity:
          $ref: '#/components/schemas/CouponCount'
        max_discount_amount:
          $ref: '#/components/schemas/CouponMoney'
        usage_limit:
          type: integer
          minimum: 0
          maximum: 1000000000
          default: 0
          description: '`0` is no limit.'
        is_active:
          type: boolean
          default: true
        starts_at:
          $ref: '#/components/schemas/CouponScheduleTime'
        expires_at:
          allOf:
            - $ref: '#/components/schemas/CouponScheduleTime'
          description: Not before `starts_at`.
        applies_to:
          allOf:
            - $ref: '#/components/schemas/CouponAppliesTo'
          default: all
        buy_quantity:
          $ref: '#/components/schemas/CouponCount'
        buy_requirement_type:
          type: string
          default: quantity
          enum:
            - quantity
            - amount
        buy_amount:
          $ref: '#/components/schemas/CouponMoney'
        get_quantity:
          $ref: '#/components/schemas/CouponCount'
        get_value_type:
          type: string
          default: free
          enum:
            - free
            - percentage
            - fixed
        get_value:
          allOf:
            - $ref: '#/components/schemas/CouponMoney'
          description: >-
            Above 0 unless `get_value_type` is `free`; at most 100 as a
            percentage.
        max_uses_per_order:
          $ref: '#/components/schemas/CouponCount'
        max_shipping_discount:
          $ref: '#/components/schemas/CouponMoney'
        exclude_shipping_over:
          $ref: '#/components/schemas/CouponMoney'
        combines_with_product:
          type: boolean
          default: false
        combines_with_order:
          type: boolean
          default: false
        combines_with_shipping:
          type: boolean
          default: false
        applicable_items:
          type: array
          maxItems: 100
          description: No item twice.
          items:
            $ref: '#/components/schemas/CouponItemInput'
    Coupon:
      type: object
      properties:
        id:
          type: string
          format: uuid
        method:
          $ref: '#/components/schemas/CouponMethod'
        code:
          type: string
          description: Lowercase. `""` for an automatic coupon.
        title:
          type: string
          description: >-
            The coupon's name, shown on the storefront (an automatic coupon's
            banner). Required on an automatic coupon; `""` for none.
        discount_type:
          $ref: '#/components/schemas/CouponDiscountType'
        value_type:
          type: string
          description: How `value` reads, `fixed` or `percentage`.
        value:
          type: number
          description: >-
            The discount of `amount_off_products` and `amount_off_order`, an
            amount or a percentage per `value_type`.
        min_order_amount:
          type: number
        min_quantity:
          type: integer
        max_discount_amount:
          type: number
        usage_limit:
          type: integer
          description: How many times the coupon can be used; `0` is no limit.
        usage_count:
          type: integer
          description: How many orders used the coupon. Read only.
        is_active:
          type: boolean
        starts_at:
          type:
            - string
            - 'null'
          format: date-time
          description: '`null`: no start.'
        expires_at:
          type:
            - string
            - 'null'
          format: date-time
          description: '`null`: no expiry.'
        applies_to:
          $ref: '#/components/schemas/CouponAppliesTo'
        buy_quantity:
          type: integer
          description: >-
            `buy_x_get_y`: how many buy items the cart needs, when
            `buy_requirement_type` is `quantity`.
        buy_requirement_type:
          type: string
          description: >-
            `buy_x_get_y`: whether the shopper must buy a quantity
            (`buy_quantity`) or an amount (`buy_amount`).
          enum:
            - quantity
            - amount
        buy_amount:
          type: number
          description: >-
            `buy_x_get_y`: how much the buy items must cost, when
            `buy_requirement_type` is `amount`.
        get_quantity:
          type: integer
          description: '`buy_x_get_y`: how many get items the shopper gets.'
        get_value_type:
          type: string
          description: >-
            `buy_x_get_y`: how the get items are discounted: `free`, or by
            `get_value` as a `percentage` or a `fixed` amount.
          enum:
            - free
            - percentage
            - fixed
        get_value:
          type: number
        max_uses_per_order:
          type: integer
        max_shipping_discount:
          type: number
        exclude_shipping_over:
          type: number
        combines_with_product:
          type: boolean
          description: >-
            Whether it combines with product coupons (`amount_off_products`,
            `buy_x_get_y`). Two coupons combine only when each allows the
            other's kind.
        combines_with_order:
          type: boolean
          description: Whether it combines with order coupons (`amount_off_order`).
        combines_with_shipping:
          type: boolean
          description: Whether it combines with shipping coupons (`free_shipping`).
        applicable_items:
          type: array
          description: >-
            What the coupon applies to; `[]` for none. Buy items first, then by
            type and ID.
          items:
            $ref: '#/components/schemas/CouponItem'
        created_at:
          type: string
          format: date-time
          description: '`1970-01-01T00:00:00Z` for an old coupon saved without one.'
        updated_at:
          type: string
          format: date-time
    Error:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          required:
            - code
            - message
          properties:
            code:
              type: string
              description: A stable, snake_case code. Branch on it, not on the message.
            message:
              type: string
              description: A human-readable explanation. It may change.
            details:
              description: More about the error, shaped per code.
    CouponMethod:
      type: string
      description: >-
        `code`: the shopper types the code at checkout. `automatic`: applied
        without a code.
      enum:
        - code
        - automatic
    CouponDiscountType:
      type: string
      description: |
        `amount_off_products`: off the products' prices. `amount_off_order`:
        off the order. `free_shipping`: off the shipping cost. `buy_x_get_y`:
        buy some items, get others free or discounted.
      enum:
        - amount_off_products
        - amount_off_order
        - free_shipping
        - buy_x_get_y
    CouponMoney:
      type: number
      minimum: 0
      maximum: 100000000
      description: An amount in the store's currency, with at most 4 decimals.
    CouponCount:
      type: integer
      minimum: 0
      maximum: 1000000
    CouponScheduleTime:
      type:
        - string
        - 'null'
      format: date-time
      description: >-
        RFC 3339, from `2000-01-01T00:00:00Z` to `2100-01-01T00:00:00Z`. Kept in
        UTC, to the microsecond.
    CouponAppliesTo:
      type: string
      description: '`specific_products` and `specific_categories` need `applicable_items`.'
      enum:
        - all
        - specific_products
        - specific_categories
    CouponItemInput:
      type: object
      required:
        - item_type
        - item_id
      additionalProperties: false
      properties:
        item_type:
          type: string
          enum:
            - product
            - variant
            - category
        item_id:
          type: string
          format: uuid
          description: A live product, variant or category of this store.
        is_buy_item:
          type: boolean
          default: false
          description: '`buy_x_get_y`: `true` for a buy item; the others are get items.'
    CouponItem:
      type: object
      properties:
        item_type:
          type: string
          description: >-
            `product` (every variant of it), `variant` (one variant of a
            product) or `category`.
          enum:
            - product
            - variant
            - category
        item_id:
          type: string
          format: uuid
          description: The product's, variant's or category's ID.
        is_buy_item:
          type: boolean
          description: '`buy_x_get_y`: `true` for a buy item; the others are get items.'
    FieldError:
      type: object
      required:
        - field
        - rule
      properties:
        field:
          type: string
          description: The JSON path of the input, e.g. `items[0].quantity`.
        rule:
          type: string
          description: The rule that failed, e.g. `required`, `between` or `in`.
        param:
          type: string
          description: The rule's parameter, e.g. `1,10000` for `between`.
  responses:
    InvalidRequest:
      description: >-
        The body is not a JSON object, or has a field of the wrong type or an
        unknown field.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: invalid_request
              message: 'Invalid JSON body: unknown field'
    Unauthenticated:
      description: The access token is missing, invalid or expired.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: unauthenticated
              message: Missing or invalid access token
    PaymentRequired:
      description: Your app's subscription on this store is suspended.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: payment_required
              message: The app's subscription on this store is suspended
    InsufficientScope:
      description: The token lacks the scope this endpoint needs.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: insufficient_scope
              message: 'This request requires the scope: read_orders'
              details:
                required_scope: read_orders
    ValidationFailed:
      description: The request broke one or more rules; `details.fields` lists every one.
      content:
        application/json:
          schema:
            allOf:
              - $ref: '#/components/schemas/Error'
              - type: object
                properties:
                  error:
                    type: object
                    properties:
                      details:
                        type: object
                        properties:
                          fields:
                            type: array
                            items:
                              $ref: '#/components/schemas/FieldError'
          example:
            error:
              code: validation_failed
              message: Validation failed
              details:
                fields:
                  - field: items[0].quantity
                    rule: between
                    param: 1,10000
    RateLimited:
      description: More than 600 requests in a minute from your app on this store.
      headers:
        Retry-After:
          $ref: '#/components/headers/Retry-After'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: too_many_requests
              message: Rate limit exceeded
  headers:
    Retry-After:
      description: Seconds to wait before retrying.
      schema:
        type: integer
  securitySchemes:
    accessToken:
      type: http
      scheme: bearer
      description: >
        An access token from the OAuth flow (`eo_at_...`). It lasts one hour;

        refresh it with the refresh token. See
        [Authentication](/authentication).

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.