Create User Token
curl --request POST \
--url https://api.example.com/api/v1/users/{user_id}/token \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"app_id": "<string>",
"app_secret": "<string>"
}
'import requests
url = "https://api.example.com/api/v1/users/{user_id}/token"
payload = {
"app_id": "<string>",
"app_secret": "<string>"
}
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({app_id: '<string>', app_secret: '<string>'})
};
fetch('https://api.example.com/api/v1/users/{user_id}/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.example.com/api/v1/users/{user_id}/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([
'app_id' => '<string>',
'app_secret' => '<string>'
]),
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://api.example.com/api/v1/users/{user_id}/token"
payload := strings.NewReader("{\n \"app_id\": \"<string>\",\n \"app_secret\": \"<string>\"\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://api.example.com/api/v1/users/{user_id}/token")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"app_id\": \"<string>\",\n \"app_secret\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/api/v1/users/{user_id}/token")
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 \"app_id\": \"<string>\",\n \"app_secret\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"access_token": "<string>",
"token_type": "bearer",
"refresh_token": "<string>",
"expires_in": 123,
"password_change": "required"
}{
"code": "VALIDATION_ERROR",
"detail": "body.email: value is not a valid email address: An email address must have an @-sign. (and 1 more)",
"errors": [
{
"loc": [
"body",
"email"
],
"msg": "value is not a valid email address: An email address must have an @-sign.",
"type": "value_error"
},
{
"loc": [
"body",
"first_name"
],
"msg": "String should have at most 100 characters",
"type": "string_too_long"
}
],
"status": 422,
"title": "Unprocessable Content"
}{
"code": "NOT_FOUND",
"detail": "User with ID: 123e4567-e89b-12d3-a456-426614174000 not found.",
"status": 404,
"title": "Not Found"
}{
"code": "NOT_FOUND",
"detail": "User with ID: 123e4567-e89b-12d3-a456-426614174000 not found.",
"status": 404,
"title": "Not Found"
}Mobile SDK
Create User Token
Exchange app credentials or admin auth for user-scoped access token.
Supports two authentication methods:
- App credentials: Provide app_id and app_secret in the request body
- Admin authentication: Authenticate as a developer/admin via Bearer token (app_id and app_secret can be omitted)
Both methods return access_token with refresh_token.
Returns a JWT token scoped to SDK endpoints only. Tokens expire after configured time (default: 60 minutes).
Args: user_id: OpenWearables User ID (UUID) payload: Optional application credentials (app_id, app_secret) db: Database session developer: Optional authenticated developer (from Bearer token)
Returns: TokenResponse containing access_token, token_type, and refresh_token
Raises: 401: If app credentials are invalid or admin auth is missing 400: If neither app credentials nor admin auth is provided
POST
/
api
/
v1
/
users
/
{user_id}
/
token
Create User Token
curl --request POST \
--url https://api.example.com/api/v1/users/{user_id}/token \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"app_id": "<string>",
"app_secret": "<string>"
}
'import requests
url = "https://api.example.com/api/v1/users/{user_id}/token"
payload = {
"app_id": "<string>",
"app_secret": "<string>"
}
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({app_id: '<string>', app_secret: '<string>'})
};
fetch('https://api.example.com/api/v1/users/{user_id}/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.example.com/api/v1/users/{user_id}/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([
'app_id' => '<string>',
'app_secret' => '<string>'
]),
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://api.example.com/api/v1/users/{user_id}/token"
payload := strings.NewReader("{\n \"app_id\": \"<string>\",\n \"app_secret\": \"<string>\"\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://api.example.com/api/v1/users/{user_id}/token")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"app_id\": \"<string>\",\n \"app_secret\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/api/v1/users/{user_id}/token")
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 \"app_id\": \"<string>\",\n \"app_secret\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"access_token": "<string>",
"token_type": "bearer",
"refresh_token": "<string>",
"expires_in": 123,
"password_change": "required"
}{
"code": "VALIDATION_ERROR",
"detail": "body.email: value is not a valid email address: An email address must have an @-sign. (and 1 more)",
"errors": [
{
"loc": [
"body",
"email"
],
"msg": "value is not a valid email address: An email address must have an @-sign.",
"type": "value_error"
},
{
"loc": [
"body",
"first_name"
],
"msg": "String should have at most 100 characters",
"type": "string_too_long"
}
],
"status": 422,
"title": "Unprocessable Content"
}{
"code": "NOT_FOUND",
"detail": "User with ID: 123e4567-e89b-12d3-a456-426614174000 not found.",
"status": 404,
"title": "Not Found"
}{
"code": "NOT_FOUND",
"detail": "User with ID: 123e4567-e89b-12d3-a456-426614174000 not found.",
"status": 404,
"title": "Not Found"
}Authorizations
Body
application/json
Response
Successful Response
Token response with optional refresh token.
Was this page helpful?