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

# Create Validation Rules Assignments

> Assign validation rule to either one of the following objects: voucher, campaign, promotion tier, earning rule, reward, distribution.



## OpenAPI

````yaml /openapi/validation-rules.json post /v1/validation-rules/{validationRuleId}/assignments
openapi: 3.0.1
info:
  title: Voucherify API - Validation Rules
  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:
  /v1/validation-rules/{validationRuleId}/assignments:
    parameters:
      - schema:
          $ref: '#/components/schemas/ParameterValidationRuleId'
        name: validationRuleId
        in: path
        required: true
        description: Unique validation rule ID.
    post:
      tags:
        - Validation Rules
      summary: Create Validation Rules Assignments
      description: >-
        Assign validation rule to either one of the following objects: voucher,
        campaign, promotion tier, earning rule, reward, distribution.
      operationId: create-validation-rule-assignment
      parameters:
        - schema:
            $ref: '#/components/schemas/ParameterBoolean'
          in: query
          description: >-
            If this flag is set to `true`, the previous assignment with the same
            data will be deleted and a new one will be added.
          name: force
      requestBody:
        description: >-
          Specify the resource that you would like to assign the validation rule
          to.
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ValidationRulesAssignmentsCreateRequestBody'
            examples:
              Voucher:
                value:
                  related_object_type: voucher
                  related_object_id: '{{voucherId}}'
              Campaign:
                value:
                  related_object_type: campaign
                  related_object_id: '{{campaignId}}'
              Distribution:
                value:
                  related_object_type: distribution
                  related_object_id: '{{distributionId}}'
        required: true
      responses:
        '200':
          description: Returns a validation rules assignment object.
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/ValidationRulesAssignmentsCreateResponseBody
              examples:
                Example:
                  value:
                    id: asgm_kPPiNW3smQLRMWiF
                    rule_id: val_ZEZmA9oit8aU
                    related_object_id: camp_Rv9EuIrkT08YEORb2pUMGSUo
                    related_object_type: campaign
                    created_at: '2022-09-14T07:06:49.557Z'
                    object: validation_rules_assignment
        '409':
          description: Returns an error if an duplicate assignment is found.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                Duplicate:
                  value:
                    code: 409
                    key: duplicate_found
                    message: Duplicated resource found
                    details: >-
                      Duplicated validation_rules_assignment exists with id
                      asgm_ixJEwQbUv8hfPlhO
                    request_id: v-0bb06fd1c3478dcb47
                    resource_id: asgm_ixJEwQbUv8hfPlhO
                    resource_type: validation_rules_assignment
      security:
        - X-App-Id: []
          X-App-Token: []
        - X-Voucherify-OAuth:
            - api
            - validation-rules
