myCarConnect sync API (what the phone apps call today) ===================================================== Changes since version 5 ----------------------- 1. Trips get one new field, "times": when the car reached each point of "path", so a replay keeps the real pace (stops at signals included). - a string of whole seconds after the trip's startAt, comma-separated, one per point of "path", in the same order: "0,5,9,14,..." - "" (empty) for trips recorded before times were kept; keep it as it comes. A trip stored without the field (everything version 5 kept) may come back without it: the apps read a missing "times" the same as "" (no timings), so old trips need no change - about 5 characters a point, so up to about 100 KB for a long trip Store it with the trip and send it back exactly as received (version 5 drops it today). Nothing else changes: same URLs, key, YouTube list, merge and removal rules. One URL, two lists. The apps build it from stream.php's address: https:///.../api/history.php?key= https:///.../api/history.php?key=&list=trips Every call is an HTTP POST with a JSON body (Content-Type: application/json) and must answer 200 with a JSON body. A wrong or missing key: 403. Anything else that goes wrong: any non-2xx code with a JSON body {"error": "what went wrong"}; the app shows/logs that text and tries again later, keeping its own copy meanwhile. (A plain GET with the key may return the YouTube list the same way; the apps only use POST.) Times are Unix milliseconds (UTC). Keep the files where the web server cannot hand them out. 1) YouTube list (POST ...history.php?key=KEY) ------------------------------------------------ Request: the phone's whole list and its removals. { "items": [ {"id": "mjO5zQD3pbU", "url": "https://www.youtube.com/watch?v=mjO5zQD3pbU", "title": "Zehni Azmaish Season 14 New Kalam", "at": 1791206250726} ], "removed": {"uji7l0WgXx4": 1791290000000} } id YouTube video id, exactly 11 characters of A-Z a-z 0-9 _ - (refuse anything else) url always https://www.youtube.com/watch?v= (you may rebuild it from id) title may be empty; keep a known title if a newer entry arrives without one at when it was last played on that phone removed id -> when it was removed on a phone Merge on the server, then answer with the full merged result in the same shape: - per id, the entry with the larger "at" wins; - removed: per id keep the larger time; - an entry is dropped when removed[id] >= entry.at (a removal beats older plays, a newer play brings it back); - order items newest "at" first; no limit on the number of items; - removals may be forgotten after 30 days. Response: {"items": [...merged, newest first...], "removed": {...}} (send "removed": {} not [] when empty) 2) Trips (POST ...history.php?key=KEY&list=trips) --------------------------------------------------- Request: only what changed on that phone since its last sync, plus all its removals. { "since": 1791285689375, "trips": [ {"id": 1791200000000, "startAt": 1791200000000, "endAt": 1791200900000, "distanceM": 7350.5, "startName": "Road 12, Banjara Hills, Hyderabad", "endName": "Charminar, Hyderabad", "destination": "Charminar", "note": "", "tag": "work", "source": "", "updatedAt": 1791200950000, "path": "_p~iF~ps|U_ulLnnqC_mqNvxq`@", "times": "0,312,900"} ], "removed": {"1791100000000": 1791286000000} } id number (the trip's start time; up to 16 digits) - the key of the trip path the route as a Google encoded polyline (1e-5 degrees); can be long - allow at least 200 KB per trip and a few MB per request source "unit" for a drive the head unit recorded itself, "" for a phone's times seconds after startAt at which each point of path was reached, comma-separated, one per point ("" for older trips); store and return it unchanged updatedAt when the trip was last created or edited on a phone since the "now" value your last answer gave this phone (0 the first time) Server rules: - for each incoming trip: store it unless removed[id] >= its updatedAt, or the stored copy has an updatedAt >= it; when stored, stamp it with the server's current time (serverAt); - for each removal: keep the larger time per id and delete that trip; - answer with every stored trip whose serverAt > since (changes from any phone), all removals, and "now" = the server time you used as the stamp. Response: {"now": 1791285689446, "trips": [ {... same fields as above, serverAt may be included ...} ], "removed": {"1791100000000": 1791286000000}} "Clear" on a phone sends every trip id in "removed", so removed trips never come back. A drive both the Pixel and the unit recorded (overlapping times) is tidied up on the phones; the server stores both.