AIMERICAAPI · Developers

Sync tokens

To keep a copy current without rereading everything: ask only for what changed.

Lists that sync — /calls and /messages — take sync_token alongside limit and cursor.

  • Without a token: the full window (the last 30 days), paged, and a new sync_token in the answer.
  • With a token: only what was created or changed since (a call whose recording arrived, a text that went to "delivered"), and a fresh token.
  • The token is opaque (a base64 of {"since", "id"}): keep it as it is, never build one yourself.
  • An invalid token, or one older than 30 days, answers 400 invalid_request "sync_token expired, do a full sync": start again without a token.
# 1. first time: no token → the last 30 days, and a token to keep
GET https://api.a1merica.ai/v1/calls?limit=200
→ {"items": [...], "next_cursor": "…", "sync_token": "eyJzaW5jZSI6IjIwMjYtMDktMjVUMTY6MDA6MDBaIiwiaWQiOm51bGx9"}

# 2. later: only what was created or changed since → a fresh token
GET https://api.a1merica.ai/v1/calls?sync_token=eyJzaW5jZSI6…
→ {"items": [ …the delta… ], "next_cursor": null, "sync_token": "eyJzaW5jZSI6…"}

# 3. a token older than 30 days
→ 400 {"error": {"type": "invalid_request", "message": "sync_token expired, do a full sync", "request_id": "…"}}

Walk every page (next_cursor) before you save the last page's sync_token; that is the one that means "up to here, I have everything". An object can show up in two consecutive syncs when it changed in between: apply the row by its id, and the result is the same.