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

> Export results allow users to acquire task data by applying specific filters. This endpoint supports two processing modes: **direct export** (returns file immediately) and **background export** (queued processing with notification via export-log).

**Export Limits:**
- XLSX format: Up to 1,000,000 tasks
- JSON format: Up to 1,000,000 tasks (separated per 10,000 tasks and merged into one zip file)

**Processing Modes:**
- **Direct Export** (`background=false`): File returned immediately in response. Best for small datasets (< 10,000 records)
- **Background Export** (`background=true`): Export queued for processing. Monitor status via [GET /tasks/export-log](#tag/Export-Task/operation/GetExportLog). Best for large datasets

**Important Notes:**
- Use `exportConfigId` to apply predefined export templates with custom fields and flows
- Export files are stored on S3 with 30-day retention
- Background exports send completion notification to user's email



## OpenAPI

````yaml /openapi/public/openapi-importexport.json post /tasks/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:
  /tasks/export:
    post:
      tags:
        - Export Task
      summary: Export tasks
      description: >-
        Export results allow users to acquire task data by applying specific
        filters. This endpoint supports two processing modes: **direct export**
        (returns file immediately) and **background export** (queued processing
        with notification via export-log).


        **Export Limits:**

        - XLSX format: Up to 1,000,000 tasks

        - JSON format: Up to 1,000,000 tasks (separated per 10,000 tasks and
        merged into one zip file)


        **Processing Modes:**

        - **Direct Export** (`background=false`): File returned immediately in
        response. Best for small datasets (< 10,000 records)

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


        **Important Notes:**

        - Use `exportConfigId` to apply predefined export templates with custom
        fields and flows

        - Export files are stored on S3 with 30-day retention

        - Background exports send completion notification to user's email
      operationId: ExportTasks
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/postExportTask'
        description: >-
          Request body containing export parameters. Use filters to narrow down
          the dataset and `fields` parameter to select specific columns.
        required: true
      responses:
        '200':
          description: Success - Export completed or queued
          content:
            application/json:
              schema:
                type: object
                title: ExportTaskResponse
                properties:
                  status:
                    type: boolean
                    description: Status of response.
                  message:
                    description: Message of API response.
                    type: string
                  total_data_be:
                    description: Total number of tasks successfully exported.
                    type: integer
                  last_id:
                    description: ID of the last task 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. Structure varies based on
                      processing mode (direct vs background).
                    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:
                          - task
                      link:
                        description: >-
                          Direct download URL for the exported file (S3
                          presigned URL)
                        type: string
                      status:
                        description: Export processing status
                        type: string
                        enum:
                          - Done
                          - Processing
                          - Failed
                example:
                  status: true
                  message: Success
                  total_data_be: 47
                  last_id: 61e5477611c1b26cef05d37c
                  last_field: status
                  data:
                    time: 1644595005
                    organizationId: 61c2fbaaf27b374e8913fe72
                    reportType: task
                    link: >-
                      https://staticdev.mile.app/production-mile/20220211/task_61c2fbaaf27b374e8913fe72_1644595005.xlsx
                    status: Done
              examples:
                response:
                  value:
                    Direct Export (background=false):
                      value:
                        status: true
                        message: Success
                        total_data_be: 150
                        last_id: 61e5477611c1b26cef05d37c
                        last_field: status
                        data:
                          time: 1644595005
                          organizationId: 61c2fbaaf27b374e8913fe72
                          reportType: task
                          link: >-
                            https://staticdev.mile.app/production-mile/20220211/task_61c2fbaaf27b374e8913fe72_1644595005.xlsx
                          status: Done
                    Background Export (background=true):
                      value:
                        status: true
                        message: >-
                          Export queued for background processing. Check status
                          at GET /tasks/export-log
                        total_data_be: 0
                        data:
                          time: 1644595005
                          organizationId: 61c2fbaaf27b374e8913fe72
                          reportType: task
                          status: Processing
        '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 field 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 tasks
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: boolean
                    example: false
                  message:
                    type: string
                    example: You do not have permission to export tasks
        '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/tasks/export" \
              -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
              -H "Content-Type: application/json" \
              -d '{
                "download": "xlsx",
                "fields": "startTime,endTime,hubId,createdBy,flow,status",
                "status": "DONE",
                "flowId": "63d8c9b0dbd5ef20a627dd86",
                "hubId": "621dd813eb3ebf16b94d6969",
                "page": 1,
                "limit": 100,
                "sortBy": "createdTime",
                "sortOrder": "desc",
                "background": false
              }'
        - lang: cURL - Background Export
          source: |-
            curl -X POST "https://apiweb.mile.app/api/v3/tasks/export" \
              -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
              -H "Content-Type: application/json" \
              -d '{
                "download": "xlsx",
                "flowId": "63d8c9b0dbd5ef20a627dd86",
                "background": true,
                "exportConfigId": "634e98498ce07d29474a7e29"
              }'
        - lang: JavaScript - Axios
          source: |-
            const axios = require('axios');

            const exportTasks = async () => {
              try {
                const response = await axios.post(
                  'https://apiweb.mile.app/api/v3/tasks/export',
                  {
                    download: 'xlsx',
                    fields: 'startTime,endTime,hubId,createdBy,flow,status',
                    status: 'DONE',
                    flowId: '63d8c9b0dbd5ef20a627dd86',
                    hubId: '621dd813eb3ebf16b94d6969',
                    page: 1,
                    limit: 100,
                    sortBy: 'createdTime',
                    sortOrder: 'desc',
                    background: false
                  },
                  {
                    headers: {
                      'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
                      'Content-Type': 'application/json'
                    }
                  }
                );
                
                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);
              }
            };

            exportTasks();
