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

# Export data source

> Export data source records by applying specific filters. This endpoint supports exporting various data types defined in your organization with customizable field selection.

**Export Modes:**
- **Direct Export** (`background=false`): Returns file immediately. Best for datasets < 10,000 records
- **Background Export** (`background=true`): Queued for processing. Monitor via [GET /tasks/export-log](#tag/Export-Task/operation/GetExportLog). Best for large datasets

**Supported Formats:**
- `xlsx`: Excel format (recommended for most use cases)
- `json`: JSON format (for programmatic processing)

**Important Notes:**
- Use `fields` parameter to select specific columns for export
- Filter by `dataTypeId` to export specific data type records
- Maximum 1,000,000 records per export
- Export files are stored for 30 days



## OpenAPI

````yaml /openapi/public/openapi-importexport.json post /data/export
openapi: 3.0.0
info:
  title: MileApp API - ImportExport
  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 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 MileApp. 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/export:
    post:
      tags:
        - Export Task
      summary: Export data source
      description: >-
        Export data source records by applying specific filters. This endpoint
        supports exporting various data types defined in your organization with
        customizable field selection.


        **Export Modes:**

        - **Direct Export** (`background=false`): Returns file immediately. Best
        for datasets < 10,000 records

        - **Background Export** (`background=true`): Queued for processing.
        Monitor via [GET
        /tasks/export-log](#tag/Export-Task/operation/GetExportLog). Best for
        large datasets


        **Supported Formats:**

        - `xlsx`: Excel format (recommended for most use cases)

        - `json`: JSON format (for programmatic processing)


        **Important Notes:**

        - Use `fields` parameter to select specific columns for export

        - Filter by `dataTypeId` to export specific data type records

        - Maximum 1,000,000 records per export

        - Export files are stored for 30 days
      operationId: ExportDataSource
      parameters:
        - name: download
          in: query
          required: true
          description: >-
            File type that user want to download. There are 2 types of
            `download`:

            **enum**: `json`,`xlsx`

            **Example:** `xlsx`
          schema:
            type: string
            enum:
              - json
              - xlsx
        - name: background
          in: query
          required: false
          description: >-
            If the user sets the background parameter to `true`, the export
            process will utilize background processing, and the results will be
            available at [GET /tasks/export-log
            API](#tag/Export-Task/operation/GetExportLog). If the user sets the
            background parameter to `false`, the export process will run
            directly, and the results will be immediately available in the
            response.

            **Example:** `true`.

            **Default:** `false`
          schema:
            type: boolean
        - name: fields
          in: query
          required: false
          description: >-
            Fields is for selecting the specific fields that you can choose by
            multiples to show in the response using a string with a comma
            delimiter.

            **Example:** `dataId,name,address`
          schema:
            type: string
        - name: hubId
          in: query
          required: false
          description: >-
            The identifier for the hub that generated by system. Use [GET /hubs
            API](#tag/Hub/operation/getHubs) to get the list of Hub IDs.

            **Example:** `63c63ab1b6972d3150348172`
          schema:
            type: string
        - name: dataTypeId
          in: query
          required: false
          description: >-
            The identifier for the dataType that generated by system. Use [GET
            /data-types API](#tag/Data-Type/operation/getDataType) to get the
            list of dataType IDs.

            **Example:** `6422816ef6710f053056d812`
          schema:
            type: string
        - name: page
          in: query
          required: false
          description: |-
            Pagination of data result list.
            **Example:** `2`.
            **Default:** `1`
          schema:
            type: integer
            format: int32
        - name: limit
          in: query
          required: false
          description: |-
            Limit of data result list.
            **Example:** `10`.
            **Default:** `30`
          schema:
            type: integer
            format: int32
        - name: sortBy
          in: query
          required: false
          description: >-
            sortBy is used to sort the result-set in ascending or descending
            order according to selected field. The value of this param is one of
            available fields on data source objects.

            **Example:** `name`, `address`, `hubId`, etc.

            **Default:** `createdTime`
          schema:
            type: string
        - name: sortOrder
          in: query
          required: false
          description: |-
            sortOrder is to decide ascending or descending order
            **Example:** `asc` or `desc`.
            **Default:** `desc`
          schema:
            type: string
            enum:
              - asc
              - desc
      responses:
        '200':
          description: Success - Export completed or queued
          content:
            application/json:
              schema:
                type: object
                title: ExportDataSourceResponse
                properties:
                  status:
                    type: boolean
                    description: Status of response.
                  message:
                    description: Message of API response.
                    type: string
                  total_data_be:
                    description: Total number of data source records successfully exported.
                    type: integer
                  last_id:
                    description: >-
                      ID of the last data source record that was successfully
                      exported.
                    type: string
                  last_field:
                    description: Name of the last field that was successfully exported.
                    type: string
                  data:
                    description: Export file information.
                    type: object
                    properties:
                      time:
                        description: Unix timestamp when export was created
                        type: integer
                      organizationId:
                        description: Organization ID that owns the export
                        type: string
                      reportType:
                        description: Type of export report
                        type: string
                        enum:
                          - data
                      link:
                        description: Direct download URL for the exported file
                        type: string
                      status:
                        description: Export processing status
                        type: string
                        enum:
                          - Done
                          - Processing
                          - Failed
                example:
                  status: true
                  message: Success
                  total_data_be: 10
                  last_id: 642282a259c3f74157368012
                  last_field: address
                  data:
                    time: 1681194657
                    organizationId: 63d397ca8cb4d07e9d581c82
                    reportType: data
                    link: >-
                      https://staticdev.mile.app/dev-mile/20230411/data_63d397ca8cb4d07e9d581c82_1681194657.xlsx
                    status: Done
        '400':
          description: Bad Request - Invalid parameters or validation error
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: boolean
                    example: false
                  message:
                    type: string
                    example: The download parameter is required.
        '401':
          description: Unauthorized - Invalid or missing authentication token
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: boolean
                    example: false
                  message:
                    type: string
                    example: Unauthorized
        '403':
          description: Forbidden - User lacks permission to export data
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: boolean
                    example: false
                  message:
                    type: string
                    example: You do not have permission to export data
        '500':
          description: Server Error - Internal server error during export
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: boolean
                    example: false
                  message:
                    type: string
                    example: Internal server error
                  error:
                    type: object
                    properties:
                      message:
                        type: string
                      file:
                        type: string
                      line_of_code:
                        type: integer
      deprecated: false
      security:
        - bearerAuth: []
      x-code-samples:
        - lang: cURL
          source: >-
            curl -X POST
            "https://apiweb.mile.app/api/v3/data/export?download=xlsx&dataTypeId=6422816ef6710f053056d812&fields=dataId,name,address&limit=100"
            \
              -H "Authorization: Bearer YOUR_ACCESS_TOKEN"
        - lang: cURL - Background Export
          source: >-
            curl -X POST
            "https://apiweb.mile.app/api/v3/data/export?download=xlsx&dataTypeId=6422816ef6710f053056d812&background=true"
            \
              -H "Authorization: Bearer YOUR_ACCESS_TOKEN"
        - lang: JavaScript - Axios
          source: |-
            const axios = require('axios');

            const exportDataSource = async () => {
              try {
                const response = await axios.post(
                  'https://apiweb.mile.app/api/v3/data/export',
                  null,
                  {
                    params: {
                      download: 'xlsx',
                      dataTypeId: '6422816ef6710f053056d812',
                      fields: 'dataId,name,address',
                      hubId: '63c63ab1b6972d3150348172',
                      limit: 100,
                      sortBy: 'createdTime',
                      sortOrder: 'desc'
                    },
                    headers: {
                      'Authorization': 'Bearer YOUR_ACCESS_TOKEN'
                    }
                  }
                );
                
                console.log('Export completed:', response.data);
                console.log('Download link:', response.data.data.link);
              } catch (error) {
                console.error('Export failed:', error.response?.data || error.message);
              }
            };

            exportDataSource();
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: Use a valid Bearer token to authenticate.

````