> ## 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.

# Genera coupon

> Genera un nuovo coupon utilizzando un generatore predefinito configurato nel backend del ristorante



## OpenAPI

````yaml openapi-it.json POST /coupon/generate
openapi: 3.1.0
info:
  title: xMenu API
  description: API Pubblica xMenu - Endpoint REST e notifiche webhook
  version: 1.0.0
servers:
  - url: https://app.xmenu.it/api
    description: xMenu API Production
security: []
paths:
  /coupon/generate:
    post:
      tags:
        - Azioni Coupon
      summary: Genera coupon
      description: >-
        Genera un nuovo coupon utilizzando un generatore predefinito configurato
        nel backend del ristorante. Il coupon viene creato secondo le regole
        specificate nel generatore.
      operationId: couponGenerate
      parameters:
        - name: restuid
          in: query
          required: true
          schema:
            type: string
          description: Identificatore univoco ristorante
        - name: gencode
          in: query
          required: true
          schema:
            type: string
          description: >-
            Codice del generatore creato nell'area backend del ristorante (per
            generare il coupon secondo le regole del generatore)
        - name: valid_email
          in: query
          required: false
          schema:
            type: string
          description: >-
            Indirizzo email del cliente. Il coupon sarà utilizzabile solo da
            questo cliente.
      responses:
        '200':
          description: Risposta generazione coupon
          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: >-
            Risultato dell'operazione: `true` se ha avuto successo, `false` se è
            fallita
        error:
          type: string
          description: >-
            Codice errore se l'operazione è fallita. Valori possibili:

            - `NOT_FOUND` = Generatore non trovato


            Vedi [Codici errore](/docs/it/overview/error-codes) per i codici
            errore generali che possono verificarsi.
        message:
          type: string
          description: Descrizione leggibile dell'errore se l'operazione è fallita
        coupon:
          $ref: '#/components/schemas/CouponDetail'
    CouponDetail:
      type: object
      description: Oggetto coupon con dettagli sul codice sconto
      required:
        - code
        - discount_perc
        - quantity
        - order_min
        - valid_from
        - valid_to
      properties:
        code:
          type: string
          description: Codice coupon
        discount_perc:
          type: number
          description: Percentuale di sconto sul totale dell'ordine
        quantity:
          type: integer
          description: >-
            Il coupon può essere utilizzabile 1 o più volte. Se è impostato a 0,
            è utilizzabile infinite volte.
        order_min:
          type: number
          description: Minimo d'ordine per poter applicare il coupon
        valid_from:
          type: string
          format: date
          description: Data di inizio validità
        valid_to:
          type: string
          format: date
          description: Data di fine validità
        valid_weekdays:
          type: array
          items:
            type: integer
            minimum: 0
            maximum: 6
          description: >-
            Array dei giorni di validità (codice giorno da 0 = domenica a 6 =
            sabato). Presente solo se il coupon è utilizzabile solo in alcuni
            giorni della settimana.
        valid_email:
          type: string
          description: >-
            Indirizzo email del cliente. Presente solo se il coupon è riservato
            a un cliente specifico.
  responses:
    Unauthorized:
      description: Autenticazione fallita.
      content:
        application/json:
          schema:
            oneOf:
              - type: object
                description: >-
                  Formato errore standard (quando si usa autenticazione API Key
                  o Client ID/Secret)
                required:
                  - success
                  - error
                properties:
                  success:
                    type: boolean
                    enum:
                      - false
                    description: Sempre false per gli errori
                  error:
                    type: string
                    enum:
                      - RESTAURANT_NOT_FOUND
                      - INVALID_KEY
                      - INVALID_AUTH
                    description: Codice errore
                  message:
                    type: string
                    description: Descrizione errore leggibile
              - type: object
                description: >-
                  Formato errore OAuth (quando si usa l'autenticazione Bearer
                  token)
                required:
                  - error
                properties:
                  error:
                    type: string
                    enum:
                      - invalid_token
                      - invalid_request
                    description: Codice errore OAuth (RFC 6749)
                  error_description:
                    type: string
                    description: Descrizione errore leggibile
          examples:
            standard:
              summary: Formato errore standard (API Key / Client ID+Secret)
              value:
                success: false
                error: INVALID_KEY
                message: La chiave API fornita non è valida
            oauth:
              summary: Formato errore OAuth (Bearer token)
              value:
                error: invalid_token
                error_description: Access token non valido o scaduto
    Forbidden:
      description: Autorizzazione fallita - permessi insufficienti o accesso negato.
      content:
        application/json:
          schema:
            oneOf:
              - type: object
                description: >-
                  Formato errore standard (quando si usa autenticazione API Key
                  o Client ID/Secret)
                required:
                  - success
                  - error
                properties:
                  success:
                    type: boolean
                    enum:
                      - false
                    description: Sempre false per gli errori
                  error:
                    type: string
                    enum:
                      - API_DISABLED
                      - INSUFFICIENT_SCOPE
                      - UNAUTHORIZED
                    description: Codice errore
                  message:
                    type: string
                    description: Descrizione errore leggibile
              - type: object
                description: >-
                  Formato errore OAuth (quando si usa l'autenticazione Bearer
                  token)
                required:
                  - error
                properties:
                  error:
                    type: string
                    enum:
                      - insufficient_scope
                      - invalid_request
                    description: Codice errore OAuth (RFC 6749)
                  error_description:
                    type: string
                    description: Descrizione errore leggibile
          examples:
            standard:
              summary: Formato errore standard (API Key / Client ID+Secret)
              value:
                success: false
                error: API_DISABLED
                message: L'accesso API non è abilitato per il ristorante
            oauth:
              summary: Formato errore OAuth (Bearer token)
              value:
                error: insufficient_scope
                error_description: 'Permessi mancanti richiesti: write:orders'
  securitySchemes:
    apiKey:
      type: apiKey
      in: header
      name: X-Api-Key
      description: >-
        Chiave API del ristorante. Può essere ottenuta da Strumenti > Accesso
        API nella dashboard xMenu.
    clientId:
      type: apiKey
      in: header
      name: X-Client-Id
      description: >-
        Client ID per l'autenticazione API Client (deve essere usato insieme al
        Client Secret)
    clientSecret:
      type: apiKey
      in: header
      name: X-Client-Secret
      description: >-
        Client Secret per l'autenticazione API Client (deve essere usato insieme
        al Client ID)
    oauth2:
      type: oauth2
      flows:
        clientCredentials:
          tokenUrl: https://app.xmenu.it/oauth/token
          scopes: {}
      description: >-
        Autenticazione OAuth 2.0 utilizzando il flusso client credentials. Il
        token di accesso deve essere incluso nell'header Authorization come
        Bearer token.

````