components:
  schemas:
    postExportTask:
      title: postExportTask
      type: object
      description: >-
        Request body schema for exporting tasks. Use filters to narrow down the
        dataset and customize the export output.
      example:
        download: xlsx
        fields: startTime,endTime,hubId,createdBy,flow,status
        doneBy: Leandro
        assignee: leandro@mile.app
        status: DONE
        flowId: 63d8c9b0dbd5ef20a627dd86
        hubId: 621dd813eb3ebf16b94d6969
        page: 1
        limit: 20
        sortBy: createdTime
        sortOrder: desc
        background: false
        exportConfigId: 634e98498ce07d29474a7e29
      properties:
        download:
          type: string
          enum:
            - json
            - xlsx
          description: >-
            File type that user want to download. There are 2 types of
            `download`:

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

            **Example:** `xlsx`
        fields:
          type: string
          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:** `startTime,endTime,hubId,createdBy,flow,status`
        doneBy:
          type: string
          description: |-
            Name of user that completing the task.
            **Example:** `Leandro`
        assignee:
          type: string
          description: |-
            User email for a given task.
            **Example**: `leandro@mile.app`
        status:
          type: string
          enum:
            - UNASSIGNED
            - ONGOING
            - DONE
          description: >-
            Status of task according to task's data condition. There are 3 types
            of `status`:

            **enum**: `UNASSIGNED`,`ONGOING`,`DONE`

            **Example:** `UNASSIGNED`
        flowId:
          type: string
          description: >-
            The identifier for the flow that generated by system. Use [GET
            /flows API](#tag/Flow/operation/getflow) to get the list of flow id.

            Comma (,) delimiter for filter multiple flow.

            **Example:** `63d8c9b0dbd5ef20a627dd86,73d8c9b0dbd5ef20a627dd87`
        hubId:
          type: string
          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:** `621dd813eb3ebf16b94d6969`
        page:
          type: integer
          format: int32
          description: |-
            Pagination of tasks result list.
            **Example:** `2`.
            **Default:** `1`
        limit:
          type: integer
          format: int32
          description: |-
            Limit of tasks result list.
            **Example:** `10`.
            **Default:** `30`
        sortBy:
          type: string
          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 task objects.

            **Example:** `flow`, `assignee`, `status`, `hubId`, etc.

            **Default:** `createdTime`
        sortOrder:
          type: string
          enum:
            - asc
            - desc
          description: |-
            sortOrder is to decide ascending or descending order
            **Example:** `asc` or `desc`.
            **Default:** `desc`
        background:
          type: boolean
          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`
        exportConfigId:
          type: string
          description: >-
            Unique identifier for the export config for allow user to export
            data using their own configuration. Use [GET
            /export-configs](#tag/Export-Config/operation/getExportConfigs)
            endpoint to get the list of Export Config IDs.

            **Example:** `634e98498ce07d29474a7e29`
      required:
        - download
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: Use a valid Bearer token to authenticate.

````