Developers

Wether you're using Trafficweb as the data-hub in your ITS application or you're just looking to include some overview of the traffic situation on your city's website, you can get the data from the Trafficweb API. With support for both vehicle-by-vehicle real-time data and aggregated measurement metrics, you should find what you need here.


Credentials

To access the Trafficweb API, you first need an account. You account credentials consists of a username and password and tells Trafficweb which groups you are a member of and thus which data you have access to. If you don't already have an account you can get one by filling out the form on the getting started page.


Quick start

The Trafficweb API is a RESTful service accessed via HTTPS at trafficweb.io/api. Objects are returned in JSON format. Here's some example code to get you up and running.

require "net/https"
require "uri"

# set path and SSL mode
uri = URI.parse("https://trafficweb.io/api/locations")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true

# create request with basic auth
request = Net::HTTP::Get.new(uri.request_uri)
request.basic_auth('USERNAME', 'PASSWORD')

# make request and print results
response = http.request(request)
puts response.body
from http.client import HTTPSConnection
from base64 import b64encode

# set up the HTTPS connection
c = HTTPSConnection("trafficweb.io")

# base64 encode credentials as it's stored as byte string by Python
credentials = b64encode(b"USERNAME:PASSWORD").decode("ascii")
headers = {'Authorization': 'Basic %s' % credentials}

# make the request and read response
c.request('GET', '/api/locations', headers=headers)
res = c.getresponse()
print(res.read())
curl -u USERNAME:PASSWORD https://trafficweb.io/api/locations

API reference

Locations


A location represents a point on a map. It contains a name for the point, possible identifiers for the road and coordinates. Meta information such as speed limit and number of lanes on the road can also be included.

Get locations


GET /locations
Parameters
Name Type Required Description
limitintegernoLimits the number of objects returned (max and default is 1000)
offsetintegernoSpecifies the number of objects to skip
Example response
Status: 200 OK
[
  {
    "id":123,
    "name":"Test location 1",
    "road_identifier":"Test road 66",
    "number_of_lanes":2,
    "longitude":"13.124721",
    "latitude":"55.484982",
    "group_id":1,
    "speed_limit":70
  },
  {
    "id":124,
    "name":"Test location 2",
    "road_identifier":"Test road 66",
    "number_of_lanes":2,
    "longitude":"17.934496",
    "latitude":"59.438881",
    "group_id":1,
    "speed_limit":70
  }
]

Get specific location


GET /locations/{id}
Example response
Status: 200 OK

  {
    "id":123,
    "name":"Test location 1",
    "road_identifier":"Test road 66",
    "number_of_lanes":2,
    "longitude":"13.124721",
    "latitude":"55.484982",
    "group_id":1,
    "speed_limit":70
  }

Installations


An installation represents the physical location of a detector at a given time by connecting detectors with locations and a time interval. The interval can be open, meaning the detector is currently installed at the location. The installation also contains information about the configuration of the detector at the time, such as classification scheme used.

Get installations


GET /installations
Parameters
Name Type Required Description
location_idintegernoReturns installations at given location
limitintegernoLimits the number of objects returned (max and default is 1000)
offsetintegernoSpecifies the number of objects to skip
Example response
Status: 200 OK
[
  {
    "id":321,
    "detector_id":1,
    "location_id":123,
    "installed":"2015-05-04T12:00:00.000+02:00",
    "removed":"2015-05-12T13:00:00.000+02:00",
    "lane_number":1,
    "bearing":"north",
    "classification_scheme":"Euro 6",
    "group_id":1
  },
  {
    "id":322,
    "detector_id":2,
    "location_id":124,
    "installed":"2015-05-19T12:05:13.000+02:00",
    "removed":"2015-05-27T11:19:01.000+02:00",
    "lane_number":2,
    "bearing":"southwest",
    "classification_scheme":"NorSIKT 4",
    "group_id":1
  }
]

Get specific installation


GET /installation/{id}
Example response
Status: 200 OK

  {
    "id":321,
    "detector_id":1,
    "location_id":123,
    "installed":"2015-05-04T12:00:00.000+02:00",
    "removed":"2015-05-12T13:00:00.000+02:00",
    "lane_number":1,
    "bearing":"north",
    "classification_scheme":"Euro 6",
    "group_id":1
  }

