> ## 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 earning rules

> 
<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 earning rules to/from a program in a single batch.
Unassign operations are processed before assign operations. When the program is
`ACTIVE`, the batch is validated to leave at least one active earning rule assigned.
In strict mode (default) missing earning rules or missing assignments cause the whole
batch to fail.



## OpenAPI

````yaml /openapi/loyalties-v2.json post /v2/loyalties/programs/{programId}/earning-rules/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}/earning-rules/batch:
    parameters:
      - name: programId
        in: path
        required: true
        description: Identifies the loyalty program. Format `lprg_[a-f0-9]+`.
        schema:
          type: string
          pattern: ^lprg_[a-f0-9]+$
    post:
      tags:
        - Programs
      summary: Batch assign/unassign earning rules
      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 earning rules to/from a program in a single
        batch.

        Unassign operations are processed before assign operations. When the
        program is

        `ACTIVE`, the batch is validated to leave at least one active earning
        rule assigned.

        In strict mode (default) missing earning rules or missing assignments
        cause the whole

        batch to fail.
      operationId: batchProgramEarningRuleAssignments
      parameters: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: >-
                #/components/schemas/V2LoyaltiesProgramsEarningRulesBatchRequestBody
      responses:
        '200':
          description: Batch processing result.
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/V2LoyaltiesProgramsEarningRulesBatchResponseBody
        '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'
        '423':
          description: >-
            Resource locked - a related resource is in a state that prevents
            this operation.
          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:
    V2LoyaltiesProgramsEarningRulesBatchRequestBody:
      title: V2 Loyalties Programs Earning Rules Batch Request Body
      type: object
      description: >-
        Request body schema for **POST**
        `/v2/loyalties/programs/{programId}/earning-rules/batch`.
      allOf:
        - $ref: '#/components/schemas/ProgramEarningRuleBatchRequest'
    V2LoyaltiesProgramsEarningRulesBatchResponseBody:
      title: V2 Loyalties Programs Earning Rules Batch Response Body
      type: object
      description: >-
        Response body schema for **POST**
        `/v2/loyalties/programs/{programId}/earning-rules/batch`.
      allOf:
        - $ref: '#/components/schemas/ProgramEarningRuleBatchResponse'
    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.
    ProgramEarningRuleBatchRequest:
      type: object
      description: >-
        Batch of earning rule assignment operations. `unassign` operations are
        processed

        before `assign` operations. Duplicate ids within a batch are rejected.
      properties:
        assign:
          description: Earning rules to assign.
          oneOf:
            - type: array
              items:
                $ref: '#/components/schemas/ProgramEarningRuleAssignItem'
              maxItems: 10
            - type: 'null'
        unassign:
          description: Earning rules to unassign.
          oneOf:
            - type: array
              items:
                $ref: '#/components/schemas/ProgramEarningRuleUnassignItem'
              maxItems: 10
            - type: 'null'
        options:
          description: Batch behavior. Defaults to strict mode when omitted.
          oneOf:
            - $ref: '#/components/schemas/ProgramEarningRuleBatchOptions'
            - type: 'null'
      additionalProperties: false
    ProgramEarningRuleBatchResponse:
      type: object
      description: >-
        Result of an earning rule 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/ProgramEarningRuleAssignment'
            - type: 'null'
        unassigned:
          description: >-
            Assignments removed by the batch, or `null` when no unassign
            operations were requested.
          oneOf:
            - type: array
              items:
                $ref: '#/components/schemas/ProgramEarningRuleAssignment'
            - type: 'null'
    ProgramEarningRuleAssignItem:
      description: Earning rule to assign to the program.
      allOf:
        - $ref: '#/components/schemas/ProgramEarningRuleAssignmentItem'
      unevaluatedProperties: false
    ProgramEarningRuleUnassignItem:
      description: Earning rule to unassign from the program.
      allOf:
        - $ref: '#/components/schemas/ProgramEarningRuleAssignmentItem'
      unevaluatedProperties: false
    ProgramEarningRuleBatchOptions:
      type: object
      description: Options for an earning rule assignment batch.
      properties:
        strict:
          type: boolean
          description: >-
            Fails the batch when an earning rule is missing, or when an
            assignment to remove is missing. Defaults to `true`.
          default: true
      additionalProperties: false
    ProgramEarningRuleAssignment:
      type: object
      description: An earning rule assigned to a program.
      properties:
        earning_rule_id:
          type: string
          description: Unique earning rule identifier.
          pattern: ^lern_[a-f0-9]+$
        created_at:
          type: string
          format: date-time
          description: Assignment creation timestamp (ISO 8601).
        object:
          type: string
          description: Object type marker. Always `program_earning_rule`.
          const: program_earning_rule
      required:
        - earning_rule_id
        - created_at
        - object
    ProgramEarningRuleAssignmentItem:
      type: object
      properties:
        id:
          type: string
          description: Unique earning rule identifier.
          pattern: ^lern_[a-f0-9]+$
      required:
        - id
  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.