Unpacking data from Unified API

Hi all

I am new to the use of the API and hoping someone can help me with some basics. I have been unable to see any data, but have been able to get ‘Response 200’ from various URLs, so I assume I am doing something right. However when I try to view this data I get errors.

So i am using the approach in Python as below (with my own app id and key). This approach works with other APIs. Per above, I do get the ‘Response 200’ through. But also:

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

import json
import requests

url = ‘TfL Unified API
response = requests.get(url)
data = response.json()

Is there something else i need to do?

Thanks,
Paul

Paul:

One thing I’ve found useful for learning is to paste the URL you are testing into the address bar of firefox, which shows the response broken down like this:

To do this you need a firefox addon which you can see at https://jsonview.com/

Firefox then allows you to expand and contract each node so that you can verify the structure and format of the data being returned.

I can’t help you with decoding it with python, but in javascript it’s fairly simple once you have an object o containing the json result:

o.mode would give you an array of modes (in this case, with a single value of “tube”)

o.lines[0].name would return the (first and only) name of “Picadilly”

Thanks Harry.

I’ve managed to get data through, but without using my API credentials.

What is the format for adding the credentials to the URL? (sorry I cannot find this anywhere).

I’ve tried appending ‘?app_key=121212?app_id=123abcd’ but to no avail.

Paul

url = ‘https://api.tfl.gov.uk/BikePoint
response = requests.get(url)
data = response.json()
data

Paul,

I may be wrong but I think you want “https://api.tfl.gov.uk/BikePoint?app_id=2222&app_key=abcd

Simon

Thanks Simon - that worked, I’m up and running now.