Measurement periods


A measurement period contains information on when measurements have been conducted for a given installation. Note that some detectors stream data continously rather than in predetermined intervals and thus lack measurement periods.

Get measurement periods


GET /measurement_periods
Parameters
Name Type Required Description
installation_idintegernoReturns mesaurement periods for given installation
limitintegernoLimits the number of objects returned (max and default is 1000)
offsetintegernoSpecifies the number of objects to skip
Example response
Status: 200 OK
[
  {
    "id":432,
    "start":"2015-05-05T12:00:00.000+02:00",
    "stop":"2015-05-07T12:00:00.000+02:00",
    "status":"completed",
    "group_id":1,
    "installation_id":321
  },
  {
    "id":433,
    "start":"2015-05-08T12:00:00.000+02:00",
    "stop":"2015-05-10T12:00:00.000+02:00",
    "status":"completed",
    "group_id":1,
    "installation_id":321
  }
]

Get specific measurement period


GET /measurement_period/{id}
Example response
Status: 200 OK

   {
    "id":432,
    "start":"2015-05-05T12:00:00.000+02:00",
    "stop":"2015-05-07T12:00:00.000+02:00",
    "status":"completed",
    "group_id":1,
    "installation_id":321
  }

Detections


A detection represents a detected vehicle, cyclist or pedestrian by a detector. It contains information on the type, speed and bearing of the vehicle. Supported classification schemes are:
- AUSTROADS (Level1)
- Austroads
- Crowd Analytics
- EUR6
- Heavy/Light
- Houston Radar
- LAM
- LRAB
- Metor
- Metor Loop
- Miovision
- Pyrobox
- SDR Örebro
- STARE-RD01
- Sensebit 5
- Sensebit 8
- Sensebit classes
- Sierzega
- Tindra
- VD11
- Wavetronix
- via count

Get detections


GET /detections
Parameters
Name Type Required Description
installation_idintegeryesSpecifies installation for which detections is desired
fromstringyesDate and time representing start of desired interval on ISO8601 format
tostringyesDate and time representing end of desired interval on ISO8601 format
limitintegernoLimits the number of objects returned (max and default is 1000)
offsetintegernoSpecifies the number of objects to skip
classification_schemestringnoClassification scheme that objects are returned in. See list of supported schemes above.
Example response
Status: 200 OK
[
  {
    "id":123321,
    "detector_id":2,
    "detection_time":"2016-08-22T22:00:00.000+02:00",
    "flagged":false,
    "velocity":"72.12",
    "installation_id":123,
    "length":5.2,
    "count":1,
    "lane_number":1,
    "bearing":"south",
    "vehicle_type":"Car"
    "vehicle_system_id":2
  },
  {
    "id":123321,
    "detector_id":2,
    "detection_time":"2016-08-22T22:00:00.000+02:00",
    "flagged":false,
    "velocity":"82.84",
    "installation_id":123,
    "length":12.2,
    "count":1,
    "lane_number":1,
    "bearing":"south",
    "vehicle_type":"Truck"
    "vehicle_system_id":4
  }
]

Detectors


A detector contains information about a physical measurement equipment such as technology, brand and model.

Get detectors


GET /detectors
Parameters
Name Type Required Description
limitintegernoLimits the number of objects returned (max and default is 1000)
offsetintegernoSpecifies the number of objects to skip
Example response
Status: 200 OK
[
  {
    "id":1,
    "short_name":"SS125_U100006476",
    "group_id":1,
    "model":"SS125",
    "technology":"Radar",
    "manufacturer":"Wavetronix",
    "status":null
  },
  {
    "id":2,
    "short_name":"METOR_LOOP_1415",
    "group_id":1,
    "model":"2000",
    "technology":"Inductive Loop",
    "manufacturer":"TDP",
    "status":"Inoperative"
  }
]

Get specific detector


