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

# Update data type

> Replaces the data type definition. `deleteFields` lists field ids to remove.

**Upgrading a v3-compatible type.** A save that uses a v4-only feature turns a v3-compatible type v4-only, for good. The response then carries `data_type.migration`, the Preparing run that re-sends its records for v4 search. A save that only changes column settings never upgrades; send `columnsOnly=true` with it. A save that upgrades **and** turns on `unique` or `uniqueTogether` is refused (`400`): upgrade first, wait for Preparing, then add the unique fields.

**Other v4 rules.** A Master Data extension cannot be renamed (`403`, `failedCode` `dtype-035`). `commonData` (scope by hub) changes only while the type has no records. Turning `unique` on, or adding a combination, when records already repeat a value is refused with `failedCode` `dtype-041` and a `duplicates` list; when they do not, the claims are registered in the background, during which record writes answer `409`. A save of a v3-compatible type while a file import into it runs answers `409`.

While the type is being prepared (`migration.status` is `running`), this route answers `409` with `failedCode` `dtype-036`.

Requires permission `edit/dataType`.



## OpenAPI

````yaml /openapi/public/openapi-data.json put /data-type/{dataTypeId}
openapi: 3.0.0
info:
  title: API - Data
  version: 3.0.0
  description: API Documentation - RESTful API for field operations management.
servers:
  - url: https://apiweb.mile.app/api/v3
security:
  - bearerAuth: []
