# Civimatica Street Data API Integrate the Civimatica Street Data API. Implement a server-side client and the calls this product needs. Use only the endpoints and fields below. Do not invent paths, query parameters, or response fields. ## Service - Base URL: https://api.civimatica.com - Docs: https://developers.civimatica.com/docs - Send the key on every /v1 request in the header `X-API-Key`. - Read the key from the environment variable `CIVIMATICA_API_KEY`. Never hardcode it. Never put it in a query string. Never ship it to a browser or a mobile app. - Test keys start with `cv_test_`. Live keys start with `cv_live_`. - The API returns structured answers about streets. It does not return images or video. - `city` is a city identifier from configuration. Do not bake one city into the client. ## What to call 1. `GET /v1/city-zones?city={city}` lists the parking zones that are turned on. 2. `GET /v1/spots?city={city}&zone={zone}` lists spots a detection vehicle found free in the last 10 minutes in that zone. Taken spots are not included. 3. `GET /v1/zones` or `POST /v1/zones/probability` returns the chance of finding a spot on a street. 4. `GET /v1/spot-type?lat={lat}&lon={lon}` classifies parking at a coordinate. 5. `GET /v1/fleet` returns the live position of the detection vehicle in each zone. 6. `GET /v1/events` is a cursor. Call it with no parameters to read `latest_seq`, then poll `?after_seq=`. Load zones before asking for spots. An empty `spots` array means nothing was found free in that zone during the last 10 minutes. That is not an error. ## City zones `GET /v1/city-zones?city=` requires `city`. Response: `{ city, count, zones }`. Each zone has `id`, `name`, `tariff_band`, `tariff_eur_hour` (euros per hour), `hours` (local schedule), and `area` (the main streets around the zone). There is no geometry. `also_tariffs` is present only when the zone has another pricing band. Each item is `{ band, eur_hour }`. Use `id` as `zone` on later calls. A space or a slash between the two parts of an id is accepted on input. Responses use the hyphen form. A zone that is turned off is omitted. Asking for its spots returns 400 `zone_disabled`. ## Spots `GET /v1/spots?city=&zone=`. `zona` is an alias of `zone`. Both `city` and `zone` are required. `limit` defaults to 500 and cannot exceed 1000. Response: `{ city, zone, window_minutes, count, spots }`. `window_minutes` is 10. `zone` in the response is the canonical id. Each spot is `id`, `lat`, `lon`, `available_at`, `size`, `in_shade`, `shade_until`. - `id` is stable and starts with `cv-`. - `available_at` is when a vehicle last found the spot free, ISO 8601 UTC. - `size` is `small`, `medium`, or `large`. - `in_shade` is whether the spot is currently shaded. - `shade_until` is an ISO 8601 time, the string `night` when it stays shaded, or null when the spot is sunlit. The spot object has no street name. A spot that is not detected again within 60 days expires and leaves the store. ## Chance of finding a spot `GET /v1/zones` and `POST /v1/zones/probability` return the same shape. The POST body is JSON. Pass one place: a street (`via` or `street`), a city zone (`zone` or `zona`), or both `lat` and `lon`. `city` may be omitted and then defaults to the service's primary city. Send `city` anyway. `at` is an ISO 8601 time. Omit it to evaluate now. `limit` defaults to 40 and cannot exceed 200. A bare street name matches the ordinary street of that name. Include the road type when you mean a square, avenue, or other specific road. A name of at least three characters can match part of a street name. An unknown street name returns 200 with `count` 0. A coordinate needs both `lat` and `lon`. The answer is the street at that point, in the city zone that contains the point. A street that never enters a city zone is one row with `city_zone` null. Response: `{ city, evaluated_at, count, streets }`. Rows are easiest first. Each street row is `street`, `city_zone`, `probability` (0 to 1), `percent`, `chance`, `length_m`, `lat`, `lon`, `near`. - `chance` is `easy` above 0.6, `possible` above 0.3, otherwise `hard`. - `length_m` is how much of the street lies in that zone. - `lat` and `lon` are a point on the longest stretch. - `near` is another street beside that stretch, or null. Show `chance` and `percent` to people. There is no geometry. ## Spot type `GET /v1/spot-type?lat=&lon=`. Both coordinates are required. `type` is `blue` (paid), `white` (free), `yellow` (reserved), `disabled`, `loading`, or `unknown`. `unknown` means no street within 400 m. Fields: `lat`, `lon`, `type`, `type_label`, `street`, `city`, `city_zone`, `paid_until`, `product`. `type_label` is omitted when `type` is `unknown`. `note` is present when no street is within 400 m. `paid_until` is the local `HH:MM` when paid hours end, or null when there is none. `product` is a tariff code when that street has one, otherwise null. A turned-off zone comes back with `city_zone`, `paid_until`, and `product` null. ## Fleet `GET /v1/fleet` takes no parameters. Response: `{ vehicles }`. Each vehicle is `id`, `lat`, `lon`, `heading_deg` (compass bearing 0–360), `speed_kmh`, `direction`. `direction` is `outbound` or `return`. There is one vehicle per city zone. `id` is `cv-veh-` plus that zone id. ## Events `GET /v1/events?after_seq=&limit=`. `limit` defaults to 500 and cannot exceed 1000. With no `after_seq`, the response is `{ latest_seq, events: [] }`. Store that cursor and poll `after_seq` equal to the greatest `seq` you have seen. Do not start from zero unless someone asks for history. Event `type` is `spot_detected`, `spot_free`, `spot_occupied`, `spot_expired`, or `engine_started`. - `spot_detected`: a vehicle found a spot free, including a later pass that finds it free again. - `spot_free`: a later pass finds a previously taken spot free. - `spot_occupied`: a later pass finds a previously free spot taken. - `spot_expired`: the spot was not detected again within 60 days. `reason` explains that. - `engine_started`: the detection service started. `spot_detected`, `spot_free`, and `spot_occupied` also have `seq`, `ts`, `spot_id`, `lat`, `lon`, `street`, `size`, `free`, `city`, `city_zone`, `in_shade`, `shade_until`. `spot_expired` has `spot_id`, `lat`, `lon`, `street`, and `reason`. `engine_started` has `stored_spots`. Events for a zone that is turned off are omitted. ## Errors Errors are `{ "error": { "code", "message" } }`. Some include `zones` or `cities`. - 401 `unauthorized`: missing or invalid key. - 404 `unknown_city`: the city identifier is not known. `cities` lists the ones that are. - 400 `unknown_zone`: the zone id is not in that city. `zones` lists the ids that are on. - 400 `zone_disabled`: the zone exists and is turned off. `zones` lists the ids that are on. - 400 `bad_time`: `at` is not ISO 8601. - 400 `no_street`: no street within 400 m of the coordinate. - 422 `city_required`, `zone_required`, `place_required`, `point_required`, or `invalid`: a required value is missing, a value has the wrong type, or `limit` is outside its range. `point_required` means `lat` and `lon` were not both sent. `place_required` means the chance call had no street, no zone, and no coordinate. ## Build it this way - Keep the key on the server. - Take `city` and `zone` as inputs. Resolve `zone` from `/v1/city-zones` when the caller has a name or a street and not an id. - Treat shade, size, and `available_at` as part of a free spot. Do not drop them. - For a street chance, show `chance`, `percent`, the street, the zone, and `near` when it is not null. - Follow the event cursor from `latest_seq`. Advance the cursor only after the batch is stored. - Do not describe the service as simulated, mock, or dummy.