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/v4/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/v4/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/v4/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/v4/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/v4/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/v4/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@example.com",
"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
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.
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/v4/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/v4/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/v4/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/v4/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/v4/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/v4/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@example.com",
"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"
}Body
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