components:
  schemas:
    ParameterValidationRuleId:
      type: string
      example: val_TU4de3EP4dlL
    ParameterBoolean:
      type: boolean
    ValidationRulesAssignmentsCreateRequestBody:
      type: object
      description: >-
        Request body schema for **POST**
        `v1/validation-rules/{validationRuleId}/assignments`.
      title: Create Validation Rule Assignments Request Body
      properties:
        related_object_type:
          type: string
          description: Defines the related object, e.g. `voucher`.
          default: voucher
          enum:
            - voucher
            - promotion_tier
            - campaign
            - earning_rule
            - distribution
            - reward_assignment
        related_object_id:
          type: string
          description: >-
            Unique related object ID assigned by Voucherify, e.g.
            `v_lfZi4rcEGe0sN9gmnj40bzwK2FH6QUno` for a voucher.
    ValidationRulesAssignmentsCreateResponseBody:
      type: object
      title: Validation Rules Assignments Create Response Body
      description: >-
        Response body for **POST**
        `v1/validation-rules/{validationRuleId}/assignments`.
      allOf:
        - $ref: '#/components/schemas/ValidationRuleAssignment'
    Error:
      title: Error Object
      type: object
      description: Error details
      properties:
        code:
          type: integer
          description: Error's HTTP status code.
        key:
          type: string
          description: Short string describing the kind of error which occurred.
        message:
          type: string
          description: A human-readable message providing a short description of the error.
        details:
          type: string
          description: A human-readable message providing more details about the error.
        request_id:
          type: string
          example: v-0a885062c80375740f
          description: >-
            This ID is useful when troubleshooting and/or finding the root cause
            of an error response by our support team.
        resource_id:
          type: string
          description: >-
            Unique resource ID that can be used in another endpoint to get more
            details.
          example: rf_0c5d710a87c8a31f86
        resource_type:
          type: string
          description: The resource type.
          example: voucher
        error:
          type: object
          description: Includes additional information about the error.
          properties:
            message:
              type: string
              description: The message configured by the user in a validation rule.
      required:
        - code
        - message
    ValidationRuleAssignment:
      title: Validation Rule Assignment
      type: object
      description: This is an object representing a validation rule assignment.
      properties:
        id:
          type: string
          example: asgm_74F7QZoYbUoljwQO
          description: Validation rule assignment ID.
        rule_id:
          type: string
          example: val_4j7DCRm2IS59
          description: Validation rule ID.
        related_object_id:
          type: string
          example: v_JtWunK6jUo7X2qOFj0SyRHq4p9tgENlT
          description: The resource ID to which the validation rule was assigned.
        related_object_type:
          type: string
          description: The type of resource to which the validation rule was assigned.
          enum:
            - voucher
            - campaign
            - earning_rule
            - reward_assignment
            - promotion_tier
            - distribution
        created_at:
          type: string
          example: '2022-02-17T08:18:15.085Z'
          description: >-
            Timestamp representing the date and time when the validation rule
            assignment was created. The value is shown in the ISO 8601 format.
          format: date-time
        object:
          type: string
          default: validation_rules_assignment
          description: The type of the object represented by the ID.
          enum:
            - validation_rules_assignment
      required:
        - id
        - rule_id
        - related_object_id
        - related_object_type
        - created_at
        - object
  securitySchemes:
    X-App-Id:
      type: apiKey
      name: X-App-Id
      in: header
    X-App-Token:
      type: apiKey
      name: X-App-Token
      in: header
    X-Voucherify-OAuth:
      type: oauth2
      flows:
        implicit:
          authorizationUrl: https://api.voucherify.io/v1/oauth/token
          scopes:
            api: Gives access to whole server-side API.
            vouchers: >-
              Gives access to all endpoints and methods starting with
              `v1/vouchers`.
            client_api: Gives access to whole client-side API.
            client_vouchers: >-
              Gives access to all endpoints and methods starting with
              `/client/v1/vouchers`.
            promotions: >-
              Gives access to all endpoints and methods starting with
              `/v1/promotions`.
            client_promotions: >-
              Gives access to all endpoints and methods starting with
              `/client/v1/promotions`
            campaigns: >-
              Gives access to all endpoints and methods starting with
              `v1/campaigns`.
            client_publish: >-
              Gives access to all endpoints and methods starting with
              `/client/v1/publish`.
            exports: >-
              Gives access to all endpoints and methods starting with
              `/v1/exports`.
            publications: >-
              Gives access to all endpoints and methods starting with
              `/v1/publications`.
            client_validate: >-
              Gives access to all endpoints and methods starting with
              `/client/v1/validate`.
            validations: >-
              Gives access to all endpoints and methods starting with
              `/v1/validations`.
            client_validations: >-
              Gives access to all endpoints and methods starting with
              `/client/v1/validations`.
            qualifications: >-
              Gives access to all endpoints and methods starting with
              `/v1/qualifications`.
            client_qualifications: >-
              Gives access to all endpoints and methods starting with
              `/client/v1/qualifications`.
            client_redeem: >-
              Gives access to all endpoints and methods starting with
              `/client/v1/redeem
            redemptions: >-
              Gives access to all endpoints and methods starting with
              `/v1/redemptions`.
            client_redemptions: >-
              Gives access to all endpoints and methods starting with
              `/client/v1/redemptions`
            customers: >-
              Gives access to all endpoints and methods starting with
              `/v1/customers`.
            client_customers: >-
              Gives access to all endpoints and methods starting with
              `/client/v1/customers`.
            orders: >-
              Gives access to all endpoints and methods starting with
              `/v1/orders`.
            products: >-
              Gives access to all endpoints and methods starting with
              `/v1/products`.
            skus: >-
              Gives access to all endpoints and methods starting with
              `/v1/SKUs`.
            validation-rules: >-
              Gives access to all endpoints and methods starting with
              `/v1/validation-rules`.
            validation-rules-assignments: >-
              Gives access to all endpoints and methods starting with
              `/v1/validation-rules-assignments
            segments: >-
              Gives access to all endpoints and methods starting with
              `/v1/segments`.
            events: >-
              Gives access to all endpoints and methods starting with
              `/v1/events`.
            client_events: >-
              Gives access to all endpoints and methods starting with
              `client/v1/events`.
            rewards: >-
              Gives access to all endpoints and methods starting with
              `/v1/rewards`.
            assets: >-
              Gives access to all endpoints and methods starting with
              `/v1/assets`.
            task-results: >-
              Gives access to all endpoints and methods starting with
              `/v1/task-results`.
            loyalties: >-
              Gives access to all endpoints and methods starting with
              `/v1/loyalties`.
            client_consents: >-
              Gives access to all endpoints and methods starting with
              `client/v1/consents`.
            consents: >-
              Gives access to all endpoints and methods starting with
              `/v1/consents`.
            async-actions: >-
              Gives access to all endpoints and methods starting with
              `/v1/async-actions`.
            product-collections: >-
              Gives access to all endpoints and methods starting with
              `/v1/product-collections`.
            categories: >-
              Gives access to all endpoints and methods starting with
              `/v1/categories`.
            metadata-schemas: >-
              Gives access to all endpoints and methods starting with
              `/v1/metadata-schemas`.
            locations: >-
              Gives access to all endpoints and methods starting with
              `/v1/locations`.
            referrals: >-
              Gives access to all endpoints and methods starting with
              `/v1/referrals`.
            trash-bin: >-
              Gives access to all endpoints and methods starting with
              `/v1/trash-bin`.
            templates: >-
              Gives access to all endpoints and methods starting with
              `/v1/templates`.

````