Authorization

In order to use Open Transport you must provide an API key in each request.

Failing to provide an API key or providing an incorrect or expired key will result in a 401 Unauthorized error.

Getting an API key

You can obtain a key from the Open Transport Console.

  1. Open the Open Transport Console
  2. Enter a description into the New key description box (e.g. “Test Key”, or “iOS app”)
  3. Click Create new key
  4. The new key will appear in the list, copy and paste it into your application

Using an API key

The recommended way to provide the API key is to set the Authorization header for each request.

Authorization: Bearer API_KEY_GOES_HERE
  • API_KEY_GOES_HERE - (string) Your API key

An alternative approach to supplying the key is to use the key URL query parameter:

GET /api/beta/vehicles/example?key=API_KEY_GOES_HERE
  • API_KEY_GOES_HERE - (string) Your API key

Setting headers

Setting headers in HTTP requests is common practice, this section decribes how to achieve it in various languages.

jQuery

You can use jQuery’s beforeSend callback to add an HTTP header with the authentication information:

beforeSend: function (xhr) {
    xhr.setRequestHeader ("Authorization", "Bearer " + apiKey);
}

Go

Use the Header map on an http.Request to set the Authorization header in Go:

req, err := http.NewRequest("GET", "/path", nil)
if err != nil {
    return err
}
req.Header.Set("Authorization", "Bearer " + apiKey)

See also