GET /detectors/{id}
Example response
Status: 200 OK

  {
    "id":1,
    "short_name":"SS125_U100006476",
    "group_id":1,
    "model":"SS125",
    "technology":"Radar",
    "manufacturer":"Wavetronix"
  }

Data losses


A data loss contains information on where data is corrupt or missing from a measurement. By specifying an interval as well as type of data loss, currupt data can be excluded from calculations.

Get data losses


GET /data_losses
Parameters
Name Type Required Description
detector_idintegernoSpecifies detector for which data losses to be retrieved
fromstringnoDate and time representing start of desired interval on ISO8601 format
tostringnoDate and time representing end of desired interval on ISO8601 format
limitintegernoLimits the number of objects returned (max and default is 1000)
offsetintegernoSpecifies the number of objects to skip
Example response
Status: 200 OK
[
  {
    "id":1,
    "detector_id":1,
    "start":"2012-02-04T08:00:00.000+02:00",
    "stop":"2012-02-04T20:00:00.000+02:00",
    "data_type":"detections",
    "comment":"Power outage"
  },
  {
    "id":2,
    "detector_id":2,
    "start":"2013-02-05T21:00:00.000+02:00",
    "stop":"2013-02-06T09:00:00.000+02:00",
    "data_type":"velocity",
    "comment":"Tube broken, count ok"
  }
]

Get specific data loss


GET /data_losses/{id}
Example response
Status: 200 OK

  {
    "id":1,
    "detector_id":1,
    "start":"2012-02-04T08:00:00.000+02:00",
    "stop":"2012-02-04T20:00:00.000+02:00",
    "data_type":"detections",
    "comment":"Power outage"
  }

Groups


All access to data is controlled by the users memberships in groups. The group data structure contains id and the name of a group.

Get groups


GET /groups
Example response
Status: 200 OK
[
  {
    "id":1,
    "name":"Test group one"
  },
  {
    "id":2,
    "name":"Test group two"
  }
]

Get specific group


GET /groups/{id}
Example response
Status: 200 OK

  {
    "id":1,
    "name":"Test group one"
  }
 

Legacy API (not recommended for new designs)


Location metrics


Location metrics contains aggregated traffic data for a location, such as average daily traffic, average speeds and percentage heavy traffic.

Get location metrics


GET /location_metrics
Parameters
Name Type Required Description
locations_per_pageintegernoSpecifies the maximum number of objects to be returned
pageintegernoSpecifies the offset in locations_per_page counts
Example response
Status: 200 OK
[
  {
    "location": {
      "id": 123,
      "name": "Test location 1",
      "longitude":"13.124721",
      "latitude":"55.484982",
      "speed_limit": 70,
      "diff_speed_limit": null,
      "diff_speed_limit_descr": null,
      "owner": "Test city 1"
    },
    "measurement": {
      "start": "2021-03-24T05:00:00.000Z",
      "stop": "2021-03-24T16:00:00.000Z",
      "daily_traffic": 1203,
      "workday_daily_traffic": 1345,
      "weekend_daily_traffic": 1002,
      "average_speed": 54.8,
      "speed_percentile_50": 54.0,
      "speed_percentile_85": 63.0,
      "type": "motor_vehicles",
      "sensors": ["Magnetometer (Sensebit FLEX)"],
      "link": "https://trafficweb.io/..."
    }
  }, 
  {
    "location": {
      "id": 124,
      "name": "Test location 2",
      "longitude":"17.934496",
      "latitude":"59.438881",
      "speed_limit": 70,
      "diff_speed_limit": null,
      "diff_speed_limit_descr": null,
      "owner": "Test city 1"
    },
    "measurement": {
      "start": "2021-03-23T23:00:00.000Z",
      "stop": "2021-03-24T23:00:00.000Z",
      "daily_traffic": 1589,
      "workday_daily_traffic": 1589,
      "weekend_daily_traffic": null,
      "average_speed": 49.1,
      "speed_percentile_50": 47.0,
      "speed_percentile_85": 59.0,
      "type": "motor_vehicles",
      "sensors": ["Magnetometer (Sensebit WD-300)"],
      "link": "https://trafficweb.io/..."
    }
  }
]