Sessions

In general, every request you make will be billed and counted. We have implemented a way to save money using what we call sessions. The idea is that repeated requests to the same resource will be less relevant for you , and if these requests happen during one session block (a time interval), only one of them will be counted.

At the moment, departure board queries to the same station and trip updates for the same trip ID will use the session block counting mechanism. Other requests will counted per request. This Function is also strictly optional. You don't have to use it.

Hint: If you use Mobilitybox.js, you will automatically benefit from the session without any change from you.

Example:

1. Request departures for a certain station:

  /* Request */
  curl -X GET "https://api.themobilitybox.com/v3/transit/departures.json?station_id=vesputi-station-OW_67U4PIKCwCBxtnNWwZ2jnsNS2WZA1eNY9MyjyvKs&api_key=abcde-fghi-jkln-mnop" -H  "accept: application/json" -D -
  [...]
  /* Response */
  HTTP/2 200
  date: Wed, 02 Jun 2021 06:16:53 GMT
  content-type: application/json; charset=utf-8
  access-control-allow-origin: *
  session-token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJodHRwOi8vYXB...
  [...]
  [{"departure":{"scheduled_at":1622617380000,"predicted_at":null,"platform":""},"trip":{"id":
  [...]
  

This is the first request, and the response includes a header field named session-token.

2. Use session-token in subsequent requests:

  curl -X GET "https://api.themobilitybox.com/v3/transit/departures.json?station_id=vesputi-station-OW_67U4PIKCwCBxtnNWwZ2jnsNS2WZA1eNY9MyjyvKs&api_key=abcde-fghi-jkln-mnop" \
    -H "accept: application/json" \
    -H "session-token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJodHRwOi8vYXB..." \
    -D -
  

This second request will not count if the request happens in a certain time window (5 minutes).

Important: Please always update the session-token with the header value you receive from subsequent requests, as we do not guarantee that it won't change.