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

# Update Metadata Schema

> Updates a metadata schema.

With this request, you can:
- Add a nonexistent attribute definition to the metadata schema.
- Update an existing attribute definition by overwriting its current values.

In the request, you can provide only those definitions you want to add or update. Definitions omitted in the request remain unchanged.

However, if you want to update a definition, you will have to add all its current key-value pairs as well. Only the pairs sent in the request are saved for this definition. This means that the key-value pairs that are not sent in a request are restored to default values. For example, if your definition has an array with values and it is not sent in an update request, the array values will be deleted.

> 👍 Additional Notes
>
>- You cannot change the type of an existing schema, e.g. from `"string"` to `"number"`.
>
>- You can remove a definition with this endpoint by providing `"deleted": true` in the request. It will be moved to the Removed definitions section in the user interface. However, you cannot permanently remove a definition with this endpoint.

> 📘 Metadata Documentation
>
> Read [the Getting Started with Metadata](/prepare/metadata) and [Metadata Mapping](/guides/metadata-mapping) articles to learn how metadata work in Voucherify.



## OpenAPI

````yaml /openapi/management.json put /management/v1/projects/{projectId}/metadata-schemas/{metadataSchemaId}
openapi: 3.0.1
info:
  title: Voucherify API - Management
  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:
  /management/v1/projects/{projectId}/metadata-schemas/{metadataSchemaId}:
    parameters:
      - schema:
          $ref: '#/components/schemas/ParameterProjectId'
        in: path
        name: projectId
        description: Provide the unique identifier of the project.
        required: true
      - schema:
          $ref: '#/components/schemas/ParameterMetadataSchemaId'
        in: path
        name: metadataSchemaId
        description: Provide the unique identifier of the metadata schema.
        required: true
    put:
      tags:
        - Management
      summary: Update Metadata Schema
      description: >-
        Updates a metadata schema.


        With this request, you can:

        - Add a nonexistent attribute definition to the metadata schema.

        - Update an existing attribute definition by overwriting its current
        values.


        In the request, you can provide only those definitions you want to add
        or update. Definitions omitted in the request remain unchanged.


        However, if you want to update a definition, you will have to add all
        its current key-value pairs as well. Only the pairs sent in the request
        are saved for this definition. This means that the key-value pairs that
        are not sent in a request are restored to default values. For example,
        if your definition has an array with values and it is not sent in an
        update request, the array values will be deleted.


        > 👍 Additional Notes

        >

        >- You cannot change the type of an existing schema, e.g. from
        `"string"` to `"number"`.

        >

        >- You can remove a definition with this endpoint by providing
        `"deleted": true` in the request. It will be moved to the Removed
        definitions section in the user interface. However, you cannot
        permanently remove a definition with this endpoint.


        > 📘 Metadata Documentation

        >

        > Read [the Getting Started with Metadata](/prepare/metadata) and
        [Metadata Mapping](/guides/metadata-mapping) articles to learn how
        metadata work in Voucherify.
      operationId: update-metadata-schema
      parameters: []
      requestBody:
        description: Defines the metadata schema to be updated.
        content:
          application/json:
            schema:
              $ref: >-
                #/components/schemas/ManagementProjectsMetadataSchemasUpdateRequestBody
        required: true
      responses:
        '200':
          description: Returns the details about the updated metadata schema.
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/ManagementProjectsMetadataSchemasUpdateResponseBody
              examples:
                Example:
                  value:
                    id: ms_u3bIQLbdU0fi3rhqpTLiF26T
                    related_object: reward
                    properties:
                      region:
                        type: string
                        array: true
                        optional: false
                        object_type: null
                        eq:
                          - EMEA
                          - APAC
                          - LATAM
                          - NA
                    allow_defined_only: null
                    created_at: '2024-04-29T12:03:55.991Z'
                    updated_at: null
                    object: metadata_schema
        '400':
          description: Returns an error if the payload includes incorrect details.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/e_400_invalid_payload'
              examples:
                Invalid payload:
                  value:
                    code: 400
                    key: invalid_payload
                    message: Invalid payload
                    details: Property .properties.Size.eq.0 must be number
                    request_id: v-0ea5a9b9b3402940a9
        '401':
          description: Returns an error if an invalid token was provided.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                Unauthorized:
                  value:
                    code: 401
                    message: Unauthorized
                    key: unauthorized
        '402':
          description: >-
            Returns an error if the current plan does not include the Management
            API feature.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorPaymentRequired'
              examples:
                Example:
                  value:
                    code: 402
                    message: Payment required
                    details: >-
                      Your current plan does not include a feature required to
                      perform this operation.
                    key: missing_required_feature
        '404':
          description: Returns an error when a resource could not be found.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                Not Found:
                  value:
                    code: 404
                    message: Resource not found
                    details: Cannot find project with id proj_2F3txY7
      security:
        - X-Management-Id: []
          X-Management-Token: []
