Profile & Preferences
How a signed-in customer reads and edits their own profile, sets preferences and an avatar, runs the four-step verified email/phone change, and self-grants user types.
This is the authenticated user's self-service surface, rooted at /api/v1/me/*. Every endpoint requires a Bearer access token (oat_...) — the whole route group sits behind middleware.auth({ guards: ['api'] }), so an anonymous call returns 401 AUTH_REQUIRED. There are no public profile endpoints.
It covers five concerns:
- Core profile — read/edit your record (
GET /api/v1/me,PATCH /api/v1/me) plus your review history (GET /api/v1/me/reviews). - Preferences — discovery prefs (
PATCH /api/v1/me/preferences) and notification toggles (PATCH /api/v1/me/settings). - Avatar — pin a previously-uploaded file (
POST /api/v1/me/avatar). - Verified contact change — a four-call OTP dance for email and another for phone.
- Capabilities — list and self-grant user types (
GET /api/v1/me/types,POST /api/v1/me/types/:type/request).
Auth & headers on every call: Authorization: Bearer <oat_...>. Send Accept-Language: ar for Arabic copy (the header is persisted as your preferred language on the first authenticated request). Read meta.requestId from each response for support/tracing. All wire timestamps are UTC ISO-8601 with a trailing Z.
Response envelope is always one of:
{
"data": {
/* payload */
},
"meta": { "requestId": "req_01..." }
}{ "error": { "code": "AUTH_REQUIRED", "message": "..." }, "meta": { "requestId": "req_01..." } }Two creates leave you with a verified value; everything else is direct and unverified — and one "create" needs FOUR calls.
- Editing
phoneviaPATCH /api/v1/mewritesuser.phoneimmediately, with no OTP and without settingphoneVerifiedAt. The only way to get a verified phone (or to change email at all) is the four-step/me/phone-change/*(or/me/email-change/*) flow:start → confirm-current → request-new → confirm-new. There is no two-call shortcut. - A user-type grant (
POST /api/v1/me/types/:type/request) is the opposite surprise: it is active on the spot — there is no pending/approval state. Do not build a "pending owner" UI.
The flow at a glance
These are the two multi-step procedures in the profile domain. The simple reads/writes (GET /me, PATCH /me, preferences, settings, avatar, types) are single calls and are detailed below the lifecycle section.
Verified email/phone change (FOUR sequential calls)
Step 1 — start
POST /api/v1/me/email-change/start (or /me/phone-change/start). No body. Sends a 6-digit OTP to your current contact and returns challenge metadata (challengeId, destination, channel, expiresAt, resendAvailableAt).
Step 2 — confirm-current
POST .../confirm-current with { "code": "123456" }. Verifies the current-side OTP. This verified challenge IS the change session — it opens a 10-minute window. The response returns sessionExpiresAt = now + 10 min; surface a countdown from it.
Step 3 — request-new
POST .../request-new with { "newEmail": "..." } (or { "newPhone": "..." }). Requires the step-2 session still valid (else 409 INVALID_CHANGE_SESSION). Validates the new value is different and not taken, then OTPs it.
Step 4 — confirm-new
POST .../confirm-new with { "code": "...", "newEmail": "..." } (or newPhone). Re-checks the session is still valid, re-checks uniqueness, verifies the new-side OTP, and commits the change in one transaction — setting the value plus emailVerifiedAt / phoneVerifiedAt. Returns the new value + its verifiedAt.
Become an owner / job seeker (ONE call, immediate)
Step 1 — request the type
POST /api/v1/me/types/owner/request with an optional ownerProfile body. The membership is status: "active" immediately — a follow-up GET /api/v1/me reflects it with no waiting and no approval.
Core profile
GET /api/v1/me — hydrate the profile screen
Returns { user, ownerBusinessProfile }. user.types is the list of active, non-revoked membership strings. user.avatar is a resolved { thumb, medium, original } URL set or null; avatarFileId is the fil_ id or null. ownerBusinessProfile is null unless you hold an owner membership with a business profile.
GET /api/v1/me HTTP/1.1
Authorization: Bearer oat_abc123
Accept-Language: en{
"data": {
"user": {
"id": "usr_01...",
"fullName": "Khalid Al-Saud",
"email": "[email protected]",
"phone": "+966555012345",
"avatarFileId": "fil_01jq8z4c0e3p5q7r9s2t4w6x8z",
"avatar": {
"thumb": "https://.../thumb.jpg",
"medium": "https://.../medium.jpg",
"original": "https://.../original.jpg"
},
"city": "Riyadh",
"country": "SA",
"status": "active",
"types": ["customer", "owner"],
"preferences": { "cuisines": ["burgers", "coffee"], "language": "en" },
"notificationPrefs": { "order": true, "payment": true, "promotion": false, "chat": true },
"language": "en",
"createdAt": "2026-01-04T08:12:00.000Z",
"updatedAt": "2026-06-21T10:00:00.000Z"
},
"ownerBusinessProfile": {
"id": "obp_01...",
"businessName": "Crispy Cart Co.",
"ownerFullName": "Khalid Al-Saud",
"businessEmail": "[email protected]",
"phone": "+966555012345",
"city": "Riyadh",
"country": "SA",
"verificationStatus": "not_required_for_mvp",
"trucksOwnedCount": 0
}
},
"meta": { "requestId": "req_01..." }
}PATCH /api/v1/me — edit basics (partial update)
Only the keys you send are applied. Fields: fullName, phone, city, country (2-letter code), language ('en' | 'ar'). Returns the same shape as GET /api/v1/me. 422 VALIDATION_ERROR on bad input.
PATCH /api/v1/me HTTP/1.1
Authorization: Bearer oat_abc123
Content-Type: application/json
{ "fullName": "Khalid A.", "city": "Jeddah" }PATCH /api/v1/me has no email field at all, and writing phone here is unverified —
it does not send an OTP and does not set phoneVerifiedAt. For a verified contact, use the
four-step change flow.
GET /api/v1/me/reviews — your review history (cursor-paginated)
Newest first. Query params: ?limit (1–50, default 20) and ?cursor. meta.pagination = { hasMore, nextCursor, limit }. Soft-deleted reviews are excluded.
GET /api/v1/me/reviews?limit=20 HTTP/1.1
Authorization: Bearer oat_abc123{
"data": {
"items": [
{
"id": "rev_01...",
"truck": { "id": "trk_01...", "name": "Crispy Cart", "image": "https://.../thumb.jpg" },
"rating": 5,
"comment": "Great shawarma.",
"images": [{ "thumb": "https://...", "medium": "https://...", "original": "https://..." }],
"createdAt": "2026-06-01T18:30:00.000Z"
}
]
},
"meta": {
"requestId": "req_01...",
"pagination": { "hasMore": true, "nextCursor": "eyJ...", "limit": 20 }
}
}Preferences & settings
PATCH /api/v1/me/preferences — discovery preferences
Body { cuisines?: string[] (≤20 items, each ≤40 chars), language?: 'en' | 'ar' }. Merge semantics — the payload is spread over the stored preferences object. If language is present it also updates top-level user.language. Returns { preferences, language }.
PATCH /api/v1/me/preferences HTTP/1.1
Authorization: Bearer oat_abc123
Content-Type: application/json
{ "cuisines": ["burgers", "coffee", "shawarma"], "language": "en" }{
"data": {
"preferences": { "cuisines": ["burgers", "coffee", "shawarma"], "language": "en" },
"language": "en"
},
"meta": { "requestId": "req_01..." }
}PATCH /api/v1/me/settings — notification preferences
Body { notificationPrefs?: object } — free-form, unknown keys allowed (e.g. order, payment, promotion, chat). Merge semantics — spread over the stored object. Returns { notificationPrefs }.
PATCH /api/v1/me/settings HTTP/1.1
Authorization: Bearer oat_abc123
Content-Type: application/json
{ "notificationPrefs": { "promotion": false } }Preferences and settings are merge, not replace. You cannot clear a cuisine or a notification key by omitting it — omitted keys are preserved as-is. Send the full desired array/object (or send the explicit value you want).
Avatar
POST /api/v1/me/avatar — pin an uploaded file
First upload bytes via POST /api/v1/uploads with purpose=avatar, then pass the returned fileId (5–40 chars) here. The server resolves the file row and verifies you own it before pinning. Raw image URLs are rejected. Returns { avatarFileId, avatar: { thumb, medium, original } }. 404 if the file id is unknown; 409 if it is not yours/valid; 422 on validation.
POST /api/v1/me/avatar HTTP/1.1
Authorization: Bearer oat_abc123
Content-Type: application/json
{ "fileId": "fil_01jq8z4c0e3p5q7r9s2t4w6x8z" }{
"data": {
"avatarFileId": "fil_01jq8z4c0e3p5q7r9s2t4w6x8z",
"avatar": {
"thumb": "https://.../thumb.jpg",
"medium": "https://.../medium.jpg",
"original": "https://.../original.jpg"
}
},
"meta": { "requestId": "req_01..." }
}Capabilities (user types)
Capabilities are additive memberships, not a single account mode stored on the server. Requesting owner does not remove customer; the response may contain both. “Switch account role” in the mobile UI should switch its local navigation/context after confirming the target membership exists — it must not delete or replace the other memberships.
GET /api/v1/me/types — list active memberships
Lighter than GET /api/v1/me — returns just { types: [{ type, status, grantedAt }] }. Only memberships with status: "active" and no revokedAt are returned. Use this for navigation/capability gating, not a cached value.
{
"data": {
"types": [{ "type": "customer", "status": "active", "grantedAt": "2026-01-04T08:12:00.000Z" }]
},
"meta": { "requestId": "req_01..." }
}POST /api/v1/me/types/:type/request — self-grant a type
:type must be one of customer, owner, job_seeker — anything else (e.g. admin tiers) returns 409 CONFLICT. The capability is granted immediately and additively as status: "active" — no approval step and no other membership is revoked. For :type=owner you may pass ownerProfile to create the business profile (only if one does not already exist; country/city fall back to the user's).
- First grant →
201 Created,{ "type": "owner", "status": "active" }. - Already held →
200 OK,{ "type": "owner", "status": "active", "already": true }(no-op).
POST /api/v1/me/types/owner/request HTTP/1.1
Authorization: Bearer oat_abc123
Content-Type: application/json
{
"ownerProfile": {
"businessName": "Crispy Cart Co.",
"ownerFullName": "Khalid Al-Saud",
"businessEmail": "[email protected]",
"phone": "+966555012345",
"city": "Riyadh",
"country": "SA"
}
}ownerBusinessProfile.verificationStatus is the fixed literal "not_required_for_mvp" — it is
not a real lifecycle. There is no owner KYC/approval gate in MVP. The user can act as an owner
the instant the 201 returns; the owner surfaces live at /api/v1/owner/*.
The verified contact-change flow in detail
Both email and phone follow the identical four-call shape. Phone differs only in: it requires a phone already on file (409 PROFILE_PHONE_MISSING on start/confirm-current otherwise), and the OTP channel is 'sms' (falls back to 'whatsapp'). Email's channel is 'email'. Both accept an optional ?locale on the start/request-new calls to localize the OTP message.
Step 1 — start
POST /api/v1/me/email-change/start HTTP/1.1
Authorization: Bearer oat_abc123{
"data": {
"challengeId": "otp_01...",
"destination": "[email protected]",
"channel": "email",
"expiresAt": "2026-06-21T10:10:00.000Z",
"resendAvailableAt": "2026-06-21T10:00:30.000Z"
},
"meta": { "requestId": "req_01..." }
}Step 2 — confirm-current (opens the 10-minute session)
POST /api/v1/me/email-change/confirm-current HTTP/1.1
Authorization: Bearer oat_abc123
Content-Type: application/json
{ "code": "123456" }{
"data": { "sessionVerified": true, "sessionExpiresAt": "2026-06-21T10:10:00.000Z" },
"meta": { "requestId": "req_01..." }
}409 on a bad/expired code; 422 on a malformed code.
Step 3 — request-new
POST /api/v1/me/email-change/request-new HTTP/1.1
Authorization: Bearer oat_abc123
Content-Type: application/json
{ "newEmail": "[email protected]" }Errors: 409 INVALID_CHANGE_SESSION (no recent verified current-side OTP), 409 PROFILE_EMAIL_UNCHANGED (equals current), 409 PROFILE_EMAIL_ALREADY_IN_USE (taken). Phone equivalents: PROFILE_PHONE_UNCHANGED, PROFILE_PHONE_ALREADY_IN_USE.
Step 4 — confirm-new (commits)
POST /api/v1/me/email-change/confirm-new HTTP/1.1
Authorization: Bearer oat_abc123
Content-Type: application/json
{ "code": "654321", "newEmail": "[email protected]" }{
"data": { "email": "[email protected]", "emailVerifiedAt": "2026-06-21T10:08:00.000Z" },
"meta": { "requestId": "req_01..." }
}Re-asserts the session is still valid (409 INVALID_CHANGE_SESSION) and re-checks uniqueness (409 PROFILE_EMAIL_ALREADY_IN_USE) before committing. The phone equivalent returns { phone, phoneVerifiedAt }.
Lifecycles
User-type membership
| State | Meaning | How you got here | What's allowed next |
|---|---|---|---|
active | Capability is live and usable now | POST /api/v1/me/types/:type/request — self-grant, no approval | Use the capability immediately; appears in user.types and GET /me/types |
revoked | Capability removed | An admin revoked it via team-management (outside /me) | Disappears from user.types / GET /me/types; re-request to get it back |
There is no pending/draft/approval state — active is the only state a self-grant produces.
Email / phone change session (implicit, OTP-backed)
| State | Meaning | How you got here | What's allowed next |
|---|---|---|---|
none | No change in progress | Initial / after commit / after expiry | start |
current-OTP-sent | OTP sitting in the current contact's inbox | start | confirm-current |
current-verified | Session open, 10-min TTL from verifiedAt | confirm-current | request-new (within 10 min) |
new-OTP-sent | OTP sitting in the new contact's inbox | request-new | confirm-new (within 10 min) |
committed | Value updated + verifiedAt set + audit row written | confirm-new | back to none |
expired | Session silently lapsed | 10 minutes elapse since current-side verifiedAt | restart at start |
Owner business profile
verificationStatus is the fixed literal "not_required_for_mvp" — not a lifecycle. There is no KYC gate in MVP.
Transitions
- no membership → active via
POST /api/v1/me/types/:type/request(user; immediate, no approval). - active → revoked via an admin team-management endpoint (admin; outside these docs).
- session none → current-OTP-sent via
start(user). - current-OTP-sent → current-verified via
confirm-current(user; opens 10-min session). - current-verified → new-OTP-sent via
request-new(user; session must still be valid). - new-OTP-sent → committed via
confirm-new(user; re-checks session + uniqueness). - current-verified / new-OTP-sent → expired when 10 minutes elapse since current-side
verifiedAt(system; time-based — must restart atstart).
Implementation Notes
| Integration issue | Correct handling |
|---|---|
| Building a "pending owner" / approval UI | Type grants are active immediately. Treat the 201 (or 200 already:true) as fully done; GET /me reflects it at once. |
| Leaving too much time between contact-change steps | The session silently expires 10 minutes after confirm-current's verifiedAt. Surface a countdown from sessionExpiresAt; on 409 INVALID_CHANGE_SESSION, restart from start. |
Jumping straight from start to request-new | You must call confirm-current first — without a verified current-side challenge, request-new returns 409 INVALID_CHANGE_SESSION. It is four calls, not two. |
Expecting PATCH /me { phone } to verify the number | It writes phone directly with no OTP and does not set phoneVerifiedAt. For a verified number use the four-step /me/phone-change/* flow. Email cannot be changed via PATCH /me at all. |
| Clearing a cuisine/notification key by omitting it | PATCH /me/preferences and PATCH /me/settings merge. Omitted keys are preserved — send the full desired array/object. |
Posting a raw image URL to /me/avatar | Avatar takes a fileId from POST /api/v1/uploads (purpose=avatar). Raw URLs are rejected; 404 unknown id, 409 not-yours. |
| Starting a phone change on an account with no phone | start and confirm-current return 409 PROFILE_PHONE_MISSING. Set a phone via PATCH /me first. |
| Assuming a new email/phone that was free stays free | Uniqueness is re-checked at confirm-new. A value free at request-new can still fail with 409 PROFILE_EMAIL_ALREADY_IN_USE / PROFILE_PHONE_ALREADY_IN_USE. Also 409 ..._UNCHANGED if it equals the current value. |
| Gating owner-only navigation on a cached flag | user.types and GET /me/types filter to active + non-revoked. A revoked owner will not appear — gate on the live list. |
Relying on user.language for response copy | The server never reads user.language for API copy — that's a mobile-side saved preference. Send Accept-Language on every request for localized responses. |
Calling any /me/* endpoint without a token | The whole group is behind middleware.auth. A missing/expired oat_ token returns { error: { code: "AUTH_REQUIRED" } }. |
Related
- Authentication — how to obtain the
oat_access token used here. - Uploads — mint the
fileIdyou pass toPOST /api/v1/me/avatar. - Reviews — create the reviews surfaced by
GET /api/v1/me/reviews. - API reference — full endpoint and schema catalogue.