# Create or alter a custom field

`PUT /custom-fields/{resource}/{name}`

> This is a subset of the full specification, limited to the `PUT /custom-fields/{resource}/{name}` operation.
>
> You can find the full specification here: /_bundle/docs/dev-docs/api/index.yaml

````yaml
openapi: 3.1.1
info:
  version: latest
  title: Core APIs
  contact:
    name: Rebilly API Support
    url: https://www.rebilly.com/contact/
    email: integrations@rebilly.com
  license:
    name: Rebilly
    url: https://www.rebilly.com/api-license/
  termsOfService: https://www.rebilly.com/terms-of-use/
  x-logo:
    url: https://rebilly-core.redoc.ly/rb_apiLogo.svg
    backgroundColor: '#0044d4'
  description: This is a subset of the full specification, limited to the `PUT /custom-fields/{resource}/{name}` operation. Components more than 3 `$ref` hops away are not included.
  x-metadata:
    description: The most common APIs used to automate common workflows.
    redocly_category: API Reference
servers:
  - url: https://api-sandbox.rebilly.com/organizations/{organizationId}
    description: Sandbox server
    variables:
      organizationId:
        default: '{organizationId}'
        description: |-
          Unique organization identifier.
          An organization is an entity that represents a company.
          For more information, see [Obtain an organization ID](https://www.rebilly.com/docs/settings/organizations-and-websites/#obtain-your-organization-id-and-website-id).
  - url: https://api.rebilly.com/organizations/{organizationId}
    description: Live server
    variables:
      organizationId:
        default: '{organizationId}'
        description: |-
          Unique organization identifier.
          An organization is an entity that represents a company.
          For more information, see [Obtain an organization ID](https://www.rebilly.com/docs/settings/organizations-and-websites/#obtain-your-organization-id-and-website-id).
security:
  - SecretApiKey: []
  - JWT: []
tags:
  - name: Custom fields
    description: |-
      Use custom fields to extend a resource scheme to include custom data that is not provided as a common field.
      Depending on the resource on which the custom field is added, it may be available in the Rebilly UI.

      Example: A custom field called `preferredCommunicationChannel` is added to the customer resource.
      It has two allowed values, which are 'email' and 'phone'.

      ```js
      {
        "customFields": {
            "preferredCommunicationChannel": "email"
        }
      }
      ```

      For detailed information on Rebilly resources, see [Resources](https://www.rebilly.com/docs/dev-docs/concepts/#resources).
x-tagGroups:
  - name: Misc
    tags:
      - Custom fields
paths:
  /custom-fields/{resource}/{name}:
    parameters:
      - $ref: '#/components/parameters/customFieldResource'
      - name: name
        in: path
        description: ID of the custom field.
        required: true
        schema:
          type: string
          maxLength: 60
          pattern: ^[\w-]+$
    put:
      x-products:
        - Core
      tags:
        - Custom fields
      summary: Create or alter a custom field
      operationId: PutCustomField
      x-sdk-operation-name: create
      description: Creates or alters a specified custom field schema for a specified resource.
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CustomField'
        description: Custom fields schema of the specified resource.
        required: true
      responses:
        '200':
          description: Custom field updated.
          headers:
            Rate-Limit-Limit:
              $ref: '#/components/headers/Rate-Limit-Limit'
            Rate-Limit-Remaining:
              $ref: '#/components/headers/Rate-Limit-Remaining'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CustomField'
        '201':
          description: Custom field created.
          headers:
            Location:
              $ref: '#/components/headers/Location'
            Rate-Limit-Limit:
              $ref: '#/components/headers/Rate-Limit-Limit'
            Rate-Limit-Remaining:
              $ref: '#/components/headers/Rate-Limit-Remaining'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CustomField'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '409':
          description: |-
            Schema in use. To remove or alter the schema, remove all
            associated data.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '422':
          $ref: '#/components/responses/ValidationError'
        '429':
          $ref: '#/components/responses/TooManyRequests'
      x-codeSamples:
        - lang: PHP
          label: PHP-SDK-2.0
          source: |
            $customFieldForm = new Rebilly\Entities\CustomField();
            $customFieldForm->setType($customFieldForm::TYPE_BOOLEAN);

            try {
                $customField = $client->customFields()->update('customers', 'testFieldName', $customFieldForm);
            } catch (Rebilly\Http\Exception\DataValidationException $e) {
                print_r($e->getValidationErrors());
            }
        - lang: JavaScript
          source: |
            // creating a custom field
            const data = {
                name: 'Date of Birth',
                type: 'date',
                description: `The customer's date of birth`
            };

            // define the entire payload
            const params = {resource: 'customers', name: 'dob', data};

            // create the custom field
            const createdField = await api.customFields.create(params);

            // or update the custom field
            const updatedField = await api.customFields.update(params);
            console.log(updatedField.fields.name);
        - lang: PHP
          source: |-
            $service = new \Rebilly\Sdk\Service($client);

            $customFieldForm = new \Rebilly\Sdk\Model\BooleanCustomField();
            $customFieldForm->setDescription('testFieldDescription');

            try {
                $customField = $service->customFields()->create('customers', 'testFieldName', $customFieldForm);
            } catch (\Rebilly\Sdk\Exception\DataValidationException $e) {
                print_r($e->getValidationErrors());
            }
components:
  securitySchemes:
    JWT:
      description: |-
        JWT is a short lifetime token that can be assigned a specific expiration time.

        Usage format: `Bearer <JWT>`.
      type: http
      scheme: bearer
      bearerFormat: JWT
    SecretApiKey:
      description: |-
        Never share your secret keys.
        Keep them guarded and secure.

        Use your secret API key only to make requests from the server side.
        To authenticate, provide your secret key in the request header.
      name: REB-APIKEY
      type: apiKey
      in: header
  parameters:
    customFieldResource:
      name: resource
      in: path
      description: Type of resource schema.
      required: true
      schema:
        type: string
        enum:
          - customers
          - payment-instruments
          - orders
          - subscriptions
          - transactions
          - websites
          - products
          - plans
          - gateway-accounts
          - deposit-requests
  headers:
    Location:
      description: Location of the related resource.
      schema:
        type: string
        format: uri
      example: https://api.rebilly.com/example
    Rate-Limit-Limit:
      description: |-
        Maximum number of requests available at one time for this rate limit.
        For more information, see [Rate limits](#section/Rate-limits).
      schema:
        type: integer
      example: 500
    Rate-Limit-Remaining:
      description: |-
        Number of requests still available for this rate limit.
        For more information, see [Rate limits](#section/Rate-limits).
      schema:
        type: integer
      example: 499
    Rate-Limit-Retry-After:
      description: Number of seconds to wait before retrying the request.
      schema:
        type: integer
      example: 1
  schemas:
    SelfLink:
      type: array
      description: Related links.
      readOnly: true
      items:
        type: object
        properties:
          href:
            description: Link URL.
            type: string
          rel:
            description: Type of link.
            type: string
            enum:
              - self
    BaseProblem:
      type: object
      additionalProperties: true
      minProperties: 1
      description: RFC-7807 [problem details](https://tools.ietf.org/html/rfc7807) JSON object.
      properties:
        type:
          type: string
          description: |-
            Problem type in the form of a [URI](https://tools.ietf.org/html/rfc3986) reference.
            It should provide human-readable documentation for the problem type.
            When this member is not present, its value is assumed to be "about:blank".
          format: uri
        title:
          type: string
          description: |-
            Short, human-readable summary of the problem type.
            Other than for the purposes of localization, this should not change from occurrence to occurrence of the problem.
        detail:
          type: string
          description: Human-readable explanation that is specific to this occurrence of the problem.
        instance:
          type: string
          description: |-
            URI reference that identifies the specific occurrence of the problem.
            It may or may not yield further information if dereferenced.
    Unauthorized:
      allOf:
        - title: Unauthorized
        - type: object
          properties:
            status:
              type: integer
              description: HTTP status code.
              minimum: 401
              maximum: 401
        - $ref: '#/components/schemas/BaseProblem'
    InvalidFields:
      type: array
      description: Invalid field details.
      items:
        type: object
        properties:
          field:
            type: string
            description: |-
              Name of the field.
              Dot notation is used for nested object field names.
          message:
            description: Message field.
            type: string
      example:
        - field: field1
          message: field1 is invalid
        - field: subObject.field2
          message: field2 is invalid
        - field: subObject.field2
          message: another error in the field2
    ValidationError:
      allOf:
        - title: Validation error
        - type: object
          properties:
            status:
              type: integer
              description: HTTP status code.
              minimum: 422
              maximum: 422
        - $ref: '#/components/schemas/BaseProblem'
        - type: object
          properties:
            invalidFields:
              $ref: '#/components/schemas/InvalidFields'
    TooManyRequests:
      type: object
      additionalProperties: true
      minProperties: 1
      description: RFC-7807 [problem details](https://tools.ietf.org/html/rfc7807) JSON object.
      properties:
        type:
          type: string
          description: |-
            Problem type in the form of a [URI](https://tools.ietf.org/html/rfc3986) reference.
            It should provide human-readable documentation for the problem type.
            When this member is not present, its value is assumed to be "about:blank".
          format: uri
          example: about:blank
        title:
          type: string
          description: |-
            Short, human-readable summary of the problem type.
            Other than for the purposes of localization, this should not change from occurrence to occurrence of the problem.
          example: Rate Limit Exceeded
        status:
          type: integer
          description: HTTP status code.
          minimum: 429
          maximum: 429
        detail:
          type: string
          description: Human-readable explanation that is specific to this occurrence of the problem.
          example: A request cannot be executed because the user has sent too many requests within a certain period of time
        instance:
          type: string
          description: |-
            URI reference that identifies the specific occurrence of the problem.
            It may or may not yield further information if dereferenced.
    CurrencyCode:
      type: string
      description: Currency code in ISO 4217 format.
      minLength: 3
      maxLength: 3
      example: USD
      x-label: Currency
    ArrayCustomField:
      type: object
      required:
        - type
      properties:
        name:
          description: Name of the custom field.
          type: string
          readOnly: true
        type:
          description: |-
            Describes the data type.
            The custom field type value cannot be changed.

            Array of strings with up to 255 characters.
            The maximum size is 1000 elements.
          type: string
          enum:
            - array
        description:
          description: Description of the custom field.
          type:
            - string
            - 'null'
        isEnabled:
          description: Specifies if the custom field is enabled.
          type: boolean
          default: true
        additionalSchema:
          type:
            - object
            - 'null'
          description: Additional schema which adds additional values constrains.
          properties:
            allowedValues:
              description: List of allowed values.
              type: array
              items:
                type: string
            required:
              description: |-
                Specifies if this value is required.
                This value can be combined with any parameter and is available for custom fields of any type.
              type: boolean
            default:
              description: Default value.
              type: array
              items:
                type: string
        _links:
          $ref: '#/components/schemas/SelfLink'
    BooleanCustomField:
      type: object
      required:
        - type
      properties:
        name:
          description: Name of the custom field.
          type: string
          readOnly: true
        type:
          description: |-
            Describes the data type.
            The custom field type value cannot be changed.

            Specifies a `true` or `false` value.
          type: string
          enum:
            - boolean
        description:
          description: Description of the custom field.
          type:
            - string
            - 'null'
        isEnabled:
          description: Specifies if custom field is enabled.
          type: boolean
          default: true
        additionalSchema:
          type:
            - object
            - 'null'
          description: Additional schema which adds additional values constrains.
          properties:
            required:
              description: Specifies if this value is required.
              type: boolean
            default:
              description: Default value.
              type: boolean
        _links:
          $ref: '#/components/schemas/SelfLink'
    DateCustomField:
      type: object
      required:
        - type
      properties:
        name:
          description: Name of the custom field.
          type: string
          readOnly: true
        type:
          description: |-
            Describes the data type.
            The custom field type value cannot be changed.

            String in [full-date](https://www.rfc-editor.org/rfc/rfc3339) format (YYYY-MM-DD).
          type: string
          enum:
            - date
        description:
          description: Description of the custom field.
          type:
            - string
            - 'null'
        isEnabled:
          description: Specifies if custom field is enabled.
          type: boolean
          default: true
        additionalSchema:
          type:
            - object
            - 'null'
          description: Additional schema which adds additional values constrains.
          properties:
            required:
              description: Specifies if this value is required.
              type: boolean
            default:
              description: Default value.
              type: string
              format: date
        _links:
          $ref: '#/components/schemas/SelfLink'
    DateTimeCustomField:
      type: object
      required:
        - type
      properties:
        name:
          description: Name of the custom field.
          type: string
          readOnly: true
        type:
          description: |-
            Describes the data type.
            The custom field type value cannot be changed.

            String in [date-time](https://www.rfc-editor.org/rfc/rfc3339) format (YYYY-MM-DDTHH:MM:SSZ).
          type: string
          enum:
            - datetime
        description:
          description: Description of the custom field.
          type:
            - string
            - 'null'
        isEnabled:
          description: Specifies if custom field is enabled.
          type: boolean
          default: true
        additionalSchema:
          type:
            - object
            - 'null'
          description: Additional schema which adds additional values constrains.
          properties:
            required:
              description: Specifies if this value is required.
              type: boolean
            default:
              description: Default value.
              type: string
              format: date-time
        _links:
          $ref: '#/components/schemas/SelfLink'
    IntegerCustomField:
      type: object
      required:
        - type
      properties:
        name:
          description: Name of the custom field.
          type: string
          readOnly: true
        type:
          description: |-
            Describes the data type.
            The custom field type value cannot be changed.

            Cardinal value of between `-2^31` and `2^31-1`.
          type: string
          enum:
            - integer
        description:
          description: Description of the custom field.
          type:
            - string
            - 'null'
        isEnabled:
          description: Specifies if custom field is enabled.
          type: boolean
          default: true
        additionalSchema:
          type:
            - object
            - 'null'
          description: Additional schema which adds additional values constrains.
          properties:
            minimum:
              description: |-
                Minimum allowed integer.
                This value can be combined with the `maximum` parameter.
              type: integer
            maximum:
              description: |-
                Maximum allowed integer.
                This value can be combined with the `minimum` parameter.
              type: integer
            required:
              description: Specifies if this value is required.
              type: boolean
            default:
              description: Default value.
              type: integer
        _links:
          $ref: '#/components/schemas/SelfLink'
    NumberCustomField:
      type: object
      required:
        - type
      properties:
        name:
          description: Name of the custom field.
          type: string
          readOnly: true
        type:
          description: |-
            Describes the data type.
            The custom field type value cannot be changed.

            Float value. This field also accepts cardinal values which are interpreted as float.
          type: string
          enum:
            - number
        description:
          description: Description of the custom field.
          type:
            - string
            - 'null'
        isEnabled:
          description: Specifies if custom field is enabled.
          type: boolean
          default: true
        additionalSchema:
          type:
            - object
            - 'null'
          description: Additional schema which adds additional values constrains.
          properties:
            minimum:
              description: |-
                Minimum allowed number.
                This value can be combined with the `maximum` parameter.
              type: number
              format: double
            maximum:
              description: |-
                Maximum allowed number.
                This value can be combined with the `minimum` parameter.
              type: number
              format: double
            required:
              description: Specifies if this value is required.
              type: boolean
            default:
              description: Default value.
              type: number
              format: double
        _links:
          $ref: '#/components/schemas/SelfLink'
    StringCustomField:
      type: object
      required:
        - type
      properties:
        name:
          description: Name of the custom field.
          type: string
          readOnly: true
        type:
          description: |-
            Describes the data type.
            The custom field type cannot be changed.

            Regular string of up to 255 characters.
          type: string
          enum:
            - string
        description:
          description: Description of the custom field.
          type:
            - string
            - 'null'
        isEnabled:
          description: Specifies if custom field is enabled.
          type: boolean
          default: true
        additionalSchema:
          type:
            - object
            - 'null'
          description: Additional schema which adds additional values constrains.
          properties:
            allowedValues:
              description: List of allowed values.
              type: array
              items:
                type: string
            maxLength:
              description: |-
                Maximum allowed string length .
                A maximum length of 4000 characters can be configured.
                By default, this value is set to 255.
              type: integer
            pattern:
              description: Allowed regular expression of a string.
              type: string
              example: /^[0-9]+$/
            required:
              description: Specifies if this value is required.
              type: boolean
            default:
              description: Default value.
              type: string
        _links:
          $ref: '#/components/schemas/SelfLink'
    MonetaryCustomField:
      type: object
      required:
        - type
      properties:
        name:
          description: Name of the custom field.
          type: string
          readOnly: true
        type:
          description: |-
            Describes the data type.
            The custom field type cannot be changed.

            A map of 3-letter currency, code, and amount.
            Example: `{"currency": "EUR", "amount": 25.30}`.
          type: string
          enum:
            - monetary
        description:
          description: Description of the custom field.
          type:
            - string
            - 'null'
        isEnabled:
          description: Specifies if custom field is enabled.
          type: boolean
          default: true
        additionalSchema:
          type:
            - object
            - 'null'
          description: Additional schema which adds additional values constrains.
          properties:
            required:
              description: Specifies if this value is required.
              type: boolean
            default:
              description: Default value.
              type: object
              properties:
                currency:
                  $ref: '#/components/schemas/CurrencyCode'
                amount:
                  type: number
                  format: double
        _links:
          $ref: '#/components/schemas/SelfLink'
    CustomField:
      description: Separate custom field schema.
      type: object
      discriminator:
        propertyName: type
        mapping:
          array: '#/components/schemas/ArrayCustomField'
          boolean: '#/components/schemas/BooleanCustomField'
          date: '#/components/schemas/DateCustomField'
          datetime: '#/components/schemas/DateTimeCustomField'
          integer: '#/components/schemas/IntegerCustomField'
          number: '#/components/schemas/NumberCustomField'
          string: '#/components/schemas/StringCustomField'
          monetary: '#/components/schemas/MonetaryCustomField'
      oneOf:
        - $ref: '#/components/schemas/ArrayCustomField'
        - $ref: '#/components/schemas/BooleanCustomField'
        - $ref: '#/components/schemas/DateCustomField'
        - $ref: '#/components/schemas/DateTimeCustomField'
        - $ref: '#/components/schemas/IntegerCustomField'
        - $ref: '#/components/schemas/NumberCustomField'
        - $ref: '#/components/schemas/StringCustomField'
        - $ref: '#/components/schemas/MonetaryCustomField'
    DocumentedProblem:
      type: object
      allOf:
        - properties:
            type:
              type: string
              description: |-
                URI reference [[RFC3986](https://tools.ietf.org/html/rfc3986)] that identifies the problem type.
                It should provide human-readable documentation for the problem type.
                When this member is not present, its value is assumed to be "about:blank".
              format: uri
              example: https://www.rebilly.com/docs/
        - $ref: '#/components/schemas/BlankProblem'
    DetailedProblem:
      type: object
      allOf:
        - $ref: '#/components/schemas/BlankProblem'
        - properties:
            detail:
              type: string
              description: Human-readable explanation specific to this occurrence of the problem.
    Problem:
      type: object
      allOf:
        - $ref: '#/components/schemas/DocumentedProblem'
        - $ref: '#/components/schemas/DetailedProblem'
    Error:
      type: object
      allOf:
        - $ref: '#/components/schemas/Problem'
        - properties:
            error:
              deprecated: true
              type: string
  responses:
    Unauthorized:
      description: |-
        Unauthorized access.
        Invalid credentials used.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Unauthorized'
    ValidationError:
      description: Invalid data sent.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ValidationError'
    TooManyRequests:
      description: Request rate limit exceeded.
      headers:
        Rate-Limit-Limit:
          $ref: '#/components/headers/Rate-Limit-Limit'
        Rate-Limit-Remaining:
          description: |-
            Number of requests still available for this rate limit.
            For more information, see [Rate limits](#section/Rate-limits).
          schema:
            type: integer
          example: 0
        Rate-Limit-Retry-After:
          $ref: '#/components/headers/Rate-Limit-Retry-After'
        Retry-After:
          description: Number of seconds to wait before retrying the request.
          schema:
            type: integer
          example: 1
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/TooManyRequests'
````
