You are here

Access token

The Open Data BCN portal offers datasets in its catalogue with different frequency of update. In order to improve access to data, especially the ones that are updated most often, and to prevent the exhaustion of the access quota being depleted due to recurring requests and therefore affecting the response time or availability of the portal for subtracting users, it will be necessary to access some resources with a user access token. This access, conveniently indicated, requires to be registered to the portal and logged in previous to the explicit request.

How to use it?

Once the access token is available:

- It can be included in the "Authorization" header when requesting the resource's download URL.

GET /data/dataset/8214557a-.../resource/d6b5a09c-.../download/recurs.json HTTP/1.1
Host: opendata-ajuntament.barcelona.cat
Accept: application/json
Authorization: 4f0d4dfaa06a4...

For example, to make the request with the Python urllib2 library, this header can be included with method add_header:

request = urllib2.Request('http://opendata-ajuntament.barcelona.cat/data/dataset/8214557a-.../resource/d6b5a09c-.../download/recurs.json')
request.add_header('Authorization', '4f0d4dfaa06a4...')
response = urllib2.urlopen(request)


- Resources can also be downloaded through the web browsers and in this case, it can be done by using an add on that allows the user to add or modify the headers for the petitions.

Although all the browsers offer similar option, we exemplify with the add on "Modify Header Value" by Mozilla Firefox. To download it, it's necessary to go to the corresponding site of Firefox Add-ons and configure the extension according to the following:

  • URL: https://opendata-ajuntament.barcelona.cat/data/dataset
  • Header Name: Authorization
  • Header Value: [the given token]

For further information on the add-ons on Firefox, click here.

How to obtain it?

To obtain the access token it is necessary to be logged in and, to log in, it is necessary to have a registered user.

Register or log in.