Exchange authorization code for user info
curl --request POST \
--url https://api.maxcare.ai/v4/oauth/token \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'X-Organization-Id: <x-organization-id>' \
--data '
{
"grant_type": "authorization_code",
"code": "d4d9cccb37643c5913fe649d1880889a...",
"redirect_uri": "https://myapp.com/auth/callback"
}
'import requests
url = "https://api.maxcare.ai/v4/oauth/token"
payload = {
"grant_type": "authorization_code",
"code": "d4d9cccb37643c5913fe649d1880889a...",
"redirect_uri": "https://myapp.com/auth/callback"
}
headers = {
"X-Organization-Id": "<x-organization-id>",
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'X-Organization-Id': '<x-organization-id>',
Authorization: 'Bearer <token>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
grant_type: 'authorization_code',
code: 'd4d9cccb37643c5913fe649d1880889a...',
redirect_uri: 'https://myapp.com/auth/callback'
})
};
fetch('https://api.maxcare.ai/v4/oauth/token', 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://api.maxcare.ai/v4/oauth/token",
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([
'grant_type' => 'authorization_code',
'code' => 'd4d9cccb37643c5913fe649d1880889a...',
'redirect_uri' => 'https://myapp.com/auth/callback'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json",
"X-Organization-Id: <x-organization-id>"
],
]);
$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://api.maxcare.ai/v4/oauth/token"
payload := strings.NewReader("{\n \"grant_type\": \"authorization_code\",\n \"code\": \"d4d9cccb37643c5913fe649d1880889a...\",\n \"redirect_uri\": \"https://myapp.com/auth/callback\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-Organization-Id", "<x-organization-id>")
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://api.maxcare.ai/v4/oauth/token")
.header("X-Organization-Id", "<x-organization-id>")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"grant_type\": \"authorization_code\",\n \"code\": \"d4d9cccb37643c5913fe649d1880889a...\",\n \"redirect_uri\": \"https://myapp.com/auth/callback\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.maxcare.ai/v4/oauth/token")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-Organization-Id"] = '<x-organization-id>'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"grant_type\": \"authorization_code\",\n \"code\": \"d4d9cccb37643c5913fe649d1880889a...\",\n \"redirect_uri\": \"https://myapp.com/auth/callback\"\n}"
response = http.request(request)
puts response.read_body{
"id_token": "eyJhbGciOiJFUzI1NiIs...",
"user": {
"id": "usr_1231b6f32b4f4b8f8eeb4f7806bc45b0",
"email": "jane@clinic.com",
"firstName": "Jane",
"lastName": "Doe",
"imageUrl": "https://img.clerk.com/..."
},
"authorizedOrganizations": [
{
"id": "org_7e2c8cfeb7a94deb986de7012589e72b",
"name": "Dermatology Clinic",
"facilities": [
{
"id": "fac_a1b2c3d4e5f67890abcdef1234567890",
"name": "Main Office",
"address": "123 Main St, Austin, TX 78701"
}
],
"role": "admin"
}
]
}{
"error": "invalid_grant",
"error_description": "Authorization code has expired"
}{
"error": "invalid_grant",
"error_description": "Authorization code has expired"
}OAuth
Exchange authorization code for user info
Exchanges an OAuth 2.0 authorization code for an OIDC id_token and user context. Authenticate with your app’s API key in the Authorization header. No X-Organization-Id header required. Errors follow OAuth 2.0 spec format (RFC 6749).
POST
/
oauth
/
token
Exchange authorization code for user info
curl --request POST \
--url https://api.maxcare.ai/v4/oauth/token \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'X-Organization-Id: <x-organization-id>' \
--data '
{
"grant_type": "authorization_code",
"code": "d4d9cccb37643c5913fe649d1880889a...",
"redirect_uri": "https://myapp.com/auth/callback"
}
'import requests
url = "https://api.maxcare.ai/v4/oauth/token"
payload = {
"grant_type": "authorization_code",
"code": "d4d9cccb37643c5913fe649d1880889a...",
"redirect_uri": "https://myapp.com/auth/callback"
}
headers = {
"X-Organization-Id": "<x-organization-id>",
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'X-Organization-Id': '<x-organization-id>',
Authorization: 'Bearer <token>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
grant_type: 'authorization_code',
code: 'd4d9cccb37643c5913fe649d1880889a...',
redirect_uri: 'https://myapp.com/auth/callback'
})
};
fetch('https://api.maxcare.ai/v4/oauth/token', 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://api.maxcare.ai/v4/oauth/token",
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([
'grant_type' => 'authorization_code',
'code' => 'd4d9cccb37643c5913fe649d1880889a...',
'redirect_uri' => 'https://myapp.com/auth/callback'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json",
"X-Organization-Id: <x-organization-id>"
],
]);
$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://api.maxcare.ai/v4/oauth/token"
payload := strings.NewReader("{\n \"grant_type\": \"authorization_code\",\n \"code\": \"d4d9cccb37643c5913fe649d1880889a...\",\n \"redirect_uri\": \"https://myapp.com/auth/callback\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-Organization-Id", "<x-organization-id>")
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://api.maxcare.ai/v4/oauth/token")
.header("X-Organization-Id", "<x-organization-id>")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"grant_type\": \"authorization_code\",\n \"code\": \"d4d9cccb37643c5913fe649d1880889a...\",\n \"redirect_uri\": \"https://myapp.com/auth/callback\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.maxcare.ai/v4/oauth/token")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-Organization-Id"] = '<x-organization-id>'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"grant_type\": \"authorization_code\",\n \"code\": \"d4d9cccb37643c5913fe649d1880889a...\",\n \"redirect_uri\": \"https://myapp.com/auth/callback\"\n}"
response = http.request(request)
puts response.read_body{
"id_token": "eyJhbGciOiJFUzI1NiIs...",
"user": {
"id": "usr_1231b6f32b4f4b8f8eeb4f7806bc45b0",
"email": "jane@clinic.com",
"firstName": "Jane",
"lastName": "Doe",
"imageUrl": "https://img.clerk.com/..."
},
"authorizedOrganizations": [
{
"id": "org_7e2c8cfeb7a94deb986de7012589e72b",
"name": "Dermatology Clinic",
"facilities": [
{
"id": "fac_a1b2c3d4e5f67890abcdef1234567890",
"name": "Main Office",
"address": "123 Main St, Austin, TX 78701"
}
],
"role": "admin"
}
]
}{
"error": "invalid_grant",
"error_description": "Authorization code has expired"
}{
"error": "invalid_grant",
"error_description": "Authorization code has expired"
}Authorizations
Marketplace API key
Headers
Target clinic organization ID
Body
application/json
Must be 'authorization_code'
Example:
"authorization_code"
The authorization code received from the callback
Example:
"d4d9cccb37643c5913fe649d1880889a..."
Must match the redirect_uri used in the authorize request
Example:
"https://myapp.com/auth/callback"
