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"import requests
url = "https://apiweb.mile.app/api/v3/data/import"
files = { "file": ("example-file", open("example-file", "rb")) }
payload = {
"dataTypeId": "<string>",
"hubId": "<string>"
}
headers = {"Authorization": "Bearer <token>"}
response = requests.post(url, data=payload, files=files, headers=headers)
print(response.text)const form = new FormData();
form.append('file', '<string>');
form.append('dataTypeId', '<string>');
form.append('hubId', '<string>');
const options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};
options.body = form;
fetch('https://apiweb.mile.app/api/v3/data/import', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://apiweb.mile.app/api/v3/data/import",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"dataTypeId\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"hubId\"\r\n\r\n<string>\r\n-----011000010111000001101001--",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: multipart/form-data; boundary=---011000010111000001101001"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://apiweb.mile.app/api/v3/data/import"
payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"dataTypeId\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"hubId\"\r\n\r\n<string>\r\n-----011000010111000001101001--")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "multipart/form-data; boundary=---011000010111000001101001")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://apiweb.mile.app/api/v3/data/import")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "multipart/form-data; boundary=---011000010111000001101001")
.body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"dataTypeId\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"hubId\"\r\n\r\n<string>\r\n-----011000010111000001101001--")
.asString();require 'uri'
require 'net/http'
url = URI("https://apiweb.mile.app/api/v3/data/import")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'multipart/form-data; boundary=---011000010111000001101001'
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"dataTypeId\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"hubId\"\r\n\r\n<string>\r\n-----011000010111000001101001--"
response = http.request(request)
puts response.read_body{
"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@mile.app",
"createdTime": "2024-03-18 10:30:45",
"updatedTime": "2024-03-18 10:30:45"
}
}{
"status": false,
"message": "The file field is required.",
"failedCode": "import-001"
}{
"status": false,
"message": "Unauthorized",
"failedCode": "auth-001"
}{
"status": false,
"message": "You do not have permission to perform this action",
"failedCode": "auth-003"
}{
"status": false,
"message": "The file must be a file of type: csv, xls, xlsx.",
"failedCode": "import-002"
}{
"status": false,
"message": "Internal server error",
"failedCode": "import-045"
}Import data source from file
This endpoint allows users to upload a file (CSV, XLS, or XLSX) containing data source records for import. The file is validated and processed in the background via queue. The import process supports multiple import types: datasource, task, visit, and route. After upload, the import is queued for processing and can be monitored via the import-monitoring endpoints.
Background Processing:
- Queue Name:
readingImportDatasource - Processing is chunked for large files
- Status updates are tracked in real-time
File Requirements:
- Max Size: 20MB
- Supported Formats: CSV, XLS, XLSX
- File structure must match the data type schema
Important Notes:
- For datasource import:
dataTypeIdis required - For datasource with hub-specific data:
hubIdis required (depends oncommonDatasetting) - Failed records are exported to a separate file for review
- Template file is generated based on data type schema
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"import requests
url = "https://apiweb.mile.app/api/v3/data/import"
files = { "file": ("example-file", open("example-file", "rb")) }
payload = {
"dataTypeId": "<string>",
"hubId": "<string>"
}
headers = {"Authorization": "Bearer <token>"}
response = requests.post(url, data=payload, files=files, headers=headers)
print(response.text)const form = new FormData();
form.append('file', '<string>');
form.append('dataTypeId', '<string>');
form.append('hubId', '<string>');
const options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};
options.body = form;
fetch('https://apiweb.mile.app/api/v3/data/import', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://apiweb.mile.app/api/v3/data/import",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"dataTypeId\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"hubId\"\r\n\r\n<string>\r\n-----011000010111000001101001--",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: multipart/form-data; boundary=---011000010111000001101001"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://apiweb.mile.app/api/v3/data/import"
payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"dataTypeId\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"hubId\"\r\n\r\n<string>\r\n-----011000010111000001101001--")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "multipart/form-data; boundary=---011000010111000001101001")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://apiweb.mile.app/api/v3/data/import")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "multipart/form-data; boundary=---011000010111000001101001")
.body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"dataTypeId\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"hubId\"\r\n\r\n<string>\r\n-----011000010111000001101001--")
.asString();require 'uri'
require 'net/http'
url = URI("https://apiweb.mile.app/api/v3/data/import")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'multipart/form-data; boundary=---011000010111000001101001'
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"dataTypeId\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"hubId\"\r\n\r\n<string>\r\n-----011000010111000001101001--"
response = http.request(request)
puts response.read_body{
"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@mile.app",
"createdTime": "2024-03-18 10:30:45",
"updatedTime": "2024-03-18 10:30:45"
}
}{
"status": false,
"message": "The file field is required.",
"failedCode": "import-001"
}{
"status": false,
"message": "Unauthorized",
"failedCode": "auth-001"
}{
"status": false,
"message": "You do not have permission to perform this action",
"failedCode": "auth-003"
}{
"status": false,
"message": "The file must be a file of type: csv, xls, xlsx.",
"failedCode": "import-002"
}{
"status": false,
"message": "Internal server error",
"failedCode": "import-045"
}Authorizations
Use a valid Bearer token to authenticate.
Body
The file containing data to import. Supported formats: CSV, XLS, XLSX. Maximum file size: 20MB.
Example: datasource_import.xlsx
The identifier for the data type. Required for datasource import type. Use GET /data-types API to get the list of Data Type IDs.
Example: 63db2fb476bc679c540369c4
The identifier for the hub. Required if the data type has commonData set to false (hub-specific data). Use GET /hubs API to get the list of Hub IDs.
Example: 63c63ab1b6972d3150348172