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

# Create or update data in bulk

> Creates or updates up to 2000 records: a row whose `dataId` already exists in its data type and hub updates that record, any other row creates one. Each row is checked on its own: the response counts `success` and `failed` and returns one result per row, so one bad row does not stop the others.

**The Title.** `dataId` is the record's Title and key, unique within its data type and hub. On a v4-only type it may contain spaces between words; on a v3-compatible type only letters, digits, `-` and `_`.

**Field rules.** On a v4-only data type the v4 field rules apply: validations, `unique` and `uniqueTogether` (per hub), `multiOption`, `boolean` and `relation` values (a `belongsTo` field takes the target record `_id`, a `belongsToMany` field a list of ids). On a v3-compatible type, the v3 rules apply. Keys that are not fields of the data type are refused. While the record's data type is being prepared or registering unique values, writes answer `409` with `failedCode` `dtype-036`.

Requires permissions `add/data` and `edit/data`.



## OpenAPI

````yaml /openapi/public/openapi-data.json post /data/bulk/upsert
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/bulk/upsert:
    post:
      tags:
        - Data Source
      summary: Create or update data in bulk
      description: >-
        Creates or updates up to 2000 records: a row whose `dataId` already
        exists in its data type and hub updates that record, any other row
        creates one. Each row is checked on its own: the response counts
        `success` and `failed` and returns one result per row, so one bad row
        does not stop the others.


        **The Title.** `dataId` is the record's Title and key, unique within its
        data type and hub. On a v4-only type it may contain spaces between
        words; on a v3-compatible type only letters, digits, `-` and `_`.


        **Field rules.** On a v4-only data type the v4 field rules apply:
        validations, `unique` and `uniqueTogether` (per hub), `multiOption`,
        `boolean` and `relation` values (a `belongsTo` field takes the target
        record `_id`, a `belongsToMany` field a list of ids). On a v3-compatible
        type, the v3 rules apply. Keys that are not fields of the data type are
        refused. While the record's data type is being prepared or registering
        unique values, writes answer `409` with `failedCode` `dtype-036`.


        Requires permissions `add/data` and `edit/data`.
      operationId: UpsertDataBulk
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/upsertDataBulkRequest'
        required: true
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                title: NetworkUpsertBulkResponse
                properties:
                  success:
                    description: Total success created or update data source.
                    type: integer
                  failed:
                    description: Total failed created or update data source.
                    type: integer
                  data:
                    description: Detail of created or update data source.
                    type: array
                    items:
                      type: object
                      properties:
                        status:
                          type: boolean
                          description: Status of response.
                        message:
                          description: Message of create or update data source
                          type: string
                        event:
                          description: >-
                            The type of action performed on the data source,
                            either `create` or `update`
                          type: string
                        _id:
                          description: Data source ID
                          type: string
                example:
                  success: 2
                  failed: 0
                  data:
                    - status: true
                      message: Data has been created successfully.
                      event: create
                      _id: 646db91d0d73b6392543fb82
                    - status: true
                      message: Data has been updated successfully.
                      event: update
                      _id: 646db91d0d73b6392543fb83
        '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: []
      servers:
        - url: https://apiweb.mile.app/api/v4
components:
  schemas:
    upsertDataBulkRequest:
      title: upsertDataBulkRequest
      example:
        data:
          - dataId: N001
            dataTypeId: 64e5d8a107e9e4337a5ba3d2
            hubId: 65322ff9cc356d4bd67fcc22
            field1: Jack Ward
            field2: Gambir Jakarta
            field3: '-6.230815251,106.75684387'
            limitUser: null
          - dataId: N002
            dataTypeId: 64e5d8a107e9e4337a5ba3d2
            hubId: 65322ff9cc356d4bd67fcc22
            field1: Jack Ward
            field2: Menteng Jakarta
            field3: '-6.1951689,106.8278573'
            limitUser: null
      type: object
      properties:
        data:
          type: array
          description: >-
            The maximum data for creating or update multiple data source is 2000
            data.
          items:
            type: object
            properties:
              dataId:
                type: string
                description: >-
                  The identifier of fields from data type. The upsert endpoint
                  combines the functionalities of both POST and PUT operations.
                  Depending on the presence of a specified identifier (dataId),
                  the endpoint will either create a new record or update an
                  existing one. 

                  **Example**: `N001`
              dataTypeId:
                type: string
                description: >-
                  The identifier of data type. Use [GET /data-types
                  API](#tag/Data-Type/operation/getDataType) to get the list of
                  Data Type IDs.

                  **Example**: `63db2fb476bc679c540369c4`
              hubId:
                type: string
                description: >-
                  The identifier for the hub that generated by system. `hubId`
                  is **not required** if the `commonData` configuration for the
                  data type is true.

                  Use [GET /hubs API](#tag/Hub/operation/getHubs) to get the
                  list of Hub IDs.

                  **Example:** `63c63ffbdef63e6f641aac72`
              field1:
                type: string
                description: >-
                  This field's type & value is according to dataType. Use [GET
                  /data-types API](#tag/Data-Type/operation/getDataType) to get
                  fields of dataType.

                  **Example:** `Jack Ward`
              field2:
                type: string
                description: >-
                  This field's type & value is according to dataType. Use [GET
                  /data-types API](#tag/Data-Type/operation/getDataType) to get
                  fields of dataType.

                  **Example:** `Gambir Jakarta`
              field3:
                type: string
                description: >-
                  This field's type & value is according to dataType. Use [GET
                  /data-types API](#tag/Data-Type/operation/getDataType) to get
                  fields of dataType.

                  **Example:** `-6.230815251,106.75684387`
              limitUser:
                type: array
                description: List of email that can see the data source.
                items:
                  type: object
                  additionalProperties: true
            required:
              - dataId
              - dataTypeId
      required:
        - data
  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.