TrackMe API Docs
Flow guides

Team & Staff

How a truck owner invites managers or cashiers, how invitees accept or decline, and how staff rows move through pending, active, declined, and revoked states.

This guide covers the truck-scoped team surface. Owners manage staff under /api/v1/owner/trucks/:id/staff; invitees act on their own inbox under /api/v1/me/staff-invites. Every endpoint requires Authorization: Bearer <oat_...>. Owner-side calls require that the caller owns the truck, otherwise the server returns 403 FORBIDDEN.

Creating a staff row does not grant access immediately. POST /api/v1/owner/trucks/:id/staff always creates or reopens a pending invite. The invite becomes usable only when the invitee calls POST /api/v1/me/staff-invites/:id/accept and the row becomes active.

The flow at a glance

Step 1 - Owner lists current staff

GET /api/v1/owner/trucks/:id/staff returns every staff row for that truck, including pending, active, declined, and revoked rows, newest first.

Step 2 - Owner invites a person

POST /api/v1/owner/trucks/:id/staff with either userId or email, plus role: "manager" | "cashier". The response is 201 with status: "pending".

Step 3 - Invitee checks inbox

GET /api/v1/me/staff-invites returns only pending invites addressed to the caller. It matches both direct userId invites and unclaimed email invites where invitedEmail matches the account email.

Step 4 - Invitee accepts or declines

POST /api/v1/me/staff-invites/:id/accept flips the row to active. POST /api/v1/me/staff-invites/:id/decline flips it to declined.

Step 5 - Owner maintains access

PATCH /api/v1/owner/trucks/:id/staff/:staffId changes the role. DELETE /api/v1/owner/trucks/:id/staff/:staffId revokes the row.

Owner endpoints

List staff

GET /api/v1/owner/trucks/trk_01jq.../staff
Authorization: Bearer oat_owner...
{
  "data": {
    "items": [
      {
        "id": "tst_01jq8z7m1n2p3q4r5s6t7u8v9w",
        "truckId": "trk_01jq...",
        "userId": "usr_01jq...",
        "role": "manager",
        "status": "active",
        "invitedEmail": "[email protected]",
        "invitedAt": "2026-05-20T10:00:00.000Z",
        "acceptedAt": "2026-05-20T11:24:18.000Z",
        "revokedAt": null
      }
    ]
  },
  "meta": { "requestId": "req_01..." }
}

Errors: 401 AUTH_REQUIRED, 403 FORBIDDEN if the truck is not yours, 404 NOT_FOUND if the truck id is missing.

Invite by existing user id

POST /api/v1/owner/trucks/trk_01jq.../staff
Authorization: Bearer oat_owner...
Content-Type: application/json

{ "userId": "usr_01jq...", "role": "manager" }

The row is addressed directly to that account and appears in that user's /me/staff-invites inbox.

Invite by email

POST /api/v1/owner/trucks/trk_01jq.../staff
Authorization: Bearer oat_owner...
Content-Type: application/json

{ "email": "[email protected]", "role": "cashier" }

If the email already belongs to an account, the row stores that account's userId. If the email is not registered yet, userId is null and invitedEmail is kept. When a user later registers with the same email and accepts, the row links to that user.

Validation: send one target (userId or email) and role. Missing both targets returns 409 STAFF_INVITE_EMPTY; a duplicate pending/active invite returns 409 STAFF_ALREADY_INVITED; inviting yourself returns 409 STAFF_INVITE_SELF; inviting the truck owner returns 409 STAFF_INVITE_OWNER.

Change role

PATCH /api/v1/owner/trucks/trk_01jq.../staff/tst_01jq...
Authorization: Bearer oat_owner...
Content-Type: application/json

{ "role": "cashier" }

Only manager and cashier are valid roles. Changing a revoked or declined row returns 409 STAFF_INACTIVE. The :id truck segment is still present in the URL, but ownership is checked from staffId; use the matching truck id to keep the client model simple.

Revoke

DELETE /api/v1/owner/trucks/trk_01jq.../staff/tst_01jq...
Authorization: Bearer oat_owner...

Returns the row with status: "revoked" and a revokedAt timestamp. Revocation is terminal for that row, but inviting the same person again can reopen a previously revoked/declined row as pending.

Invitee endpoints

Inbox

GET /api/v1/me/staff-invites
Authorization: Bearer oat_invitee...

Returns pending rows only. It includes:

  • rows directly addressed to the caller's userId;
  • email-only rows where invitedEmail matches the caller's email case-insensitively.

No pagination object is returned.

Accept

POST /api/v1/me/staff-invites/tst_01jq.../accept
Authorization: Bearer oat_invitee...

Accepting sets status: "active" and stamps acceptedAt. If this was an email-only invite (userId: null), accept links the row to the caller's user id. If the row is no longer pending, the server returns 409 STAFF_INVITE_NOT_PENDING.

Decline

POST /api/v1/me/staff-invites/tst_01jq.../decline
Authorization: Bearer oat_invitee...

Declining sets status: "declined". A stranger touching someone else's invite gets 403 FORBIDDEN, not 404; a missing invite gets 404 NOT_FOUND.

Lifecycle

StateMeaningHow you got hereWhat's allowed next
pendingInvite exists, not usable yetOwner invited by userId or emailinvitee accept -> active; invitee decline -> declined; owner revoke -> revoked; owner role change
activeStaff access is live for this truckInvitee acceptedowner role change; owner revoke
declinedInvitee rejected the inviteInvitee declinedowner can invite again, reopening/replacing the row as pending
revokedOwner removed accessOwner deleted the staff rowowner can invite again, reopening/replacing the row as pending

Roles:

RoleIntended use
managerFull truck-operations role for a non-owner staff member.
cashierNarrow order-counter role.

Implementation Notes

Integration issueCorrect handling
Treating 201 from invite as active accessIt is pending. Wait for invitee accept, or re-read the staff list until the row is active.
Hiding email-only invites until a backend link job runsThere is no job. /me/staff-invites matches invitedEmail against the signed-in user's email at read time.
Letting a stranger accept by idThe server returns 403 if the invite is not addressed to the caller. Show a "not your invite" state, not "missing".
Updating a declined/revoked invite's roleThat returns 409 STAFF_INACTIVE. Re-invite the person instead.
Inviting the same person twice while pendingThat returns 409 STAFF_ALREADY_INVITED. Surface the existing pending row.

On this page