Switch Organization
curl --request POST \
--url https://apiweb.mile.app/api/v3/organization/switch \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"targetUserId": "507f1f77bcf86cd799439012"
}
'import requests
url = "https://apiweb.mile.app/api/v3/organization/switch"
payload = { "targetUserId": "507f1f77bcf86cd799439012" }
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({targetUserId: '507f1f77bcf86cd799439012'})
};
fetch('https://apiweb.mile.app/api/v3/organization/switch', 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/switch",
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([
'targetUserId' => '507f1f77bcf86cd799439012'
]),
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/switch"
payload := strings.NewReader("{\n \"targetUserId\": \"507f1f77bcf86cd799439012\"\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/switch")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"targetUserId\": \"507f1f77bcf86cd799439012\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://apiweb.mile.app/api/v3/organization/switch")
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 \"targetUserId\": \"507f1f77bcf86cd799439012\"\n}"
response = http.request(request)
puts response.read_body{
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9...",
"expires_in": 31536000,
"data": {
"_id": "507f1f77bcf86cd799439012",
"name": "John Doe",
"email": "john@example.com",
"organizationId": "507f1f77bcf86cd799439023"
},
"isHubSet": true,
"organizations": [
{
"userId": "507f1f77bcf86cd799439011",
"organizationId": "507f1f77bcf86cd799439022",
"organizationName": "Acme Corp",
"organizationLogo": "https://storage.mile.app/logos/acme.png",
"roleName": "owner",
"isCurrent": false
},
{
"userId": "507f1f77bcf86cd799439012",
"organizationId": "507f1f77bcf86cd799439023",
"organizationName": "Beta Inc",
"organizationLogo": null,
"roleName": "admin",
"isCurrent": true
}
]
}{
"status": false,
"message": "Account is not active"
}{
"status": false,
"message": "Invalid organization selection"
}Multi-Organization
Switch Organization
Switch to a different organization that the user belongs to. This endpoint revokes the current token and generates a new access token for the target organization.
Requirements:
- User must be authenticated
- Target user must belong to the same email as current user
- Target organization must be active
Note: After switching, the previous access token is revoked. You must use the new token returned in the response.
POST
/
organization
/
switch
Switch Organization
curl --request POST \
--url https://apiweb.mile.app/api/v3/organization/switch \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"targetUserId": "507f1f77bcf86cd799439012"
}
'import requests
url = "https://apiweb.mile.app/api/v3/organization/switch"
payload = { "targetUserId": "507f1f77bcf86cd799439012" }
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({targetUserId: '507f1f77bcf86cd799439012'})
};
fetch('https://apiweb.mile.app/api/v3/organization/switch', 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/switch",
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([
'targetUserId' => '507f1f77bcf86cd799439012'
]),
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/switch"
payload := strings.NewReader("{\n \"targetUserId\": \"507f1f77bcf86cd799439012\"\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/switch")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"targetUserId\": \"507f1f77bcf86cd799439012\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://apiweb.mile.app/api/v3/organization/switch")
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 \"targetUserId\": \"507f1f77bcf86cd799439012\"\n}"
response = http.request(request)
puts response.read_body{
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9...",
"expires_in": 31536000,
"data": {
"_id": "507f1f77bcf86cd799439012",
"name": "John Doe",
"email": "john@example.com",
"organizationId": "507f1f77bcf86cd799439023"
},
"isHubSet": true,
"organizations": [
{
"userId": "507f1f77bcf86cd799439011",
"organizationId": "507f1f77bcf86cd799439022",
"organizationName": "Acme Corp",
"organizationLogo": "https://storage.mile.app/logos/acme.png",
"roleName": "owner",
"isCurrent": false
},
{
"userId": "507f1f77bcf86cd799439012",
"organizationId": "507f1f77bcf86cd799439023",
"organizationName": "Beta Inc",
"organizationLogo": null,
"roleName": "admin",
"isCurrent": true
}
]
}{
"status": false,
"message": "Account is not active"
}{
"status": false,
"message": "Invalid organization selection"
}Authorizations
Use a valid Bearer token to authenticate.
Body
application/json
The user ID to switch to. This can be obtained from the organizations array returned by Get User Organizations endpoint.
Response
Switch successful - returns new access token and user data
New access token for the target organization
Token expiration time in seconds
User data for the target organization
Whether user has hub assigned in the target organization
Updated list of all user's organizations
Show child attributes
Show child attributes
⌘I