> ## Documentation Index
> Fetch the complete documentation index at: https://api-doc.xmenu.it/llms.txt
> Use this file to discover all available pages before exploring further.

# Generate coupon

> Generates a new coupon using a predefined generator configured in the restaurant backend



## OpenAPI

````yaml openapi-en.json POST /coupon/generate
openapi: 3.1.0
info:
  title: xMenu API
  description: xMenu Public API - REST endpoints and webhook notifications
  version: 1.0.0
servers:
  - url: https://app.xmenu.it/api
    description: xMenu API Production
security: []
paths:
  /coupon/generate:
    post:
      tags:
        - Coupon Actions
      summary: Generate coupon
      description: >-
        Generates a new coupon using a predefined generator configured in the
        restaurant backend. The coupon is created according to the rules
        specified in the generator.
      operationId: couponGenerate
      parameters:
        - name: restuid
          in: query
          required: true
          schema:
            type: string
          description: Unique restaurant identifier
        - name: gencode
          in: query
          required: true
          schema:
            type: string
          description: >-
            Generator code created in the restaurant backend area (to generate
            the coupon according to the generator rules)
        - name: valid_email
          in: query
          required: false
          schema:
            type: string
          description: >-
            Email address of the customer. Coupon will be usable only by this
            customer.
      responses:
        '200':
          description: Coupon generation response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CouponGenerateResponse'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
      security:
        - apiKey: []
        - clientId: []
          clientSecret: []
        - oauth2: []
components:
  schemas:
    CouponGenerateResponse:
      type: object
      required:
        - success
      properties:
        success:
          type: boolean
          description: 'Operation result: `true` if successful, `false` if failed'
        error:
          type: string
          description: >-
            Error code if the operation failed. Possible values:

            - `NOT_FOUND` = Generator not found


            See [Error codes](/docs/en/overview/error-codes) for general error
            codes that may also occur.
        message:
          type: string
          description: Human-readable error description if the operation failed
        coupon:
          $ref: '#/components/schemas/CouponDetail'
    CouponDetail:
      type: object
      description: Coupon object with details about discount code
      required:
        - code
        - discount_perc
        - quantity
        - order_min
        - valid_from
        - valid_to
      properties:
        code:
          type: string
          description: Coupon code
        discount_perc:
          type: number
          description: Discount percentage on order total
        quantity:
          type: integer
          description: >-
            Number of times the coupon can be used. If set to 0, it can be used
            unlimited times.
        order_min:
          type: number
          description: Minimum order amount required to apply the coupon
        valid_from:
          type: string
          format: date
          description: Validity start date
        valid_to:
          type: string
          format: date
          description: Validity end date
        valid_weekdays:
          type: array
          items:
            type: integer
            minimum: 0
            maximum: 6
          description: >-
            Array of valid weekdays (0 = Sunday to 6 = Saturday). Only present
            if the coupon is valid only on specific days of the week.
        valid_email:
          type: string
          description: >-
            Email address of the customer. Only present if the coupon is
            restricted to a specific customer.
  responses:
    Unauthorized:
      description: Authentication failed.
      content:
        application/json:
          schema:
            oneOf:
              - type: object
                description: >-
                  Standard error format (when using API Key or Client ID/Secret
                  authentication)
                required:
                  - success
                  - error
                properties:
                  success:
                    type: boolean
                    enum:
                      - false
                    description: Always false for errors
                  error:
                    type: string
                    enum:
                      - RESTAURANT_NOT_FOUND
                      - INVALID_KEY
                      - INVALID_AUTH
                    description: Error code
                  message:
                    type: string
                    description: Human-readable error description
              - type: object
                description: OAuth error format (when using Bearer token authentication)
                required:
                  - error
                properties:
                  error:
                    type: string
                    enum:
                      - invalid_token
                      - invalid_request
                    description: OAuth error code (RFC 6749)
                  error_description:
                    type: string
                    description: Human-readable error description
          examples:
            standard:
              summary: Standard error format (API Key / Client ID+Secret)
              value:
                success: false
                error: INVALID_KEY
                message: The provided API key is not valid
            oauth:
              summary: OAuth error format (Bearer token)
              value:
                error: invalid_token
                error_description: Access token is invalid or expired
    Forbidden:
      description: Authorization failed - insufficient permissions or access denied.
      content:
        application/json:
          schema:
            oneOf:
              - type: object
                description: >-
                  Standard error format (when using API Key or Client ID/Secret
                  authentication)
                required:
                  - success
                  - error
                properties:
                  success:
                    type: boolean
                    enum:
                      - false
                    description: Always false for errors
                  error:
                    type: string
                    enum:
                      - API_DISABLED
                      - INSUFFICIENT_SCOPE
                      - UNAUTHORIZED
                    description: Error code
                  message:
                    type: string
                    description: Human-readable error description
              - type: object
                description: OAuth error format (when using Bearer token authentication)
                required:
                  - error
                properties:
                  error:
                    type: string
                    enum:
                      - insufficient_scope
                      - invalid_request
                    description: OAuth error code (RFC 6749)
                  error_description:
                    type: string
                    description: Human-readable error description
          examples:
            standard:
              summary: Standard error format (API Key / Client ID+Secret)
              value:
                success: false
                error: API_DISABLED
                message: API access is not enabled for the restaurant
            oauth:
              summary: OAuth error format (Bearer token)
              value:
                error: insufficient_scope
                error_description: 'Missing required permissions: write:orders'
  securitySchemes:
    apiKey:
      type: apiKey
      in: header
      name: X-Api-Key
      description: >-
        Restaurant API Key. Can be obtained from Tools > API Access in the xMenu
        dashboard.
    clientId:
      type: apiKey
      in: header
      name: X-Client-Id
      description: >-
        Client ID for API Client authentication (must be used together with
        Client Secret)
    clientSecret:
      type: apiKey
      in: header
      name: X-Client-Secret
      description: >-
        Client Secret for API Client authentication (must be used together with
        Client ID)
    oauth2:
      type: oauth2
      flows:
        clientCredentials:
          tokenUrl: https://app.xmenu.it/oauth/token
          scopes: {}
      description: >-
        OAuth 2.0 authentication using client credentials flow. The access token
        must be included in the Authorization header as a Bearer token.

````