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

# Import data

> Uploads an Excel file (`xls` or `xlsx`, at most 20 MB) of records into one data type. The rows are read in the background: the response returns the import record (`status` `onprocess`, `totalRows`) and the result appears in the import history.

`hubId` is required unless the data type has no hub scope; every row goes to that hub, and a `hubsName` column in the file is ignored. The header row must match the data type fields. A file with no data rows is refused (`failedCode` `data-013`). While an import runs, the data type cannot be upgraded or saved as v3 (`409`). While the record's data type is being prepared or registering unique values, writes answer `409` with `failedCode` `dtype-036`.

Requires permission `add/data`.



## OpenAPI

````yaml /openapi/public/openapi-importexport.json post /data/import
openapi: 3.0.0
info:
  title: API - ImportExport
  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 Import
    description: >-
      The Data Import module allows users to upload and import data source
      records from Excel or CSV files. Import operations are processed in the
      background via queue system for scalability and can handle large datasets.
      The import process validates data against data type schemas, tracks
      processing status in real-time, and generates detailed reports including
      failed records for review. All import activities can be monitored through
      import-monitoring endpoints with 30-day data retention.
  - name: Export Task
    description: >-
      The Export Task module provides functionality to export task data and data
      source records to various formats (XLSX, JSON). It supports both direct
      export for small datasets and background processing for large exports.
      Users can customize exports using export configurations, filter data by
      multiple criteria, and monitor export operations through export logs.
      Export files are stored securely with 30-day retention period.
  - name: Export Config
    description: >-
      The Export Config module is used to save and manage the specific fields
      that a user wants included in export results. This allows users to
      customize their exported data by selecting only the necessary fields for
      each export, ensuring that the output contains exactly the information
      they need.


      **To see the details of export config object, please follow [this
      link](#tag/export_config_model)**
  - name: Import Config
    description: >-
      The Import Config module saves and manages column mapping presets for bulk
      import features across the app. Users can store field-to-Excel-column
      mappings so they can be reused across multiple imports. Each config is
      linked to a specific resource and contains the mapping between its fields
      and Excel header columns.
paths:
  /data/import:
    post:
      tags:
        - Data Import
      summary: Import data
      description: >-
        Uploads an Excel file (`xls` or `xlsx`, at most 20 MB) of records into
        one data type. The rows are read in the background: the response returns
        the import record (`status` `onprocess`, `totalRows`) and the result
        appears in the import history.


        `hubId` is required unless the data type has no hub scope; every row
        goes to that hub, and a `hubsName` column in the file is ignored. The
        header row must match the data type fields. A file with no data rows is
        refused (`failedCode` `data-013`). While an import runs, the data type
        cannot be upgraded or saved as v3 (`409`). While the record's data type
        is being prepared or registering unique values, writes answer `409` with
        `failedCode` `dtype-036`.


        Requires permission `add/data`.
      operationId: ImportData
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                file:
                  description: >-
                    The file containing data to import. Supported formats: CSV,
                    XLS, XLSX. Maximum file size: 20MB.

                    **Example:** `datasource_import.xlsx`
                  type: string
                  format: binary
                dataTypeId:
                  description: >-
                    The identifier for the data type. Required for datasource
                    import type. Use [GET /data-types
                    API](#tag/Data-Type/operation/getDataType) to get the list
                    of Data Type IDs.

                    **Example:** `63db2fb476bc679c540369c4`
                  type: string
                hubId:
                  description: >-
                    The identifier for the hub. Required if the data type has
                    `commonData` set to false (hub-specific data). Use [GET
                    /hubs API](#tag/Hub/operation/getHubs) to get the list of
                    Hub IDs.

                    **Example:** `63c63ab1b6972d3150348172`
                  type: string
              required:
                - file
                - dataTypeId
        required: true
      responses:
        '200':
          description: Success - File uploaded and import process queued
          content:
            application/json:
              schema:
                type: object
                title: ImportDataResponse
                properties:
                  status:
                    type: boolean
                    description: Status of response.
                  message:
                    description: Message of API response.
                    type: string
                  data:
                    description: Import monitoring record created for this import.
                    type: object
                    properties:
                      _id:
                        type: string
                        description: Import monitoring ID
                      organizationId:
                        type: string
                        description: Organization ID
                      inputType:
                        type: string
                        description: >-
                          The input type of the component (e.g., string, number,
                          date, etc.)
                      hubId:
                        type: string
                        description: Hub ID (if applicable)
                      filename:
                        type: string
                        description: Original uploaded filename
                      totalRows:
                        type: integer
                        description: Total rows in the file
                      totalValid:
                        type: integer
                        description: >-
                          Total valid rows (initially 0, updated during
                          processing)
                      totalInvalid:
                        type: integer
                        description: >-
                          Total invalid rows (initially 0, updated during
                          processing)
                      status:
                        type: string
                        description: Import status
                        enum:
                          - onprocess
                          - success
                          - partially
                          - failed
                      dataTypeId:
                        type: string
                        description: Data type ID (for datasource import)
                      dataTypeName:
                        type: string
                        description: Data type name (for datasource import)
                      fileTemplate:
                        type: string
                        description: URL to download template file
                      createdBy:
                        type: string
                        description: Email of user who initiated the import
                      createdTime:
                        type: string
                        description: Timestamp when import was created
                      updatedTime:
                        type: string
                        description: Timestamp when import was last updated
                example:
                  status: true
                  message: Import process has been queued successfully
                  data:
                    _id: 65f8a4c2d9e3b1234567890a
                    organizationId: 63c61d865347e356d05e3052
                    type: string
                    hubId: 63c63ab1b6972d3150348172
                    filename: outlets_import.xlsx
                    totalRows: 150
                    totalValid: 0
                    totalInvalid: 0
                    status: onprocess
                    dataTypeId: 63db2fb476bc679c540369c4
                    dataTypeName: OutletDetail
                    fileTemplate: >-
                      https://staticdev.mile.app/dev-mile/templates/template_OutletDetail.xlsx
                    totalChunks: 3
                    processedChunks: 0
                    createdBy: john.doe@example.com
                    createdTime: '2024-03-18 10:30:45'
                    updatedTime: '2024-03-18 10:30:45'
        '400':
          description: Bad Request - Validation error
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: boolean
                  message:
                    type: string
                  failedCode:
                    type: string
              examples:
                response:
                  value:
                    status: false
                    message: The file field is required.
                    failedCode: import-001
        '401':
          description: Unauthorized - Invalid or missing authentication token
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: boolean
                  message:
                    type: string
                  failedCode:
                    type: string
              examples:
                response:
                  value:
                    status: false
                    message: Unauthorized
                    failedCode: auth-001
        '403':
          description: Forbidden - User does not have permission to import data
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: boolean
                  message:
                    type: string
                  failedCode:
                    type: string
              examples:
                response:
                  value:
                    status: false
                    message: You do not have permission to perform this action
                    failedCode: auth-003
        '422':
          description: Unprocessable Entity - Invalid file format or data type not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: boolean
                  message:
                    type: string
                  failedCode:
                    type: string
              examples:
                response:
                  value:
                    status: false
                    message: 'The file must be a file of type: csv, xls, xlsx.'
                    failedCode: import-002
        '500':
          description: Server error
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: boolean
                  message:
                    type: string
                  failedCode:
                    type: string
              examples:
                response:
                  value:
                    status: false
                    message: Internal server error
                    failedCode: import-045
      deprecated: false
      security:
        - bearerAuth: []
      servers:
        - url: https://apiweb.mile.app/api/v4
      x-code-samples:
        - lang: cURL
          source: |-
            curl -X POST "https://apiweb.mile.app/api/v3/data/import" \
              -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
              -F "file=@/path/to/datasource_import.xlsx" \
              -F "dataTypeId=63db2fb476bc679c540369c4" \
              -F "hubId=63c63ab1b6972d3150348172"
components:
  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.