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

# Create data type



## OpenAPI

````yaml /openapi/public/openapi-data.json post /data-type
openapi: 3.0.0
info:
  title: MileApp API - Data
  version: 3.0.0
  description: MileApp 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 at MileApp. 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:
    post:
      tags:
        - Data Type
      summary: Create data type
      operationId: CreateDataType
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/postRequestDataType'
        required: true
      responses:
        '201':
          headers: {}
          description: Success
          content:
            application/json:
              schema:
                type: object
                title: NetworkCreateResponse
                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@mile.app
                    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.
        '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: []
components:
  schemas:
    postRequestDataType:
      title: postRequestDataType
      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:00 AM
            type: string
            optionData: []
            required: true
          - id: outletClosed
            title: Outlet Closed
            default: 09:00:00 PM
            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
            properties:
              id:
                type: string
                description: |-
                  ID of Field.
                  **Example**: `outletName`
              title:
                type: string
                description: |-
                  Title of field.
                  **Example**: `Outlet Name`
              type:
                type: string
                enum:
                  - title
                  - text
                  - number
                  - boolean
                  - option
                  - multiOption
                  - date
                  - dateTime
                  - time
                  - geolocation
                  - phoneNumber
                  - relation
                  - primaryKey
                description: >-
                  Field type. Exactly one field per data type must be `type:
                  "title"` -- it is forced `required`, `unique`, `show`, and
                  `searchable` regardless of what is submitted. `primaryKey`
                  remains supported for data types created before `title`
                  existed; a data type uses one or the other, never both. The
                  title field's `id` is always `dataId`: the record's `dataId`
                  is its title. It may contain letters, digits, `-`, `_` and
                  inner spaces; other symbols are rejected. A data type created
                  in the earlier version keeps the no-space rule until it is
                  first saved through this API.

                  **Example**: `title`
              description:
                type: string
              inputType:
                type: string
                description: >-
                  The input type of the component (e.g., string, number, date,
                  etc.)
              default:
                type: string
                description: |-
                  Default value of field.
                  **Example**: `09:00:00 AM`
              optionData:
                type: array
                description: >-
                  Option Data of field. Field only exist, if *type* is
                  **option** or **multiOption** 

                  **Example**: `['minimarket','supermarket','vending
                  machine','warung']`
                items:
                  type: string
              isRequired:
                type: boolean
                description: |2-
                   Flag that mark field as required or not.
                  **Example**: `true`
              unique:
                type: boolean
                description: >-
                  When true, this field's value must be unique across every
                  record of the data type (scoped by hub unless `commonData` is
                  true). Always `true` on the `title` field.

                  **Default**: `false`
              searchable:
                type: boolean
                description: >-
                  When true, this field is matched by the `q` search parameter
                  on `GET /data`. Always `true` on the `title` field. A data
                  type can have at most 5 searchable fields; a save that would
                  raise the count above 5 is rejected, while a data type already
                  above 5 can still be saved and have fields turned off.

                  **Default**: `false`
              validations:
                type: object
                description: >-
                  Rules checked when a record is created or updated. `min`/`max`
                  accept a literal value, or `{ "ref": "otherFieldId" }` to
                  compare against another field on the same record (applies to
                  `number`, `date`, `dateTime`, `time`; a `ref` must name a
                  field of the same type). On `date`, `dateTime` and `time`,
                  `minInclusive` / `maxInclusive` (default `true`) say whether
                  the bound itself is allowed. `decimals` caps decimal places on
                  `number`. `minSelected`/`maxSelected` bound how many options
                  may be chosen on `multiOption`. A rule unsupported by the
                  field's `type` is rejected when the data type is saved.

                  **Example**: `{ "min": 1, "max": 100 }` or `{ "min": { "ref":
                  "minQuantity" } }`
                properties:
                  min:
                    description: |-
                      Literal minimum, or `{ "ref": "otherFieldId" }`.
                      **Example**: `5`
                  max:
                    description: |-
                      Literal maximum, or `{ "ref": "otherFieldId" }`.
                      **Example**: `100`
                  decimals:
                    type: integer
                    description: |-
                      Maximum decimal places accepted for a `number` field.
                      **Example**: `2`
                  minSelected:
                    type: integer
                    description: >-
                      Minimum number of options that must be selected on a
                      `multiOption` field.

                      **Example**: `1`
                  maxSelected:
                    type: integer
                    description: >-
                      Maximum number of options that may be selected on a
                      `multiOption` field.

                      **Example**: `3`
              relation:
                type: object
                description: >-
                  Required when `type` is `relation`. Declares what this field
                  points to.

                  **Example**: `{ "kind": "belongsTo", "targetKind": "standard",
                  "target": "vehicle" }`
                properties:
                  kind:
                    type: string
                    enum:
                      - belongsTo
                      - belongsToMany
                      - hasOne
                      - hasMany
                    description: >-
                      `belongsTo` stores one target `_id` on this record;
                      `belongsToMany` stores an array of target `_id` values.
                      `hasOne`/`hasMany` store nothing here and are resolved
                      through the target's `via` field.
                  targetKind:
                    type: string
                    enum:
                      - dataType
                      - standard
                    description: >-
                      `dataType` points at another data type by id. `standard`
                      points at a MileApp entity named in `target`.
                  target:
                    type: string
                    description: >-
                      When `targetKind` is `dataType`, the target data type's
                      `_id`. When `targetKind` is `standard`, one of `user`,
                      `hub`, `vehicle`, `role`, `flow`.

                      **Example**: `user`
                  via:
                    type: string
                    description: >-
                      Required when `kind` is `hasOne` or `hasMany`. The `id` of
                      the field on the target data type holding the inverse
                      relation back to this data type.
                required:
                  - kind
                  - targetKind
                  - target
            required:
              - id
              - title
              - type
              - required
        limitUser:
          type: boolean
          description: |-
            Setting to limit data source usage by users.
            **Default**: `false`
        commonData:
          type: boolean
          description: >-
            Settings to define the data source to be unique by hub or shared
            across all hubs. This setting is not changeable after creation.

            **Default**: `false`
        uniqueTogether:
          type: array
          items:
            type: array
            items:
              type: string
            minItems: 2
          description: >-
            Combinations of field ids whose values together must not repeat, for
            example `[["outlet", "product"]]`. Each combination has two or more
            fields, cannot include the title field or a relation filled from
            another data type, and cannot be listed twice. A multi-value field
            matches only the same set of values in any order, and an unticked
            boolean counts as false. A record with an empty field in a
            combination is not checked. Scoped per hub when the data type is
            limited by hub.

            **Example**: `[["outlet", "product"]]`
        extends:
          type: object
          nullable: true
          description: >-
            Set to attach custom fields to a MileApp entity instead of creating
            a standalone data source. At most one extension data type per
            `entity` per organization; forces `commonData` to `true` and the
            data type has no `title` field.

            **Example**: `{ "entity": "user" }`
          properties:
            entity:
              type: string
              enum:
                - user
                - hub
                - vehicle
                - role
                - flow
        provider:
          type: string
          enum:
            - internal
            - external-api
          default: internal
          description: |-
            The data source provider type.
            **Default**: `internal`
            **Available values**: `internal`, `external-api` (external GET API)
        providerConfig:
          type: object
          nullable: true
          description: >-
            Provider-specific configuration. Required when `provider` is
            `external-api`, should be null for `internal` provider.
          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.
                    **Example**: `Bearer sk_live_1234567890`
              required:
                - url
      required:
        - name
        - fields
  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.