TrackMe API Docs
Getting started

Auth & Tokens

How to obtain a Bearer access token, send it on every call, and revoke it on logout.

This is the getting-started primer for authenticating against the TrackMe API. It covers the one thing you must get right before any other endpoint works: the opaque Bearer access token (prefix oat_). For the full catalogue of auth endpoints (OTP, password reset, email verification, social link/unlink, refresh rotation), read the Authentication flow — this page is the short version.

Every authenticated call under /api/v1/* sends the token in one header:

Authorization: Bearer oat_01jq8z4ay9k2m4p6r8t0v2x4z6

Password registration creates a pending account. SMS verification through /auth/verify-otp activates it and issues session tokens; pending accounts cannot sign in through another method.

Updated clients send X-Auth-Flow: sms-otp when registering; this flow returns no tokens. /auth/verify-otp returns a 15-minute access token and 30-day refresh token. Rotate that pair through /auth/token/refresh. Existing login, social and generic OTP sign-in return a 30-day access token. During temporary AUTH_LEGACY_REGISTRATION_ENABLED compatibility, unversioned clients and app versions up to 1.1.8+24 retain optional phone/city/country and receive data.accessToken immediately. Versions 1.1.9 and newer require SMS. Disable compatibility after the new store build ships.

End-to-end sequence

Step 1 — Get a token (pick ONE entry point)

Choose the appropriate flow:

  • Password register — POST /api/v1/auth/register with name, email, unique E.164 phone, password, country and canonical city, then /auth/verify-otp with { emailOrPhone, code, channel: "sms" }. Load supported values from /locations/countries and /locations/countries/{code}/cities.
  • Password login — POST /api/v1/auth/login
  • Social — POST /api/v1/auth/social/google or POST /api/v1/auth/social/apple (your app does the native handshake, then POSTs the provider JWT)
  • Passwordless OTP — POST /api/v1/auth/otp/send then POST /api/v1/auth/otp/verify with purpose: "sign_in" (the verify response carries user + accessToken)

Step 2 — Store the token in the keychain

Persist data.accessToken securely. It is opaque — never parse it; just store and replay it.

Step 3 — Send it on every authenticated call

Add Authorization: Bearer <oat_...> to every request to /api/v1/me/*, /api/v1/owner/*, and any other guarded endpoint. Public endpoints (/trucks/search, /trucks/:id, /categories, /currencies) need no token.

Step 4 — Sign out

POST /api/v1/auth/logout revokes only the calling token. Other devices stay signed in. After logout, that token is unusable — go back to Step 1.

All responses use the standard envelope:

{ "data": { "...": "..." }, "meta": { "requestId": "req_..." } }
{ "error": { "code": "AUTH_REQUIRED", "message": "..." }, "meta": { "requestId": "req_..." } }

Where tokens come from

SMS-flow registration returns a pending user; completing verification issues tokens. Temporary store compatibility returns an active user and access token. Existing sign-in flows remain available for active accounts.

FlowEndpointReturns
Password registerPOST /api/v1/auth/registerSMS flow: { user, ownerBusinessProfile, verification }; temporary legacy flow: { user, ownerBusinessProfile, accessToken }; status 201
Registration SMSPOST /api/v1/auth/verify-otp{ user, token, accessToken, refreshToken, accessTokenExpiresAt, refreshTokenExpiresAt }, status 200
Password loginPOST /api/v1/auth/login{ user, accessToken }, status 200
Social (Google/Apple)POST /api/v1/auth/social/{google,apple}{ user, accessToken }, status 200
OTP sign-inPOST /api/v1/auth/otp/verify (purpose: "sign_in"){ verified, user, accessToken }, status 200

Register

POST /api/v1/auth/register
Content-Type: application/json
Accept-Language: en
X-Auth-Flow: sms-otp

{
  "fullName": "Khalid Al-Saud",
  "email": "[email protected]",
  "password": "StrongPass123!",
  "phone": "+966555012345",
  "country": "SA",
  "city": "Riyadh",
  "requestedTypes": ["customer"],
  "acceptedTermsVersion": "2026-04"
}
{
  "data": {
    "user": { "id": "usr_...", "email": "[email protected]", "status": "pending_verification", "isVerified": false, "types": ["customer"] },
    "ownerBusinessProfile": null,
    "verification": { "channel": "sms", "destination": "+966555012345", "expiresAt": "2026-10-20T12:10:00Z", "resendAvailableAt": "2026-10-20T12:01:00Z" }
  },
  "meta": { "requestId": "req_..." }
}

Login

POST /api/v1/auth/login
Content-Type: application/json

{ "email": "[email protected]", "password": "StrongPass123!" }
{
  "data": {
    "user": { "id": "usr_...", "status": "active", "types": ["customer"] },
    "accessToken": "oat_01jq8z4ay9k2m4p6r8t0v2x4z6"
  },
  "meta": { "requestId": "req_..." }
}

Unknown email and wrong password both return 401 INVALID_CREDENTIALS (anti-enumeration). The full request bodies, validation rules, social JWKS verification, and OTP details live in the Authentication flow.


Sending the token

Put the token in the Authorization header on every guarded request. Example: fetch your own profile.

GET /api/v1/me
Authorization: Bearer oat_01jq8z4ay9k2m4p6r8t0v2x4z6
Accept-Language: ar
X-Timezone: Asia/Riyadh
  • Miss or malform the header on a guarded route → 401 AUTH_REQUIRED.
  • Hold a valid token but lack the required membership (e.g. an /api/v1/owner/* route without an active owner type) → 403 FORBIDDEN.
  • The token is sent as-is — it is not a JWT. Do not decode it; the server resolves it server-side.

Locale and timezone ride alongside the token: Accept-Language: ar switches error/notification/email copy to Arabic (default en; persisted as the user's preferred language on the first authenticated request). X-Timezone: Asia/Riyadh (IANA) sets server-rendered display strings. Wire timestamps always stay UTC ISO-8601 with a Z suffix.


Guest vs full accounts

A guest token is not a real token. POST /api/v1/auth/guest returns a client-side hint string, never stored server-side, that fails the Bearer guard if you send it as Authorization.

POST /api/v1/auth/guest
{
  "data": { "anonymousToken": "guest_01J...", "capabilities": ["observe"] },
  "meta": { "requestId": "req_..." }
}
GuestFull account
What you holdguest_<ULID> string, capabilities: ["observe"]oat_... Bearer token
Works as Authorization?No — rejected by the guardYes
What you can callPublic endpoints only (/trucks/search, /trucks/:id, /categories, /currencies) — which are anonymous anywayPublic + authenticated endpoints per membership
How you get itPOST /api/v1/auth/guestregister / login / social / OTP sign-in

Guest-mode constraints: (1) sending guest_<ULID> as a Bearer token returns 401; use it only as a read-only client-side intent flag. (2) Passing the guest token to /auth/register does not upgrade the session — there is no guest-upgrade path. Treat guest → account as a fresh registration.


Token lifecycle & revocation

A token lives until something explicitly revokes it. The three mutations differ in scope:

StateMeaningHow you got hereWhat's allowed next
Access token validUsable Bearer credentialIssued after successful sign-in or registration SMS verificationAuthenticated calls until expiry (15 minutes for a registration token pair; 30 days for existing sign-in flows)
This token revokedOnly the calling token is unusablePOST /api/v1/auth/logoutOther devices unaffected; this client must re-login
Other tokens revokedEvery device except the caller signed outPOST /api/v1/auth/password/changeThe calling client stays signed in
All tokens revokedEvery device signed outPOST /api/v1/auth/password/reset/completeEvery device, including this one, must re-login
Token expiredPast its expiry timestampTimeRotate a refresh token if available, or sign in again

Transitions

  • authenticated (this token) → this token revoked: POST /api/v1/auth/logout
  • known password → password changed + all OTHER tokens revoked (current kept alive): POST /api/v1/auth/password/change
  • forgot password → password reset + ALL tokens revoked (signed out everywhere): POST /api/v1/auth/password/reset/complete
POST /api/v1/auth/logout
Authorization: Bearer oat_01jq8z4ay9k2m4p6r8t0v2x4z6
{ "data": { "success": true }, "meta": { "requestId": "req_..." } }

Implementation Notes

Integration issueCorrect handling
Expecting a token from /auth/register.Finish /auth/verify-otp to obtain access and refresh tokens. Existing login/social/generic OTP return access tokens only.
Sending the guest guest_<ULID> string as a Bearer token.It fails the guard. Use it only as a client-side read-only hint; guest endpoints are anonymous anyway.
"Promoting" a guest by registering with the guest token.Not implemented. Treat guest → account as a fresh register.
Decoding the oat_ token client-side.It is opaque, not a JWT. Store and replay it verbatim.
Expecting logout to sign out all devices.It revokes only the calling token. Use password change (other devices) or reset/complete (all devices) for broader revocation.
Expecting the current device to survive a password reset.reset/complete revokes ALL tokens — every device re-logs in. Use password/change (keeps the caller) when the user knows their old password.
Treating a 403 as an auth failure.403 FORBIDDEN means the token is valid but lacks the membership for that route (e.g. /owner/* without an owner type). 401 AUTH_REQUIRED is the missing/invalid-token case.

On this page