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

# Batch assign/unassign rewards

> 
<Info>

<Badge color="gray">Documentation in progress</Badge>

This documentation is in progress. The parameters, fields, request and response bodies, and other data may be subject to change. If you need more information or you want to share feedback, contact [Voucherify support](https://www.voucherify.io/contact-support) or your Technical Account Manager.

</Info>

Assigns and/or unassigns rewards to/from a program in a single batch.
Unassign operations are processed before assign operations. Each reward to assign
must include its `stock` configuration. In strict mode (default) missing rewards
or missing assignments cause the whole batch to fail (`404 Not Found`).



## OpenAPI

````yaml /openapi/loyalties-v2.json post /v2/loyalties/programs/{programId}/rewards/batch
openapi: 3.1.0
info:
  title: Voucherify API - Loyalty v2
  version: v2018-08-01
  description: >-
    Voucherify promotion engine REST API. Please see
    https://docs.voucherify.io/docs for more details.
  contact:
    name: Voucherify Team
    url: https://www.voucherify.io/contact-support
    email: support@voucherify.io
  termsOfService: https://www.voucherify.io/legal/subscription-agreement
  license:
    name: MIT
    url: https://github.com/voucherifyio/voucherify-js-sdk/blob/main/LICENSE
servers:
  - url: https://{cluster}.voucherify.io
    description: Base URL
    variables:
      cluster:
        default: api
        enum:
          - api
          - us1.api
          - as1.api
          - download
          - us1.download
          - as1.download
security: []
paths:
  /v2/loyalties/programs/{programId}/rewards/batch:
    parameters:
      - name: programId
        in: path
        required: true
        description: Unique program identifier.
        schema:
          type: string
          pattern: ^lprg_[a-f0-9]+$
    post:
      tags:
        - Programs
      summary: Batch assign/unassign rewards
      description: >-

        <Info>


        <Badge color="gray">Documentation in progress</Badge>


        This documentation is in progress. The parameters, fields, request and
        response bodies, and other data may be subject to change. If you need
        more information or you want to share feedback, contact [Voucherify
        support](https://www.voucherify.io/contact-support) or your Technical
        Account Manager.


        </Info>


        Assigns and/or unassigns rewards to/from a program in a single batch.

        Unassign operations are processed before assign operations. Each reward
        to assign

        must include its `stock` configuration. In strict mode (default) missing
        rewards

        or missing assignments cause the whole batch to fail (`404 Not Found`).
      operationId: batchProgramRewardAssignments
      parameters: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/V2LoyaltiesProgramsRewardsBatchRequestBody'
      responses:
        '200':
          description: Batch processing result.
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/V2LoyaltiesProgramsRewardsBatchResponseBody
        '400':
          description: >-
            Validation error - request body or query parameters failed
            validation, or the operation is not allowed in the current resource
            state.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: Resource not found.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '409':
          description: Conflict - e.g. duplicate resource or invalid state transition.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Internal server error.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                Internal server error:
                  value:
                    code: 500
                    key: api_error
                    message: >-
                      Something went wrong. Don't worry, your campaigns are
                      still safe and the Voucherify Team has been notified.
                      Check out our Help Center and forums for help, or head
                      back to home.
      security:
        - X-App-Id: []
          X-App-Token: []
        - bearerAuth: []
components:
  schemas:
    V2LoyaltiesProgramsRewardsBatchRequestBody:
      title: V2 Loyalties Programs Rewards Batch Request Body
      type: object
      description: >-
        Request body schema for **POST**
        `/v2/loyalties/programs/{programId}/rewards/batch`.
      allOf:
        - $ref: '#/components/schemas/ProgramRewardBatchRequest'
    V2LoyaltiesProgramsRewardsBatchResponseBody:
      title: V2 Loyalties Programs Rewards Batch Response Body
      type: object
      description: >-
        Response body schema for **POST**
        `/v2/loyalties/programs/{programId}/rewards/batch`.
      allOf:
        - $ref: '#/components/schemas/ProgramRewardBatchResponse'
    ErrorResponse:
      type: object
      description: Standard error response returned by all Loyalty v2 endpoints.
      properties:
        code:
          type: integer
          description: HTTP status code of the error.
        key:
          type: string
          description: Machine-readable error key.
        message:
          type: string
          description: Human-readable error message.
        details:
          type: string
          description: Additional details about the error.
        request_id:
          type: string
          description: Unique identifier of the request that produced the error.
        resource_id:
          type: string
          description: Unique identifier of the resource that produced the error.
        resource_type:
          type: string
          description: Type of the resource that produced the error.
    ProgramRewardBatchRequest:
      type: object
      description: >-
        Batch of reward assignment operations. `unassign` operations are
        processed

        before `assign` operations. Duplicate ids within a batch are rejected.
      properties:
        assign:
          description: Rewards to assign, each with its stock configuration.
          oneOf:
            - type: array
              items:
                $ref: '#/components/schemas/ProgramRewardAssignItem'
              maxItems: 10
            - type: 'null'
        unassign:
          description: Rewards to unassign.
          oneOf:
            - type: array
              items:
                $ref: '#/components/schemas/ProgramRewardUnassignItem'
              maxItems: 10
            - type: 'null'
        options:
          description: Batch behavior. Defaults to strict mode when omitted.
          oneOf:
            - $ref: '#/components/schemas/ProgramRewardBatchOptions'
            - type: 'null'
      additionalProperties: false
    ProgramRewardBatchResponse:
      type: object
      description: >-
        Result of a reward assignment batch. Keys are null when the
        corresponding operation list was not provided.
      properties:
        assigned:
          description: >-
            Assignments created by the batch, or `null` when no assign
            operations were requested.
          oneOf:
            - type: array
              items:
                $ref: '#/components/schemas/ProgramRewardAssignment'
            - type: 'null'
        unassigned:
          description: >-
            Assignments removed by the batch, or `null` when no unassign
            operations were requested.
          oneOf:
            - type: array
              items:
                $ref: '#/components/schemas/ProgramRewardAssignment'
            - type: 'null'
    ProgramRewardAssignItem:
      type: object
      description: Reward to assign to the program, together with its stock configuration.
      properties:
        id:
          type: string
          description: Unique reward identifier.
          pattern: ^lrew_[a-f0-9]+$
        stock:
          $ref: '#/components/schemas/ProgramRewardAssignmentStock'
      required:
        - id
        - stock
      additionalProperties: false
    ProgramRewardUnassignItem:
      type: object
      description: Reward to unassign from the program.
      properties:
        id:
          type: string
          description: Unique reward identifier.
          pattern: ^lrew_[a-f0-9]+$
      required:
        - id
      additionalProperties: false
    ProgramRewardBatchOptions:
      type: object
      description: Options for a reward assignment batch.
      properties:
        strict:
          type: boolean
          description: >-
            Fails the batch when a reward is missing, or when an assignment to
            remove is missing. Defaults to `true`.
          default: true
      additionalProperties: false
    ProgramRewardAssignment:
      type: object
      description: >-
        A reward assigned to a program, with stock configuration and redemption
        counter.
      properties:
        reward_id:
          type: string
          description: Unique reward identifier.
          pattern: ^lrew_[a-f0-9]+$
        stock:
          $ref: '#/components/schemas/ProgramRewardAssignmentStock'
          description: Stock configuration of the assignment.
        redeemed:
          type: number
          description: >-
            Number of times the reward has been redeemed within the program.
            Defaults to 0.
        created_at:
          type: string
          format: date-time
          description: Assignment creation timestamp (ISO 8601).
        updated_at:
          type:
            - string
            - 'null'
          format: date-time
          description: Last update timestamp (ISO 8601), or `null` when never updated.
        object:
          type: string
          description: Object type marker. Always `program_reward`.
          const: program_reward
      required:
        - reward_id
        - stock
        - redeemed
        - created_at
        - updated_at
        - object
    ProgramRewardAssignmentStock:
      type: object
      description: >-
        Reward stock configuration. When `type` is `UNLIMITED`, `limited` must
        not be provided. When `type` is `LIMITED`, `limited` is required.
      properties:
        type:
          type: string
          description: Stock type.
          enum:
            - UNLIMITED
            - LIMITED
        limited:
          $ref: '#/components/schemas/ProgramRewardAssignmentStockLimited'
          description: >-
            Limited stock details. Required when `type` is `LIMITED`. Absent
            when `type` is `UNLIMITED`.
      required:
        - type
      additionalProperties: false
      allOf:
        - if:
            properties:
              type:
                const: UNLIMITED
          then:
            not:
              required:
                - limited
        - if:
            properties:
              type:
                const: LIMITED
          then:
            required:
              - limited
            properties:
              limited:
                $ref: '#/components/schemas/ProgramRewardAssignmentStockLimited'
    ProgramRewardAssignmentStockLimited:
      type: object
      description: Limited stock configuration.
      properties:
        quantity:
          type: integer
          description: >-
            Available stock quantity. For responses, updates with each reward
            purchase.
          minimum: 0
          maximum: 9007199254740991
      required:
        - quantity
      additionalProperties: false
  securitySchemes:
    X-App-Id:
      type: apiKey
      name: X-App-Id
      in: header
    X-App-Token:
      type: apiKey
      name: X-App-Token
      in: header
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

````

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