25.1 Before you write any code
Four things, in this order. The first three involve a person, so start them early.
- Request access. From Fleet Command under Account, or from the request form on the website. Say what you are building, which endpoint classes you need, and roughly how many calls a month. The volume is not a commitment; it decides your allowance.
- Wait for approval. Sawa sets your scopes, your rate limit and your free monthly allowance. Asking for scopes you will not call is the commonest cause of delay here.
- Create your key, in Fleet Command, once approved. The secret appears once. Put it in your secret store before you close that dialog.
- Make one call by hand before writing anything.
curlagainstget_devices_latest. If it returns your fleet, everything else in this document is a variation on it.
Only the account named as your company's manager can hold a key. If you are a developer at a client company, the request goes through whoever holds that account. See §15.2.
25.2 Your first call
export SAWA_KEY='sk_live_a7f3_9Kd2mX…'
export SAWA_BASE='https://myfleet.sawatelematics.com/api'
curl -sS -H "Authorization: Bearer $SAWA_KEY" \
-H 'Accept-Encoding: gzip' \
"$SAWA_BASE/get_devices_latest" | jq '.items | length'
If that prints a number, you are done with setup.
If it prints nothing useful, work down this list before anything else:
| Symptom | Cause |
|---|---|
401 |
The key is wrong, or you put it in a query parameter. The key only goes in the header |
401 and the key is right |
You are sending ?api_hash=. That is a different, older parameter. See §2 |
402 |
Unpaid subscription, or the account past its credit limit. Different codes, §15.8 |
403 |
Valid key, wrong scope. The body names the scope you need |
404 on a path you copied |
You dropped the /api/ prefix. There is no route at the root |
200 with "status": 0 |
A 200 is not success on this platform. §25.5 |
25.3 The five things that catch everyone
Read §3 in full. It is the highest value section in this document and it is short. The headlines:
- A
200does not mean success. Most v1 endpoints answer200with"status": 0and an error body. Check both, always. timeis account local,timestampis UTC. Two fields, two meanings, on the same object. Usetimestampfor arithmetic andtimefor display.- The two report engines disagree on date format, and the error does not say
so. One wants
YYYY-MM-DD, the other a datetime. device_idsis an array, even for one vehicle. A scalar produces the generic "Whoops" error.- Everything is prefixed
/api/./get_devicesis a 404.
25.4 Choosing the right endpoint
The commonest integration mistake here is polling a snapshot endpoint when an incremental one exists.
| What you want | Use | Not |
|---|---|---|
| Where is the fleet now | get_devices_latest, every 10 to 30 s |
get_devices, which is 10.3 MB on a 917 vehicle fleet |
| What happened since I last looked | v2/events/since?minutes=N |
get_events on a loop |
| One vehicle's track for a period | get_history |
repeated get_devices_latest and storing it yourself |
| A summary over time | a report (§6) or analytics (§7) | computing it from raw positions |
| Journey performance | dispatch analytics (§16) | deriving it from positions and guessing the plan |
The last row is worth dwelling on. If you want plan versus actual, on time arrival or border waits, the platform already computes them against the planned journey. Deriving them from position data means reinventing the plan, and you will get different answers to the ones the client sees in their portal, which is the worst kind of integration bug to debug.
25.5 Error handling that actually works
A minimal client that survives production:
import time, requests
BASE = "https://myfleet.sawatelematics.com/api"
S = requests.Session()
S.headers.update({
"Authorization": f"Bearer {KEY}", # never a query parameter
"Accept-Encoding": "gzip", # these payloads compress well
})
def call(path, **params):
for attempt in range(5):
r = S.get(f"{BASE}/{path}", params=params, timeout=60)
if r.status_code == 429: # rate limited, not billed
time.sleep(int(r.headers.get("Retry-After", 5)))
continue
if r.status_code == 402: # stop. a human must act
raise PaymentRequired(r.json().get("code"))
if r.status_code in (500, 502, 503, 504): # usually too wide a range
time.sleep(2 ** attempt)
continue
r.raise_for_status()
body = r.json()
# a 200 is not success
if body.get("status") == 0:
raise ApiError(body.get("message"), body.get("errors"))
return body
raise RuntimeError(f"{path}: giving up after 5 attempts")
Four rules behind that:
- Never retry a
402. Nothing about retrying fixes an unpaid bill, and a tight retry loop on 402 is the fastest way to look like an attack. Alert a human and stop. - Never discard your credential on a
402. It is deliberately not a401for exactly this reason. The key is still valid. - Honour
Retry-Afteron a429. A throttled call is never metered and never billed, so backing off costs you nothing. - Treat
500and504as "my date range was too wide" before treating them as a platform fault. That is what they usually mean here.
25.6 Watching what it costs you
Every response carries its own price:
X-Sawa-Units: 3
X-Sawa-Units-Remaining: 19380
Log both from day one. Two reasons, and the second is the one people regret:
- You can see a change in your own cost the day you deploy it, not at the end of the month.
- When an invoice is ever disputed, the argument is settled by your logs and ours agreeing, in units, per call. Without them it is a conversation about impressions.
Your free monthly allowance is spent first, before anything is billed, so a
small integration may never be billed at all. X-Sawa-Units-Remaining is the
free units left this month. Once it reaches zero, further calls are billed on
your monthly API usage invoice.
25.7 Four recipes
Each is a few calls, and each is a pattern a real integration uses.
Mirror live positions. get_devices_latest every 10 to 30 s, keyed by
device id, and trust timestamp rather than your own clock. Request gzip. Do
not poll faster than the devices report; most report on movement, so a 5 s poll
returns the same data five times and costs you five times.
Stream events. v2/events/since?minutes=N where N comfortably covers your
interval, then de-duplicate on event id. Overlap the window on purpose: a
missed event is worse than a repeated one, and de-duplication is three lines.
Pull a nightly report. Generate it after midnight in the account's
timezone, not yours, or you will silently cut the last hours off the day. Ask
for format=json for machine use; the PDF is for people. See
§6.
Score a journey. GET /api/v2/dispatches?status=completed for yesterday,
then …/{id}/adherence per dispatch, then …/analytics/coverage for the same
window so you know how much telemetry backed those scores. Re-read anything
scored in the last 48 hours: a vehicle out of coverage uploads its history when
it reconnects, and recompute moves the result.
25.8 Things that will bite you later
- Fuel is eventually consistent. An override or a resolved claim changes a past day's figure. Re-read periods you care about rather than caching the first answer. §17
- Revocation is 60 seconds, not instant. If you rotate a key, both the old and new work briefly. Deploy the new one, confirm traffic on it, then revoke. §15.9
- Your key is your whole company's view. It sees every vehicle that account sees, and nothing else, ever. If you need a narrower view, ask for narrower scopes rather than filtering client side and calling it security.
- Writes need a scope you probably were not granted. Reads are the default.
If you plan to create or update anything, say so in the access request, or you
will be building against
403s. §15.5 - Date ranges have practical limits. A wide range on a report or a history
call returns
500or504. Page by day or by week.
25.9 Where to go next
| You want | Read |
|---|---|
| The traps, in full | §3 |
| A complete working client | §12. Replace its login step with your key; everything after it is unchanged |
| Keys, scopes, limits, pricing | §15 |
| Journey planning and adherence | §16 |
| Every published endpoint | §14 |