tags:
  - name: Data Source
    description: >-
      The Data source could help you simplify the process of filling in task
      information based on existing data in the app. This data could consist of
      information such as name, number, date, coordinate, and multiple options.
      The Data typically represents entities such as customers, products,
      employees, suppliers, or any other critical data elements that are used
      across the application.


      **To see the details of data source object, please follow [this
      link](#tag/data_source_model)**
  - name: Data Type
    description: >-
      The Data type is the structure of data fields that is customizable to suit
      your business needs. Data type attributes consist of IDs, name, field
      details, type, and primary key. This data type structure will be used at
      Data Source and Flow.


      **To see the details of data type object, please follow [this
      link](#tag/data_type_model)**
paths:
  /data-type/{dataTypeId}:
    put:
      tags:
        - Data Type
      summary: Update data type
      description: >-
        Replaces the data type definition. `deleteFields` lists field ids to
        remove.


        **Upgrading a v3-compatible type.** A save that uses a v4-only feature
        turns a v3-compatible type v4-only, for good. The response then carries
        `data_type.migration`, the Preparing run that re-sends its records for
        v4 search. A save that only changes column settings never upgrades; send
        `columnsOnly=true` with it. A save that upgrades **and** turns on
        `unique` or `uniqueTogether` is refused (`400`): upgrade first, wait for
        Preparing, then add the unique fields.


        **Other v4 rules.** A Master Data extension cannot be renamed (`403`,
        `failedCode` `dtype-035`). `commonData` (scope by hub) changes only
        while the type has no records. Turning `unique` on, or adding a
        combination, when records already repeat a value is refused with
        `failedCode` `dtype-041` and a `duplicates` list; when they do not, the
        claims are registered in the background, during which record writes
        answer `409`. A save of a v3-compatible type while a file import into it
        runs answers `409`.


        While the type is being prepared (`migration.status` is `running`), this
        route answers `409` with `failedCode` `dtype-036`.


        Requires permission `edit/dataType`.
      operationId: putDataTypeById
      parameters:
        - name: _id
          in: path
          required: true
          description: |-
            Unique identifier for the data that generated by system.
            **Example**: `640a45dd089dc95a0a09ef14`
          schema:
            type: string
        - name: columnsOnly
          in: query
          required: false
          description: >-
            Marks a save that only changes `columnOrder`, `metaColumns` or a
            field's `show`, so it never upgrades a v3-compatible type. Ignored
            when anything else changed.
          schema:
            type: boolean
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/putRequestDataType'
        required: true
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                title: NetworkPutResponse
                properties:
                  status:
                    type: boolean
                    description: Status of response.
                  message:
                    description: Message of API response.
                    type: string
                  data_type:
                    description: Detail of object data type.
                    type: object
                    additionalProperties: true
                example:
                  status: true
                  message: Success
                  data_type:
                    _id: 640a45dd089dc95a0a09ef14
                    name: OutletDetail
                    fields:
                      - id: dataId
                        title: Data ID
                        type: string
                        default: 'true'
                        optionData: []
                        required: true
                      - id: outletName
                        title: Outlet Name
                        type: string
                        optionData: []
                        required: true
                      - id: outletHours
                        title: Outlet Hours
                        default: 12
                        type: number
                        optionData: []
                        required: true
                      - id: outletType
                        title: Outlet Type
                        type: string
                        optionData:
                          - minimarket
                          - supermarket
                          - vending machine
                          - warung
                        required: true
                      - id: outletOpen
                        title: Outlet Open
                        default: '09:00'
                        type: string
                        optionData: []
                        required: true
                      - id: outletClosed
                        title: Outlet Closed
                        default: '17:00'
                        type: string
                        optionData: []
                        required: true
                      - id: outletContractExpired
                        title: Outlet Contract Expired
                        type: string
                        optionData: []
                        required: true
                      - id: outletOpenInWeekend
                        title: Outlet Open In Weekend
                        type: string
                        optionData: []
                        required: true
                      - id: outletCoordinate
                        title: Outlet Coordinate
                        description: >-
                          Contoh inputan 
                          "-6.171702325136309,106.81775093078615"
                        type: string
                        optionData: []
                        required: true
                      - id: outletPhoneNumber
                        title: Outlet Phone Number
                        description: >-
                          Example format  "+628 456 7890 or +62 123 456 789 or
                          0123456789"
                        type: string
                        optionData: []
                        required: true
                      - id: outletCloseOrder
                        title: Outlet Close Order
                        description: >-
                          Example format  "2024-11-01 15:30:45 or
                          2024-11-01T15:30:45.123+02:00 or
                          2024-11-01T15:30:45+02:00"
                        type: string
                        format: date-time
                        optionData: []
                        required: true
                    createdBy: john.doe@example.com
                    organizationId: 63c61d865347e356d05e3052
                    updatedTime: '2023-03-09 20:47:24'
                    createdTime: '2023-03-09 20:47:24'
                    provider: internal
                    providerConfig: null
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: boolean
                    description: Shows if the request was successful.
                  message:
                    type: string
                    description: A short message explaining what went wrong.
                example:
                  status: false
                  message: Bad request - invalid parameters provided.
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: boolean
                    description: Shows if the request was successful.
                  message:
                    type: string
                    description: A short message explaining what went wrong.
                example:
                  status: false
                  message: Bad request - invalid parameters provided.
        '404':
          description: Not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: boolean
                    description: Shows if the request was successful.
                  message:
                    type: string
                    description: A short message explaining what went wrong.
                example:
                  status: false
                  message: Data not found
        '409':
          description: >-
            Conflict: the data type is being prepared or a file import into it
            is running
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: boolean
                    description: Shows if the request was successful.
                  message:
                    type: string
                    description: A short message explaining what went wrong.
                example:
                  status: false
                  message: Bad request - invalid parameters provided.
        '500':
          description: Server error
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: boolean
                    description: Shows if the request was successful.
                  message:
                    type: string
                    description: A short message explaining what went wrong.
                example:
                  status: false
                  message: Internal server error, please contact support@mile.app.
      deprecated: false
      security:
        - bearerAuth: []
      servers:
        - url: https://apiweb.mile.app/api/v4
components:
  schemas:
    putRequestDataType:
      title: putRequestDataType
      example:
        name: OutletDetail
        fields:
          - id: dataId
            title: Data ID
            type: string
            optionData: []
            required: true
            primaryKey: true
          - id: outletName
            title: Outlet Name
            type: string
            optionData: []
            required: true
          - id: outletHours
            title: Outlet Hours
            default: 12
            type: number
            optionData: []
            required: true
          - id: outletType
            title: Outlet Type
            type: string
            optionData:
              - minimarket
              - supermarket
              - vending machine
              - warung
            required: true
          - id: outletOpen
            title: Outlet Open
            default: '09:00'
            type: string
            optionData: []
            required: true
          - id: outletClosed
            title: Outlet Closed
            default: '17:00'
            type: string
            optionData: []
            required: true
          - id: outletContractExpired
            title: Outlet Contract Expired
            type: string
            optionData: []
            required: true
          - id: outletOpenInWeekend
            title: Outlet Open In Weekend
            type: boolean
            optionData: []
            required: true
          - id: outletGeolocation
            title: Outlet Geolocation
            description: Contoh inputan  "-6.171702325136309,106.81775093078615"
            type: string
            optionData: []
            required: true
          - id: outletPhoneNumber
            title: Outlet Phone Number
            description: Example format  "+628 456 7890 or +62 123 456 789 or 0123456789"
            type: string
            optionData: []
            required: true
          - id: outletCloseOrder
            title: Outlet Close Order
            description: >-
              Example format  "2024-11-01 15:30:45 or
              2024-11-01T15:30:45.123+02:00 or 2024-11-01T15:30:45+02:00"
            type: string
            format: date-time
            optionData: []
            required: true
      type: object
      properties:
        name:
          type: string
          description: |-
            Name of data type.
            **Example**: `OutletDetail`
        fields:
          type: array
          description: |-
            List of fields to data type .
            **Example**: 
             `{` 
             `'id': 'dataId',` 
             `'title': 'Data ID',` 
             `'type': 'text',` 
             `'optionData': [],` 
             `'required': true,` 
             `'primaryKey': true` 
             `}`
          items:
            type: object
            required:
              - id
              - title
              - type
              - required
              - show
            properties:
              id:
                type: string
                description: >-
                  Field key, letters, digits, `-` and `_`. Unique within the
                  data type.

                  **Example:** `outletName`
              title:
                type: string
                description: |-
                  Field label.
                  **Example:** `Outlet Name`
              description:
                type: string
              inputType:
                type: string
                description: >-
                  The input type of the component (e.g., string, number, date,
                  etc.)
              isRequired:
                type: boolean
                description: Whether a record must hold a value.
              show:
                type: boolean
                description: Whether the field is shown in the Data Source table.
              unique:
                type: boolean
                description: >-
                  No two records of one hub may hold the same value. Turning it
                  on when records already repeat a value is refused with `400`,
                  `failedCode` `dtype-041`, and a `duplicates` list.
              default:
                description: Default value for a new record.
              optionData:
                type: array
                items:
                  type: object
                  additionalProperties: true
                description: |-
                  Required for `option` and `multiOption`: the choices.
                  **Example:** `[{"value":"retail","label":"Retail"}]`
              validations:
                type: object
                description: >-
                  v4 field rules. `min` and `max` are a literal value, or
                  `{"ref":"fieldId"}` pointing at a sibling field of the same
                  date, date and time, or time type. A literal `min` above a
                  literal `max` is refused. For `multiOption`, `min` and `max`
                  bound how many choices are picked. A text field has no `min`
                  or `max`.
                properties:
                  min:
                    description: |-
                      Lowest value, earliest date, or fewest choices.
                      **Example:** `0` or `{"ref":"startDate"}`
                  max:
                    description: Highest value, latest date, or most choices.
                  minInclusive:
                    type: boolean
                    description: |-
                      Whether `min` itself is allowed.
                      **Default:** `true`
                  maxInclusive:
                    type: boolean
                    description: |-
                      Whether `max` itself is allowed.
                      **Default:** `true`
                  decimals:
                    type: integer
                    description: 'Number fields: digits allowed after the decimal point.'
              relation:
                type: object
                description: 'Required for a `relation` field: which records it links to.'
                properties:
                  kind:
                    type: string
                    enum:
                      - belongsTo
                      - belongsToMany
                      - hasOne
                      - hasMany
                    description: >-
                      `belongsTo` stores one target id, `belongsToMany` a list
                      of ids. `hasOne` and `hasMany` store nothing: they show
                      the records of another type that point here through `via`.
                  targetKind:
                    type: string
                    enum:
                      - dataType
                      - standard
                    description: A data type, or a MileApp entity.
                  target:
                    type: string
                    description: >-
                      The target data type `_id`, or for `standard` one of
                      `user`, `hub`, `vehicle`, `role`, `flow`.

                      **Example:** `hub`
                  via:
                    type: string
                    description: >-
                      Required for `hasOne` and `hasMany`: the field id, on the
                      target type, that points back here.
                  displayField:
                    type: string
                    description: >-
                      The target field shown for a linked record. Must exist on
                      the target type. Defaults to its Title.
        deleteFields:
          type: array
          description: >-
            This parameter is list of fields to data type id for delete the
            field on collection of data source.

            **Example**: 
             `[` 
             `'outletPhoneNumber',` 
             `'outletCloseOrder'` 
             `]`
        limitUser:
          type: boolean
          description: |-
            Setting to limit data source usage by users.
            **Default**: `false`
        provider:
          type: string
          enum:
            - internal
            - external-api
          description: The data source provider type. Cannot be changed after creation.
        providerConfig:
          type: object
          nullable: true
          description: >-
            Provider-specific configuration. Can only be modified if the data
            type was created with `provider` set to `external-api`. The
            `provider` field itself cannot be changed after creation.
          oneOf:
            - description: For internal provider
              nullable: true
            - type: object
              description: For external-api provider
              properties:
                url:
                  type: string
                  format: uri
                  description: >-
                    The external API endpoint URL. Must be a valid [GET] URL
                    format.

                    **Example**: `https://api.external-system.com/v1/products`

                    **Validation**: Must be a valid [GET] URL with http:// or
                    https:// protocol
                key:
                  type: string
                  description: >-
                    Authentication key for the external API. When updating, if
                    not provided, the existing key will be preserved.

                    **Example**: `Bearer sk_live_1234567890`
              required:
                - url
        extends:
          type: object
          properties:
            entity:
              type: string
              enum:
                - user
                - hub
                - vehicle
                - role
          description: >-
            Makes this data type the Extended data of a MileApp entity: its
            records hold the custom fields read back as `extendedData` with
            `include=extendedData`. One extension per entity per organization.
            An extension keeps its own name; any other type may not take a
            Master Data name (`user`, `hub`, `vehicle`, `role`, `tasktype` and
            their translations), refused with `failedCode` `dtype-037`.
        uniqueTogether:
          type: array
          items:
            type: array
            items:
              type: string
          description: >-
            Combinations of two or more field ids whose values together must not
            repeat within a hub. `primaryKey`, `hasOne` and `hasMany` fields
            cannot join one. The same combination twice is refused.

            **Example:** `[["outlet","product"]]`
        columnOrder:
          type: array
          items:
            type: string
          description: >-
            Order of the Data Source table columns: `_select`, `_no`, field ids,
            then `createdBy`, `createdTime`, `updatedTime`, `hub`, `limitUser`.
            Unknown ids are dropped on read.
        metaColumns:
          type: array
          items:
            type: object
            properties:
              id:
                type: string
              show:
                type: boolean
          description: |-
            Visibility of the non-field columns.
            **Example:** `[{"id":"createdBy","show":true}]`
        commonData:
          type: boolean
          description: >-
            `false` scopes records by hub (each record belongs to one hub).
            Changeable only while the type has no records.
      required:
        - name
        - fields
      description: >-
        Data type definition. The v4 field model adds field types, validations,
        relations, unique together, column settings and Master Data extensions.
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: Use a valid Bearer token to authenticate.

````

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