components:
  schemas:
    ParameterProjectId:
      type: string
      example: proj_TrlkLiH4
    ParameterMetadataSchemaId:
      type: string
      example: ms_f0r4hm3ta6a4a5ch3ma
    ManagementProjectsMetadataSchemasUpdateRequestBody:
      type: object
      description: ''
      properties:
        allow_defined_only:
          type: boolean
          description: "Restricts the creation of metadata fields when set to `true`. In other words, it indicates whether or not you are allowed to create new metadata definitions; for example, in the campaign manager or publication manager. If it is set to true, then only the defined fields will be available for assigning values.\t"
        properties:
          type: object
          description: >-
            Contains metadata definitions. There can be many properties within
            this object.


            Only the properties sent in the request will be updated. However, if
            you send a property, all its key-value pairs must be provided -
            otherwise, they will be overwritten to new values.


            You cannot change the `"type"` property. However, it is required, so
            you need to add it to the request.
          additionalProperties:
            $ref: '#/components/schemas/ManagementProjectsMetadataSchemaDefinition'
      required:
        - properties
    ManagementProjectsMetadataSchemasUpdateResponseBody:
      type: object
      title: Management Projects Metadata Schemas Update Response Body
      description: >-
        Response body schema for **PUT**
        `management/v1/projects/{projectId}/metadata-schemas/{metadataSchemaId}`.
      allOf:
        - $ref: '#/components/schemas/ManagementProjectsMetadataSchema'
    e_400_invalid_payload:
      title: Invalid Payload
      type: object
      description: 'Error: Bad Request &rarr; Invalid Payload'
      properties:
        code:
          type: integer
          default: 400
          description: Error's HTTP status code.
        key:
          type: string
          default: invalid_payload
          description: Short string describing the kind of error which occurred.
        message:
          type: string
          default: Invalid payload
          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-0a884c6be8c3756f42
          description: >-
            This ID is useful when troubleshooting and/or finding the root cause
            of an error response by our support team.
    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
    ErrorPaymentRequired:
      title: Payment Required Error
      type: object
      description: 'Error: Payment required - the current plan does not include the feature.'
      properties:
        code:
          type: integer
          description: Error's HTTP status code.
        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.
        key:
          type: string
          description: Short string describing the kind of error which occurred.
      required:
        - code
        - message
        - details
        - key
    ManagementProjectsMetadataSchemaDefinition:
      type: object
      title: Metadata Definitions
      description: >-
        Custom definition name. This is also shown in **Project Settings** >
        **Metadata Schema** in the Voucherify Dashboard.
      properties:
        type:
          type: string
          description: >-
            Indicates the type of metadata. Note that `"geopoint"` type is a
            paid feature.
          enum:
            - string
            - number
            - object
            - date
            - datetime
            - geopoint
            - boolean
            - image_url
        optional:
          type: boolean
          description: Indicates if this definition is optional or not for the resource.
        array:
          type: boolean
          description: Indicates if the definition is an array.
        deleted:
          type: boolean
          description: Indicates if the definition has been deleted from the schema.
        object_type:
          type: string
          nullable: true
          description: >-
            The name of the custom resource (i.e. a nested object) if the
            resource has been previously defined. Otherwise, it is `null` for
            other types.
        min_length:
          type: integer
          description: >-
            Value indicating the minimum length. Available only for the `string`
            type.
        max_length:
          type: integer
          description: >-
            Value indicating the maximum length. Available only for the `string`
            type.
        exact_length:
          type: integer
          description: >-
            Value indicating the exact length. Available only for the `string`
            type.
        eq:
          type: array
          description: >-
            Array of values that are allowed. Available only for the `string`
            and `number` types.
          items:
            oneOf:
              - title: Add number
                description: >-
                  Adds numbers to the array. The value should be up to two
                  decimal places.
                type: number
              - title: Add string
                description: Adds strings to the array.
                type: string
        ne:
          type: array
          description: >-
            Array of values that are not allowed. Available only for the
            `number` type.
          items:
            description: >-
              Adds number to the array. The value should be up to two decimal
              places.
            type: number
        lt:
          type: number
          description: >-
            A property of the `number` type must have `less than` this value.
            The value should be up to two decimal places.
        lte:
          type: number
          description: >-
            A property of the `number` type must be `less than or equal` to this
            value. The value should be up to two decimal places.
        gt:
          type: number
          description: >-
            A property of `number` type must be `greater than` this value. The
            value should be up to two decimal places.
        gte:
          type: number
          description: >-
            A property of `number` type must be `greater than or equal` to this
            value. The value should be up to two decimal places.
      required:
        - type
        - optional
        - array
    ManagementProjectsMetadataSchema:
      type: object
      description: Object representing a metadata schema.
      allOf:
        - type: object
          properties:
            id:
              type: string
              description: Unique identifier of the metadata schema.
            related_object:
              type: string
              description: >-
                The resource type. You can define custom metadata schemas, which
                have a custom `"related_object"` resource type. The standard
                metadata schemas are: `"campaign"`, `"customer"`,
                `"earning_rule"`, `"loyalty_tier"`, `"order"`, `"order_item"`,
                `"product"`, `"promotion_tier"`, `"publication"`,
                `"redemption"`, `"reward"`, `"voucher"`.
        - type: object
          properties:
            properties:
              type: object
              description: Contains metadata definitions.
              additionalProperties:
                $ref: >-
                  #/components/schemas/ManagementProjectsMetadataSchemaDefinition
          required:
            - properties
        - type: object
          properties:
            allow_defined_only:
              type: boolean
              nullable: true
              description: >-
                Restricts the creation of metadata fields when set to `true`. It
                indicates whether or not you can create new metadata
                definitions, e.g. in the campaign or publication manager. If set
                to `true`, then only the defined fields are available for
                assigning values.
            created_at:
              type: string
              example: '2021-12-03T13:33:44.556Z'
              description: >-
                Timestamp representing the date and time when the metadata
                schema was created. The value for this parameter is shown in the
                ISO 8601 format.
              format: date-time
            updated_at:
              type: string
              nullable: true
              example: '2022-08-11T08:05:30.695Z'
              description: >-
                Timestamp representing the date and time when the metadata
                schema was updated. The value for this parameter is shown in the
                ISO 8601 format.
              format: date-time
            object:
              type: string
              default: metadata_schema
              description: >-
                The type of the object represented by the JSON. This object
                stores information about the metadata schema.
      required:
        - id
        - related_object
        - properties
        - allow_defined_only
        - created_at
        - updated_at
        - object
  securitySchemes:
    X-Management-Id:
      type: apiKey
      name: X-Management-Id
      in: header
    X-Management-Token:
      type: apiKey
      name: X-Management-Token
      in: header

````