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

# Create a code batch

> Creates a batch of up to **32,768 unique single-use codes** per batch (create multiple batches for larger runs) to print
on physical products. Creation is instant — codes are derived from a
per-batch cryptographic secret, not stored — and **you are only
charged the per-transaction fee when a code is actually redeemed** by
a customer in the Rigaly app.

Download the codes with the export endpoint. `example_code` shows the
exact print format (`[PREFIX-]XXXX-XXX-XXX-XXX`), and
`example_deep_link` the recommended QR payload — print each code's
`deep_link` as a QR code so scanning it opens the Rigaly app with the
code ready to claim (or an install page when the app is missing).




## OpenAPI

````yaml /openapi/v1.yaml post /api/v1/code-batches
openapi: 3.1.0
info:
  title: Rigaly Business API
  version: '1.0'
  description: |
    Public API for businesses to manage their Rigaly loyalty programs: issue
    and redeem points, manage rewards, validate redemptions, and generate mass
    codes for physical products.

    All endpoints require an API key created in the Rigaly business dashboard
    (Tools → API Management), passed as `Authorization: Bearer rgly_sk_...`.
  contact:
    email: support@rigaly.com
servers:
  - url: https://api.rigaly.com
    description: Production
security:
  - apiKey: []
paths:
  /api/v1/code-batches:
    post:
      tags:
        - Code batches
      summary: Create a code batch
      description: >
        Creates a batch of up to **32,768 unique single-use codes** per batch
        (create multiple batches for larger runs) to print

        on physical products. Creation is instant — codes are derived from a

        per-batch cryptographic secret, not stored — and **you are only

        charged the per-transaction fee when a code is actually redeemed** by

        a customer in the Rigaly app.


        Download the codes with the export endpoint. `example_code` shows the

        exact print format (`[PREFIX-]XXXX-XXX-XXX-XXX`), and

        `example_deep_link` the recommended QR payload — print each code's

        `deep_link` as a QR code so scanning it opens the Rigaly app with the

        code ready to claim (or an install page when the app is missing).
      operationId: createCodeBatch
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - name
                - points
                - quantity
                - expires_at
              properties:
                name:
                  type: string
                  maxLength: 100
                  example: Summer 2027 bottles
                points:
                  type: integer
                  minimum: 1
                  example: 250
                  description: Points each code awards when claimed
                quantity:
                  type: integer
                  minimum: 1
                  maximum: 32768
                  example: 30000
                expires_at:
                  type: string
                  format: date-time
                  example: '2027-12-31T23:59:59Z'
                prefix:
                  type: string
                  pattern: ^[A-Z0-9]{1,10}$
                  nullable: true
                  example: SUMMER
                  description: Cosmetic print prefix
      responses:
        '201':
          description: Batch created
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/SuccessEnvelope'
                  - type: object
                    properties:
                      data:
                        type: object
                        properties:
                          batch:
                            $ref: '#/components/schemas/CodeBatch'
                          example_code:
                            type: string
                            example: SUMMER-595Y-000-JT5-A5Q
                          example_deep_link:
                            type: string
                            example: HTTPS://LINK.RIGALY.COM/CODE/595Y000JT5A5Q
        '400':
          $ref: '#/components/responses/BadRequest'
components:
  schemas:
    SuccessEnvelope:
      type: object
      properties:
        success:
          type: boolean
          example: true
        message:
          type: string
        data:
          type: object
    CodeBatch:
      type: object
      properties:
        id:
          type: string
          format: uuid
        business_id:
          type: string
          format: uuid
        batch_ref:
          type: string
          example: 595Y
        name:
          type: string
          example: Summer 2027 bottles
        prefix:
          type: string
          nullable: true
          example: SUMMER
        points:
          type: integer
          example: 250
        quantity:
          type: integer
          example: 30000
        expires_at:
          type: string
          format: date-time
        active:
          type: boolean
        created_via:
          type: string
          example: api
        created_at:
          type: string
          format: date-time
        failed_attempts:
          type: integer
          example: 0
          description: >-
            Claim attempts that failed signature verification — a
            counterfeiting-attempt signal. Deactivate the batch if it spikes
            unexpectedly.
    ErrorEnvelope:
      type: object
      properties:
        success:
          type: boolean
          example: false
        error:
          type: object
          properties:
            message:
              type: string
  responses:
    BadRequest:
      description: Validation or business-rule error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorEnvelope'
          example:
            success: false
            error:
              message: Provide exactly one of "user_id" or "identifier"
  securitySchemes:
    apiKey:
      type: http
      scheme: bearer
      description: 'API key from the Rigaly dashboard: `Authorization: Bearer rgly_sk_...`'

````