Every example under a Built endpoint was recorded from the running API: the sample request, curl and response are exactly what was sent and returned. Real keys appear as YOUR_API_KEY.
How every call works
Every endpoint is POST https://vivo.websacco.com/api/<module>/<method>.
Photo uploads (profile photo, customer documents, IMEI label, handover photos) are multipart/form-data: request_id, api_key, user_id and the other fields as form fields, the photo in a field named file (JPEG or PNG, max 5 MB). A form field holding JSON, such as device, is decoded.
Field
Meaning
api_key
Identifies the app. Issued and revoked by head office; only its hash is stored. Sandbox keys (ak_test_…) use the SMS code 123456 and return it as debug_code.
request_id
A number the app sends with each call, for tracing
user_id
The person using the app, returned by login. Required on every call except check_account, login, forgot_password, resend_reset_code, verify_reset_code and reset_password.
idempotency_key
A UUID on calls that create money or state (submit_application, create_order, request_deposit, record_handover); a retry returns the first answer
Answers come back with HTTP 200; check status (1 success, 0 refused) and branch on error_code. The Users API puts fields directly in response; Customers and Orders put them in response.data and add http_status on a refusal. Phones are accepted as 07…, 7…, 2547… or +254 7… and returned as 2547…; amounts are whole Kenyan shillings; times are ISO 8601 with +03:00.
Checks before any method runs
A refusal here uses the short shape {"code": "API006", "description": "Invalid API key."}.
Code
Meaning
API001
Empty body
API002
Body (or the data form field) is not valid JSON
API005
Missing api_key
API006
Unknown or wrong API key
API007
API key revoked or expired
API008
API key not allowed from this IP address
API009
API key not allowed to call this module
API003
Missing request_id
API004
Missing data
API010
Missing or invalid user_id (not needed before login)
API011
No user with that user_id
API012
User account deactivated
The journey
Log in — users/check_account → users/login. First time or forgotten password: users/forgot_password → users/verify_reset_code → users/reset_password.
Find or add the customer — customers/lookup_customer → customers/create_customer.
Hand over — orders/start_activation → (status 9 only: verify_activation_code) → poll activation_status until next is handover_photos → upload_handover_photo ×4 → record_handover. See Activation and handover flow.
Customer app — the customer logs in with their ID number and sees the device, countdown, balance and agreement.
Activation and handover flow
Step 4 of the salesperson app, Activate & hand over: from a signed agreement to a handed-over phone. The app only calls our API; our server signs and encrypts every VTrust request (SHA-256 signature with the clientSecret, body AES-128-GCM with the aesKey and aesIv) through the Vtrust_api library. Endpoints marked Design · to build below are the agreed design for locking_mode = vtrust; the recorded samples under 8.1 and 8.2 come from the mock locking layer.
The screens
Screens 3 and 3e are only for phones VTrust reports as unauthorized (status 9). Phones in our import go straight from Screen 2 to Screen 4. our APIVTrust
Screen 1Not startedThe phone must be on and online. Photos and Complete handover stay off.get_orderScreen 2EnrollingOur API enrols IMEI1 with VTrust and reads its status. Buttons show Please wait… and are locked.start_activationdevice/createdevice/infoScreen 3 · status 9Enter the code from the phoneThe phone shows a 6-digit code. The salesperson types it in and taps Confirm code.verify_activation_codedevice/verify-auth-codeScreen 3eWrong codeVTrust rejects the code. The boxes turn red; the salesperson checks the phone and retries, or sends a new code.resend_activation_codedevice/send-auth-codeScreen 4 · status 8Waiting for the deviceNothing to type. The app polls every 5 s; VTrust Guard activates the phone once it is online.activation_statusdevice/infowebhookScreen 5ActiveVTrust reports Active. The lock date shows, and the photo rows switch on.activation_statusdevice/remind-messageScreen 6Four photos takenEach photo is taken live and uploaded on its own. At 4 of 4, Complete handover turns on.upload_handover_photo ×4Screen 7Before you hand overA sheet with the five education topics. Record handover stays off until all are ticked.record_handoverScreen 8Handover completeThe plan is active, the customer has the welcome SMS, and the order is closed.
Screen transitions
From
To
Trigger
1 Not started
2 Enrolling
Tap Enrol device
2 Enrolling
3 Enter the code
next = enter_auth_code (VTrust status 9)
2 Enrolling
4 Waiting
next = wait_online (status 8)
3 Enter the code
4 Waiting
Code accepted (next = wait_online)
3 Enter the code
3e Wrong code
AUTH_CODE_WRONG
3e Wrong code
3 Enter the code
New code sent, or the salesperson edits the code
4 Waiting
5 Active
next = handover_photos (status 1)
5 Active
6 Photos taken
Fourth photo saved
6 Photos taken
7 Checklist
Tap Complete handover
7 Checklist
8 Complete
All five ticked, record_handover succeeds
Code boxes: digits only, focus moves to the next box as you type, pasting six digits fills all six, Confirm code is off until six digits are in, Send a new code is off for 60 seconds after each send. The code is never stored on our side.
The next field
start_activation, activation_status, verify_activation_code and resend_activation_code all return next. The app draws the enrol card from it and never reads activation_code in VTrust mode.
next
Screen
What the app does
wait_online
4 Waiting
Show Waiting for the device… with the tips; keep polling activation_status every poll_every_seconds.
enter_auth_code
3 Enter the code
Show six code boxes; Confirm code calls verify_activation_code; Send a new code calls resend_activation_code (off for resend_after_seconds).
handover_photos
5 Active
Stop polling; show the lock date; switch on the four photo rows.
call_head_office
Problem card
Stop polling; show message and the head office number. Used for a locked phone, DEVICE_NOT_IN_SCOPE and AUTHORISATION_LIMIT.
Chip, order status and VTrust status
Chip on the card
Order status
VTrust status
next
Photos
Complete handover
Not started
signed
–
–
Off
Off
Code needed
activating
9 unauthorized
enter_auth_code
Off
Off
Inactivated
activating
8 unactivated
wait_online
Off
Off
Active
ready_for_handover
1 active · 2 normal
handover_photos
On
On at 4 of 4
Locked
activating
3 locking · 4 locked · 10/11 progressive
call_head_office
Off
Off
Handed over
handed_over
1 active
–
Read-only
Done
Call by call
App → our API: start_activation {order_id}
Our API → VTrust: device/create {deviceId=IMEI1, lockTime, messages, deviceLabelId}; VTrust answers code 0 (or "device already exists", treated as done)
Our API → VTrust: device/info {deviceId}; VTrust answers status 8 (unactivated) or 9 (unauthorized)
Our API → app: next = wait_online or enter_auth_code
Status 9 only: the handset shows a code; app → our API verify_activation_code {order_id, auth_code} → VTrust device/verify-auth-code → status 8. If the code expired or never showed: resend_activation_code → VTrust device/send-auth-code
Handset online; VTrust Guard confirms activation; VTrust pushes deviceStatusChange (newStatus ACTIVE) to POST /orders/callbacks/vtrust
App polls activation_status every 5 s, up to 3 minutes; our API calls device/info only if no push has arrived for 10 s; answers next = handover_photos
Our API → VTrust: device/remind-message (welcome and first lock date)
App → our API: upload_handover_photo ×4, then record_handover; plan active, welcome SMS
#
Salesperson does
App calls
Our API does
VTrust
On screen
1
Turns the phone on, connects it to Wi-Fi or data
–
–
–
Screen 1
2
Taps Enrol device
start_activation
Checks the order is signed. Works out the lock time from the days credited at handover. Saves the request; order → activating
device/create, device/info
Screen 2, then 3 or 4
2a
Status 9 only: types the code the phone shows
verify_activation_code (resend_activation_code if needed)
Passes the code to VTrust; never stores it
device/verify-auth-code (device/send-auth-code)
Screen 3 → 4, or 3e
3
Waits; nothing to type
activation_status every 5 s
Answers from the order (kept current by the webhook); asks VTrust only if nothing has arrived for 10 s
device/info, webhook
Screen 4 until Active
4
–
(poll returns Active)
Order → ready_for_handover; activated_at saved
device/remind-message (welcome)
Screen 5: photos unlocked
5
Takes the four photos with the camera
upload_handover_photo ×4
Refuses gallery photos; saves each with size, time and checksum; a retake replaces that photo
–
Screen 6: 4 of 4
6
Goes through the five topics, taps Record handover
record_handover
Needs Active + 4 photos + all 5 topics. Creates the plan (active, days credited), unit → on_plan, stock issued; welcome SMS
–
Screens 7 → 8
VTrust lock flow
What our API sends to VTrust. Every request is POST https://{domain}/openapi/v2/{manufacturer}/… with the headers -x-vtrust-transactionId, -x-vtrust-clientId, -x-vtrust-timestamp (ms) and -x-vtrust-signature (plus -x-vtrust-region if VTrust asks for it), and the encrypted body as the form field param.
Once per order; "device already exists" counts as done
start_activation
device/info
deviceId
Straight after create, to choose screen 3 or 4
verify_activation_code
device/verify-auth-code
deviceId, authCode
Status 9 only
resend_activation_code
device/send-auth-code
deviceId
At most once a minute
activation_status
device/info
deviceId
Only if no webhook update for 10 s
On Active
device/remind-message
deviceId, msgTitle, msgContent
Once: welcome and first lock date
VTrust status → our answer.
VTrust status
Name
provider_state
next
9
unauthorized
Unauthorized
enter_auth_code
8
unactivated
Inactivated
wait_online
1
active
Active
handover_photos
2
normal
Active
handover_photos
3
locking
Locked
call_head_office
4
locked
Locked
call_head_office
5
unlocking
Unlocking
wait_online
7
completing
Released
call_head_office
6
completed
Released
call_head_office
10 / 11
progressive
Locked
call_head_office
-1
unknown
Unknown
wait_online
Device lifecycle (VTrust Open API v2.3.9, page 7).
From
To
Caused by
(new)
unactivated
device/create, phone in our import
(new)
unauthorized
device/create, phone outside our import
unauthorized
unactivated
device/verify-auth-code
unactivated
active
Phone online, activation confirmed
active
locking → locked
control type 1, or lockTime reached; device confirms
locked
unlocking → active
control type 2, or type 3 with a new lockTime; device confirms
active / locked
completing → completed
device/complete-contract; device confirms
completed
removed
device/remove
Lock settings at enrolment.
VTrust field
Value we send
Where it comes from
deviceId
IMEI1
The IMEI confirmed against the store's sellable list
lockTime
End of the last paid-up day, 23:59 EAT, in epoch milliseconds
Days credited at handover (days_credited_at_handover, default 1)
remindBeforePhoneLock
720 minutes (12 hours)
Configurable lock timing
warnMsgBeforeLocked
"Your phone locks tonight at 23:59. Pay KES 68 to Paybill [our Paybill], account [your number]."
Template, with the daily amount
warnMsgAfterLocked
"This phone is locked. Pay your instalment to unlock it. Help: [support number]."
Template
lockTimeDelayPeriod
0: an offline unlock PIN doesn't re-lock by itself
Erroneous-lock service records control the expiry instead (scope item 22)
deviceLabelId
Our label for this programme
From VTrust with the credentials
After handover: keeping the lock date right.
Event
What our server does
VTrust call
Instalment paid
Adds the days bought to the plan and moves the lock date forward
device/control type 3 (lockTime)
Paid while locked
Sets the new lock date, which unlocks the phone
device/control type 3 (or type 2, then type 3)
Reminder before the lock date
Message on the phone, on top of VTrust's own warning
device/remind-message
Erroneous lock, phone offline
Service record with operator, reason and expiry; no re-lock while open
device/unlock-pin · device/query-sms-unlock-pin
Plan fully paid
Permanent release. Not reversible
device/complete-contract
Device changes state
Order and plan updated from the push
webhook deviceStatusChange
When something goes wrong
Situation
error_code
http_status
What the salesperson sees
Agreement not signed yet
AGREEMENT_NOT_EXECUTED
409
"Sign the agreement before enrolling the phone."
VTrust doesn't answer, times out or returns 5xx
LOCKING_UNAVAILABLE
502
"Enrolment isn't available right now. Try again in a minute." Order stays signed
"This device is not within the import scope of your account"
DEVICE_NOT_IN_SCOPE
422
"This phone isn't registered for instalments. Call head office." Head office imports the IMEI in the VTrust console
"Mes do not exist"
DEVICE_NOT_RECOGNISED
422
"VTrust doesn't recognise this IMEI. Check the phone is genuine and the IMEI matches the box."
"Authentication code does not match"
AUTH_CODE_WRONG
401
"That code doesn't match the phone. Check and try again."
Too many wrong codes
AUTH_CODE_LOCKED
429
"Too many tries. Send a new code."
New code asked for within 60 s
TOO_SOON
409
Send a new code stays off; retry_after_seconds says how long
Code sent when the phone doesn't need one
AUTH_CODE_NOT_NEEDED
409
Nothing; the app follows next from the response
"The number of unauthorized devices exceeds the limit"
AUTHORISATION_LIMIT
409
"Head office must clear pending phones before more can be added."
"device already exists" / "The device is authenticated"
(none)
–
Nothing; the API reads the current status and carries on
Still Inactivated after 3 minutes
ACTIVATION_TIMEOUT
409
"The phone hasn't connected yet. Check it's online and the date and time are right." Check again resumes polling
Photo picked from the gallery
GALLERY_NOT_ALLOWED
422
"Take the photo with the camera."
Photo before the phone is Active
ACTIVATION_PENDING
409
"Wait for the phone to show Active."
Complete handover with a topic unticked
CHECKLIST_INCOMPLETE
422
"Go through every topic with the customer." The missing topics are listed
Complete handover with photos missing
EVIDENCE_MISSING
422
"Take all four handover photos first."
Webhook with a bad signature, or older than 5 minutes
SIGNATURE_INVALID
401
Server to server only; VTrust retries
Rules
Order of events (scope item 14): signature, deposit by STK Push, activation, photos, handover. Today the deposit comes before the signature; that change sits in the order flow, before this screen.
Photos only once Active.upload_handover_photo is refused with ACTIVATION_PENDING until the order is ready_for_handover, matching the screen.
Locking layer:locking_mode = vtrust, with Order_locking calling the Vtrust_api library. mock stays for demos and returns the activation_code shown in the recorded samples.
One enrolment per order. A second tap on Enrol device returns the current state; "device already exists" from VTrust counts as enrolled.
Secrets (clientSecret, aesKey, aesIv, webhook secretKey) live only in the server environment (VTRUST_*). Each VTrust call is logged to device_locking_log without secrets, signatures, codes or PINs.
To confirm with VTrust before build
Whether a phone in our import ever shows the authorisation code, how long a code stays valid, and how many attempts it allows.
Whether setting a new lockTime (type 3) on a locked phone unlocks it straight away.
How long an unlock PIN stays valid.
Error codes
http_status
Codes
Meaning
400
VALIDATION_FAILED
A field is missing or wrong; see field_errors / validation_errors
All 73 requests, one folder per module, with sample photos picked in the form-data file field and test scripts that carry user_id, customer_id, order_id, codes and tokens from one request to the next.
Open the collection's Variables and set api_key to your key (a sandbox key ak_test_… fills SMS codes in automatically). site_url is already https://vivo.websacco.com.
Run Users → 1.2 Log in first; it saves user_id for every later request.
Users API
Built
POST https://vivo.websacco.com/api/users/<method>
Log in with the national ID number and a password; forgot and reset password by SMS code; profile and account. The ID number finds the account, the account's phone receives every code, and ion_auth->login($user->phone, $password) checks the password. Login returns user_id and the flags is_dealer, is_salesperson, is_customer; each app accepts its own role. Answers keep the users style: fields directly in response, refusals with error_code and form errors in validation_errors.
1.1 Check account (ID number)
POST/api/users/check_account
Log in and password
Returns the masked phone, has_password and next (login or set_password).
{
"response": {
"status": 0,
"error_code": "INVALID_CREDENTIALS",
"message": "Wrong ID number or password.",
"time": 1791300715
}
}
1.3 Forgot password: send code
POST/api/users/forgot_password
Log in and password
Sends a 6-digit code to the phone on the account. With a sandbox key (ak_test_…) the code is 123456 and is saved to reset_code; otherwise type the SMS code into reset_code.
POST https://vivo.websacco.com/api/customers/<method>
Find or add the customer (phone and national ID), the four checks (mobile code, profile with next of kin, three live photos, consents), then the application. Saving the profile creates the customer's app login the same way dealers and salespeople get theirs (added as a group member, linked in device_customers.user_id). Answers carry fields in data.
2.0 My customers
POST/api/customers/get_customers
Find or add customer
Customers registered by this salesperson, newest first, with verification, latest application, active plan and can_order. Optional: search (name, phone, ID number, customer no), stage (onboarding, awaiting_decision, approved, declined, on_plan), limit (max 100), offset.
POST https://vivo.websacco.com/api/devices/<method>
What a salesperson can sell and for how much: the catalogue as a list of repayment plans, each with its devices and their price on that plan, stock at their store and, for a customer, only the devices whose cash (retail) price is within their approved limit. Also device details with stock at other stores, the active plans, a quote that matches exactly what orders/create_order will fix, store stock and IMEI checks. Read-only: prices and plans are set by head office. Answers carry fields in data.
Catalogue for a customer (limit check)
POST/api/devices/get_catalogue
data is the list of plans, each with its devices and their price on that plan; only devices whose cash price is within this customer's limit. meta has the customer, limit and store. Saves the first device to product_id.
{
"response": {
"status": 1,
"message": "Not registered yet. It is registered when the IMEI is confirmed on an order.",
"time": 1791300719,
"data": {
"imei": "354129071842263",
"known": false,
"can_sell": true,
"open_order": null
}
}
}
Orders API
Built
POST https://vivo.websacco.com/api/orders/<method>
Order to handover: create the order (price fixed), photograph the IMEI label (read by Claude), confirm the IMEI, M-Pesa deposit from the customer's own number, agreement signed by SMS code, enrol the device with VTrust (entering the code from the phone when VTrust asks for it), four live handover photos, record the handover. Answers carry fields in data.
5.2 Create order
POST/api/orders/create_order
5. Device and IMEI
Reserves stock and fixes the price. Saves order_id.
Sends the label photo to Claude. Saves imei from ocr.imei. Choose the label photo in Body → form-data → file. Sent as multipart/form-data; the photo goes in the "file" field.
Sample request (form-data)
Content-Type: multipart/form-data
request_id: 1201
api_key: YOUR_API_KEY
user_id: 7
order_id: ORD-1001
capture_source: camera
file: (the photo file, JPEG or PNG, max 5 MB)
{
"response": {
"status": 1,
"message": "Payment prompt sent. Ask the customer to enter their M-Pesa PIN.",
"time": 1791300720,
"data": {
"deposit_id": 1,
"amount": 6000,
"status": "pending",
"checkout_request_id": "ws_CO_061020261832000829",
"poll_every_seconds": 5,
"timeout_seconds": 120
}
}
}
6.3 M-Pesa STK result
Callback · server to server
POST/orders/callbacks/stk_callback
6. Deposit
Plays Safaricom's part in sandbox. Disable outside sandbox. Amount and PhoneNumber must match the order's deposit and the customer's number, or the payment is held.
{
"response": {
"status": 1,
"message": "Enter the activation code on the device, then wait for Active.",
"time": 1791300720,
"data": {
"provider": "vtrust",
"provider_state": "Inactivated",
"activation_code": "9362-952D",
"poll_every_seconds": 5
}
}
}
With VTrust (locking_mode = vtrust, design): no activation_code; the answer carries provider_status, lock_time and next. Errors: AGREEMENT_NOT_EXECUTED, DEVICE_NOT_IN_SCOPE, DEVICE_NOT_RECOGNISED, AUTHORISATION_LIMIT, LOCKING_UNAVAILABLE. A second call returns the current state.
{
"response": {
"status": 1,
"message": "Waiting for the device to report Active.",
"time": 1791300720,
"data": {
"provider_state": "Inactivated",
"activated_at": null,
"ready_for_handover": false
}
}
}
With VTrust (design): answered from the order, which the status push keeps current; our API asks VTrust device/info only if no push has arrived for 10 s. Stop polling when next is handover_photos or call_head_office; after 3 minutes the answer is ACTIVATION_TIMEOUT and Check again resumes.
Response with VTrust: Active
{
"response": {
"status": 1,
"message": "The phone is Active. Take the four handover photos.",
"time": 1791300720,
"data": {
"provider_state": "Active",
"provider_status": 1,
"activated_at": "2026-10-16T15:57:12+03:00",
"lock_time": "2026-10-17T23:59:00+03:00",
"ready_for_handover": true,
"next": "handover_photos"
}
}
}
Response with VTrust: still offline after 3 minutes
{
"response": {
"status": 0,
"message": "The phone hasn't connected yet. Check it's online and the date and time are right.",
"time": 1791300720,
"error_code": "ACTIVATION_TIMEOUT",
"http_status": 409,
"data": {
"provider_state": "Inactivated",
"provider_status": 8,
"next": "wait_online"
}
}
}
8.2a Enter the code from the phone
Design · to build
POST/api/orders/verify_activation_code
8. Activate and hand over
Only when next is enter_auth_code (VTrust status 9). Sends auth_code (the six digits on the handset) to VTrust device/verify-auth-code; the code is never stored. On success the phone moves to status 8 and the app goes back to polling activation_status. Errors: AUTH_CODE_WRONG (401), AUTH_CODE_LOCKED (429), AUTH_CODE_NOT_NEEDED (409), ACTIVATION_NOT_STARTED (409), LOCKING_UNAVAILABLE (502).
Asks VTrust (device/send-auth-code) to show a new code on the handset; the old code stops working. At most once every 60 seconds per order: a sooner call gets TOO_SOON with retry_after_seconds.
VTrust calls this when a device changes state (deviceStatusChange), when a SIM is bound (deviceBinding) and when a batch task finishes (batchTaskResult). Registered with VTrust as the webhook URL. The device is found by deviceId (IMEI1). Replaces 8.6 locking-layer event when locking_mode is vtrust.
Header
Meaning
-x-vtrust-transactionId
Unique ID of the push (UUID, no dashes). Used to drop repeats: VTrust retries up to 3 times (about 5 s, then 10 s) until it gets HTTP 2xx.
-x-vtrust-timestamp
Push time, epoch milliseconds. Older than 5 minutes is refused.
-x-vtrust-signature
HmacSHA256_hex(rawBody + transactionId + timestamp, secretKey), lowercase hex; compared in constant time. Not the same as the request signature our server sends to VTrust.
operationType
Meaning
What we do
3
Activated
Order → ready_for_handover, activated_at saved, welcome message
Sent as multipart/form-data; the photo goes in the "file" field.
Change with VTrust: handover photos are refused with ACTIVATION_PENDING until the order is ready_for_handover; capture_source must be camera. kind: provider_home | app_home | salesperson_with_customer | customer_with_id.
Sample request (form-data)
Content-Type: multipart/form-data
request_id: 1201
api_key: YOUR_API_KEY
user_id: 7
order_id: ORD-1001
kind: provider_home
capture_source: camera
file: (the photo file, JPEG or PNG, max 5 MB)
{
"response": {
"status": 1,
"message": "Orders API",
"time": 1791300721,
"data": {
"endpoints": {
"create_order": "Create an order for an approved customer; reserves stock and fixes the price",
"get_order": "One order with quote, IMEI, deposit, agreement, activation and handover state",
"get_orders": "This salesperson's orders (filter: status, open_only)",
"upload_imei_photo": "Photo of the IMEI label; the server reads the IMEI (OCR) and returns it",
"confirm_imei": "Confirm the IMEI (pre-filled from OCR) and reserve the handset",
"request_deposit": "Send the deposit STK push to the customer's own number",
"deposit_status": "Poll the deposit: pending, paid, failed, cancelled, held",
"generate_agreement": "Create the hire-purchase agreement once the deposit is paid",
"send_sign_code": "SMS the signing code to the customer",
"sign_agreement": "Customer signs by OTP; signatory countersigns; copy sent",
"start_activation": "Enrol the handset with the locking provider through our layer",
"activation_status": "Poll until the provider reports Active",
"upload_handover_photo": "One of the four live handover photos",
"handover_photos": "Which handover photos are on file",
"order_photos": "Every photo on the order (IMEI label and handover, retakes included) with links",
"record_handover": "Complete the handover; starts the plan",
"cancel_order": "Cancel an unsigned order and release stock"
}
}
}
}
Plans
Design
Payments after handover are not built yet. The requests follow the same conventions.