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

# Create custom field

> Creates a custom field that no module of Aira owns, so each record of the `entity` takes a value of it in its `customFields`, and the list of custom fields shows it. The billing app shows it after the other custom fields of the `entity`, with a toggle for a `boolean`, a select for a custom field with `options` or a `dataSource`, a text area for a `multiline` one, and a text input for the others.

Requires the role `custom_fields:write`.



## OpenAPI

````yaml /api-reference/openapi.yaml post /v1/custom-fields/
openapi: 3.1.0
info:
  title: API Reference
  version: '1.0'
  description: Aira API Reference
  x-logo:
    url: https://static.useaira.com/images/airalogo.svg
    backgroundColor: '#FFFFFF'
    altText: Aira Logo
servers:
  - url: https://api.useaira.com
    description: API base URL
security:
  - ApiKey: []
paths:
  /v1/custom-fields/:
    post:
      tags:
        - Custom Fields
      summary: Create custom field
      description: >-
        Creates a custom field that no module of Aira owns, so each record of
        the `entity` takes a value of it in its `customFields`, and the list of
        custom fields shows it. The billing app shows it after the other custom
        fields of the `entity`, with a toggle for a `boolean`, a select for a
        custom field with `options` or a `dataSource`, a text area for a
        `multiline` one, and a text input for the others.


        Requires the role `custom_fields:write`.
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                entity:
                  type: string
                  enum:
                    - contract
                    - product
                    - item
                    - customer
                    - importable_template
                    - legal_entity
                    - revenue_traceability
                    - revenue_attribution
                    - invoice_discount
                    - invoice
                    - plan_instance_version
                  description: >-
                    The kind of record that the custom field belongs to, such as
                    `customer` or `contract`.
                fieldKey:
                  type: string
                  description: >-
                    The key, in camelCase, under which each record of the
                    `entity` holds the value of the custom field in its
                    `customFields`. No other custom field of the same `entity`
                    has it.
                  pattern: ^[a-z][a-zA-Z0-9]*$
                  errorMessage:
                    pattern: fieldKey must be in camelCase format
                  example: canalDeVenda
                dataType:
                  type: string
                  enum:
                    - string
                    - string_array
                    - boolean
                  description: >-
                    The type of the value of the custom field: `string` holds
                    one text, `string_array` holds a list of texts, and
                    `boolean` holds the text `true` or `false`.
                label:
                  type: string
                  minLength: 1
                  description: The name of the custom field that the billing app shows.
                  example: Canal de venda
                description:
                  type:
                    - 'null'
                    - string
                  description: >-
                    The help text that the billing app shows with the input of
                    the custom field, or null for none.
                  example: Canal pelo qual o cliente compra.
                required:
                  type: boolean
                  description: >-
                    Whether each record of the `entity` must hold a value of the
                    custom field.
                  default: false
                defaultValue:
                  type:
                    - 'null'
                    - string
                  description: >-
                    The value that the billing app fills in on a new record, or
                    null for none.
                  example: varejo
                options:
                  type:
                    - 'null'
                    - array
                  items:
                    type: object
                    description: A value that a record can hold in the custom field.
                    properties:
                      label:
                        type: string
                        minLength: 1
                        description: The text that the billing app shows for the option.
                        examples:
                          - Varejo
                      value:
                        type: string
                        minLength: 1
                        description: >-
                          The value that a record holds in its `customFields`
                          when a user picks the option.
                        examples:
                          - varejo
                    required:
                      - label
                      - value
                    additionalProperties: false
                  description: >-
                    The values that a record can hold in the custom field, in
                    the order that the billing app shows them, or null when the
                    custom field takes any value.
                  minItems: 1
                dataSource:
                  type:
                    - 'null'
                    - string
                  enum:
                    - customers
                    - omie_categories
                    - omie_bank_accounts
                    - null
                  description: >-
                    The records whose ids a record holds in the custom field, in
                    place of `options`: `customers` for the customers, and
                    `omie_categories` or `omie_bank_accounts` for the categories
                    or the bank accounts of Omie. Null when the custom field
                    takes no records.
                multiline:
                  type: boolean
                  description: >-
                    Whether the billing app shows the input of the custom field
                    as a text area of several lines, in place of a text input of
                    one line. Only a custom field of `string` with no `options`
                    and no `dataSource` is multiline.
                  default: false
              required:
                - entity
                - fieldKey
                - dataType
                - label
              additionalProperties: false
        required: true
        description: The custom field to create.
      responses:
        '201':
          description: >-
            A custom field: a field that you add to one kind of record, such as
            customers or contracts, whose value users fill in on each record.
            Each record of that kind holds the value in its `customFields`,
            under the `fieldKey`.
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    format: uuid
                    description: The unique identifier of the custom field.
                  entity:
                    type: string
                    enum:
                      - contract
                      - product
                      - item
                      - customer
                      - importable_template
                      - legal_entity
                      - revenue_traceability
                      - revenue_attribution
                      - invoice_discount
                      - invoice
                      - plan_instance_version
                    description: >-
                      The kind of record that the custom field belongs to, such
                      as `customer` or `contract`.
                  fieldKey:
                    type: string
                    description: >-
                      The key under which each record of the `entity` holds the
                      value of the custom field in its `customFields`. No other
                      custom field of the same `entity` has it.
                    example: canalDeVenda
                  dataType:
                    type: string
                    enum:
                      - string
                      - string_array
                      - boolean
                    description: >-
                      The type of the value of the custom field: `string` holds
                      one text, `string_array` holds a list of texts, and
                      `boolean` holds the text `true` or `false`.
                  label:
                    type: string
                    minLength: 1
                    description: The name of the custom field that the billing app shows.
                    example: Canal de venda
                  description:
                    type:
                      - 'null'
                      - string
                    description: >-
                      The help text that the billing app shows with the input of
                      the custom field, or null for none.
                    example: Canal pelo qual o cliente compra.
                  required:
                    type: boolean
                    description: >-
                      Whether each record of the `entity` must hold a value of
                      the custom field.
                  defaultValue:
                    type:
                      - 'null'
                      - string
                    description: >-
                      The value that the billing app fills in on a new record,
                      or null for none.
                    example: varejo
                  options:
                    type:
                      - 'null'
                      - array
                    items:
                      type: object
                      description: A value that a record can hold in the custom field.
                      properties:
                        label:
                          type: string
                          minLength: 1
                          description: The text that the billing app shows for the option.
                          examples:
                            - Varejo
                        value:
                          type: string
                          minLength: 1
                          description: >-
                            The value that a record holds in its `customFields`
                            when a user picks the option.
                          examples:
                            - varejo
                      required:
                        - label
                        - value
                      additionalProperties: false
                    description: >-
                      The values that a record can hold in the custom field, in
                      the order that the billing app shows them, or null when
                      the custom field takes any value.
                  dataSource:
                    type:
                      - 'null'
                      - string
                    enum:
                      - customers
                      - omie_categories
                      - omie_bank_accounts
                      - null
                    description: >-
                      The records whose ids a record holds in the custom field,
                      in place of `options`: `customers` for the customers, and
                      `omie_categories` or `omie_bank_accounts` for the
                      categories or the bank accounts of Omie. Null when the
                      custom field takes no records.
                  multiline:
                    type: boolean
                    description: >-
                      Whether the billing app shows the input of the custom
                      field as a text area of several lines, in place of a text
                      input of one line. Only a custom field of `string` with no
                      `options` and no `dataSource` is multiline.
                  module:
                    type:
                      - 'null'
                      - string
                    enum:
                      - omie
                      - senior
                      - celcash
                      - asaas
                      - enotas
                      - hubspot
                      - contaazul
                      - null
                    description: >-
                      The module of Aira that owns the custom field, such as the
                      integration `omie`, which reads its value by the
                      `fieldKey`, or null when no module owns it. You cannot
                      update or delete a custom field that a module owns.
                required:
                  - id
                  - entity
                  - fieldKey
                  - dataType
                  - label
                  - description
                  - required
                  - defaultValue
                  - options
                  - dataSource
                  - multiline
                  - module
                additionalProperties: false
        '400':
          description: >-
            The request cannot succeed as sent.


            - `json_schema_validation_error`: the body breaks the schema of the
            endpoint.

            - `invalid_custom_fields`: the body has both `options` and a
            `dataSource`, gives a custom field of `boolean` options, a
            `dataSource` or a `defaultValue` other than `true` and `false`,
            makes `multiline` a custom field that is not a `string` with no
            `options` and no `dataSource`, names `omie_categories` or
            `omie_bank_accounts` as the `dataSource` while the integration of
            Omie is not enabled, or has an option with the value
            `__aira_empty__`, which Aira keeps for the filter of the records
            without a value.

            - `custom_field_already_exists`: another custom field of the
            `entity` has the `fieldKey`.
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    description: >-
                      A sentence for a person that says what failed. It can
                      change, so a system compares the code instead.
                  code:
                    type: string
                    description: >-
                      The identifier of the error, which a system compares to
                      decide what to do. It never changes.
                    enum:
                      - json_schema_validation_error
                      - invalid_custom_fields
                      - custom_field_already_exists
                  details:
                    oneOf:
                      - type: object
                        additionalProperties: true
                      - type: array
                    description: >-
                      The data of the error, when it has any, such as the fields
                      that failed the validation.
                  causations:
                    type: array
                    description: >-
                      The errors that caused this one, when several did, each
                      with its own message, code and details.
                    items:
                      type: object
                      properties:
                        message:
                          type: string
                          description: A sentence for a person that says what failed.
                        code:
                          type: string
                          description: The identifier of the error.
                        details:
                          type: object
                          additionalProperties: true
                          description: The data of the error, when it has any.
                      required:
                        - message
                        - code
                      additionalProperties: false
                required:
                  - message
                  - code
                additionalProperties: false
              examples:
                json_schema_validation_error:
                  value:
                    message: '''entity'' is required'
                    code: json_schema_validation_error
                invalid_custom_fields:
                  value:
                    message: 'Unknown custom field(s) for {entity}: {value}'
                    code: invalid_custom_fields
                custom_field_already_exists:
                  value:
                    message: >-
                      custom field with fieldKey "{fieldKey}" already exists for
                      entity "{entity}"
                    code: custom_field_already_exists
        '401':
          description: >-
            The request carries no API key.


            - `no_authorization`: the request carries no API key in the
            `X-API-KEY` header.
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    description: >-
                      A sentence for a person that says what failed. It can
                      change, so a system compares the code instead.
                  code:
                    type: string
                    description: >-
                      The identifier of the error, which a system compares to
                      decide what to do. It never changes.
                    enum:
                      - no_authorization
                  details:
                    oneOf:
                      - type: object
                        additionalProperties: true
                      - type: array
                    description: >-
                      The data of the error, when it has any, such as the fields
                      that failed the validation.
                  causations:
                    type: array
                    description: >-
                      The errors that caused this one, when several did, each
                      with its own message, code and details.
                    items:
                      type: object
                      properties:
                        message:
                          type: string
                          description: A sentence for a person that says what failed.
                        code:
                          type: string
                          description: The identifier of the error.
                        details:
                          type: object
                          additionalProperties: true
                          description: The data of the error, when it has any.
                      required:
                        - message
                        - code
                      additionalProperties: false
                required:
                  - message
                  - code
                additionalProperties: false
              examples:
                no_authorization:
                  value:
                    message: No authorization provided
                    code: no_authorization
        '403':
          description: >-
            The API key cannot call the endpoint.


            - `bad_auth`: the API key does not hold the role that the endpoint
            requires.

            - `invalid_api_key`: the API key does not exist.

            - `deactivated_api_key`: the API key is deactivated.

            - `revoked_api_key`: the API key is revoked.

            - `expired_api_key`: the API key is past its expiry date.

            - `ip_not_allowed`: the IP of the request is not among the IPs that
            your API keys accept.
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    description: >-
                      A sentence for a person that says what failed. It can
                      change, so a system compares the code instead.
                  code:
                    type: string
                    description: >-
                      The identifier of the error, which a system compares to
                      decide what to do. It never changes.
                    enum:
                      - bad_auth
                      - invalid_api_key
                      - deactivated_api_key
                      - revoked_api_key
                      - expired_api_key
                      - ip_not_allowed
                  details:
                    oneOf:
                      - type: object
                        additionalProperties: true
                      - type: array
                    description: >-
                      The data of the error, when it has any, such as the fields
                      that failed the validation.
                  causations:
                    type: array
                    description: >-
                      The errors that caused this one, when several did, each
                      with its own message, code and details.
                    items:
                      type: object
                      properties:
                        message:
                          type: string
                          description: A sentence for a person that says what failed.
                        code:
                          type: string
                          description: The identifier of the error.
                        details:
                          type: object
                          additionalProperties: true
                          description: The data of the error, when it has any.
                      required:
                        - message
                        - code
                      additionalProperties: false
                required:
                  - message
                  - code
                additionalProperties: false
              examples:
                bad_auth:
                  value:
                    message: role custom_fields:write can not be satisfied
                    code: bad_auth
                invalid_api_key:
                  value:
                    message: Invalid API key
                    code: invalid_api_key
                deactivated_api_key:
                  value:
                    message: Deactivated API key
                    code: deactivated_api_key
                revoked_api_key:
                  value:
                    message: Revoked API key
                    code: revoked_api_key
                expired_api_key:
                  value:
                    message: Expired API key
                    code: expired_api_key
                ip_not_allowed:
                  value:
                    message: IP not allowed
                    code: ip_not_allowed
components:
  securitySchemes:
    ApiKey:
      type: apiKey
      description: API Key Authentication.
      name: X-API-KEY
      in: header

````

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