Create Organization
curl --request POST \
--url https://apiweb.mile.app/api/v3/organization \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"organizationName": "My New Company",
"hubName": "Main Warehouse",
"hubLat": -6.2088,
"hubLng": 106.8456,
"copyDataFromFirstOrg": false
}
'import requests
url = "https://apiweb.mile.app/api/v3/organization"
payload = {
"organizationName": "My New Company",
"hubName": "Main Warehouse",
"hubLat": -6.2088,
"hubLng": 106.8456,
"copyDataFromFirstOrg": False
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
organizationName: 'My New Company',
hubName: 'Main Warehouse',
hubLat: -6.2088,
hubLng: 106.8456,
copyDataFromFirstOrg: false
})
};
fetch('https://apiweb.mile.app/api/v3/organization', 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/organization",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'organizationName' => 'My New Company',
'hubName' => 'Main Warehouse',
'hubLat' => -6.2088,
'hubLng' => 106.8456,
'copyDataFromFirstOrg' => false
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$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/organization"
payload := strings.NewReader("{\n \"organizationName\": \"My New Company\",\n \"hubName\": \"Main Warehouse\",\n \"hubLat\": -6.2088,\n \"hubLng\": 106.8456,\n \"copyDataFromFirstOrg\": false\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
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/organization")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"organizationName\": \"My New Company\",\n \"hubName\": \"Main Warehouse\",\n \"hubLat\": -6.2088,\n \"hubLng\": 106.8456,\n \"copyDataFromFirstOrg\": false\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://apiweb.mile.app/api/v3/organization")
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"] = 'application/json'
request.body = "{\n \"organizationName\": \"My New Company\",\n \"hubName\": \"Main Warehouse\",\n \"hubLat\": -6.2088,\n \"hubLng\": 106.8456,\n \"copyDataFromFirstOrg\": false\n}"
response = http.request(request)
puts response.read_body{
"status": true,
"message": "Organization created successfully",
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9...",
"expires_in": 31536000,
"data": {
"_id": "507f1f77bcf86cd799439099",
"name": "John Doe",
"email": "[email protected]",
"organizationId": "507f1f77bcf86cd799439100",
"hubId": [
"507f1f77bcf86cd799439102"
]
},
"isHubSet": true,
"organizations": [
{
"userId": "507f1f77bcf86cd799439011",
"organizationId": "507f1f77bcf86cd799439022",
"organizationName": "Acme Corp",
"organizationLogo": null,
"roleName": "owner",
"isCurrent": false
},
{
"userId": "507f1f77bcf86cd799439099",
"organizationId": "507f1f77bcf86cd799439100",
"organizationName": "My New Company",
"organizationLogo": null,
"roleName": "owner",
"isCurrent": true
}
]
}{
"status": false,
"message": "Hub name is required when you have no existing organization"
}{
"status": false,
"message": "You do not have permission to create a new organization. Please contact your administrator."
}Switching Organization
Create Organization
Create a new organization and automatically switch to it. The user becomes the owner of the new organization.
Requirements:
- User must be authenticated
- User must have
create/organizationpermission
Behavior:
- If user has an existing owned organization with hubs, hub fields are optional (will copy from source)
- If user has no owned organization, hub fields (hubName, hubLat, hubLng) are required
- If
copyDataFromFirstOrgis true, copies configuration, hubs, and flows from user’s first owned organization - Creates default flows from templates
- Generates sample data (vehicles, data sources, tasks) via background job
Note: After creation, the previous access token is revoked. You must use the new token returned in the response.
POST
/
organization
Create Organization
curl --request POST \
--url https://apiweb.mile.app/api/v3/organization \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"organizationName": "My New Company",
"hubName": "Main Warehouse",
"hubLat": -6.2088,
"hubLng": 106.8456,
"copyDataFromFirstOrg": false
}
'import requests
url = "https://apiweb.mile.app/api/v3/organization"
payload = {
"organizationName": "My New Company",
"hubName": "Main Warehouse",
"hubLat": -6.2088,
"hubLng": 106.8456,
"copyDataFromFirstOrg": False
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
organizationName: 'My New Company',
hubName: 'Main Warehouse',
hubLat: -6.2088,
hubLng: 106.8456,
copyDataFromFirstOrg: false
})
};
fetch('https://apiweb.mile.app/api/v3/organization', 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/organization",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'organizationName' => 'My New Company',
'hubName' => 'Main Warehouse',
'hubLat' => -6.2088,
'hubLng' => 106.8456,
'copyDataFromFirstOrg' => false
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$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/organization"
payload := strings.NewReader("{\n \"organizationName\": \"My New Company\",\n \"hubName\": \"Main Warehouse\",\n \"hubLat\": -6.2088,\n \"hubLng\": 106.8456,\n \"copyDataFromFirstOrg\": false\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
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/organization")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"organizationName\": \"My New Company\",\n \"hubName\": \"Main Warehouse\",\n \"hubLat\": -6.2088,\n \"hubLng\": 106.8456,\n \"copyDataFromFirstOrg\": false\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://apiweb.mile.app/api/v3/organization")
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"] = 'application/json'
request.body = "{\n \"organizationName\": \"My New Company\",\n \"hubName\": \"Main Warehouse\",\n \"hubLat\": -6.2088,\n \"hubLng\": 106.8456,\n \"copyDataFromFirstOrg\": false\n}"
response = http.request(request)
puts response.read_body{
"status": true,
"message": "Organization created successfully",
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9...",
"expires_in": 31536000,
"data": {
"_id": "507f1f77bcf86cd799439099",
"name": "John Doe",
"email": "[email protected]",
"organizationId": "507f1f77bcf86cd799439100",
"hubId": [
"507f1f77bcf86cd799439102"
]
},
"isHubSet": true,
"organizations": [
{
"userId": "507f1f77bcf86cd799439011",
"organizationId": "507f1f77bcf86cd799439022",
"organizationName": "Acme Corp",
"organizationLogo": null,
"roleName": "owner",
"isCurrent": false
},
{
"userId": "507f1f77bcf86cd799439099",
"organizationId": "507f1f77bcf86cd799439100",
"organizationName": "My New Company",
"organizationLogo": null,
"roleName": "owner",
"isCurrent": true
}
]
}{
"status": false,
"message": "Hub name is required when you have no existing organization"
}{
"status": false,
"message": "You do not have permission to create a new organization. Please contact your administrator."
}Body
application/json
Whether to copy data from user's first organization where they have 'owner' role. When enabled, copies: (1) Organization configuration (language, currency, settings), (2) All hubs the user has access to, (3) Custom roles with system permissions only (custom module permissions are excluded), (4) All flows. Note: Default roles (owner, admin, planner, field user) always use standard templates regardless of this setting.
Response
Organization created successfully - returns new access token and user data