Help plz : Using api for the first time

Hi guys

Im trying to use the tfl api for my university assignment which includes me making a journey planner for underground trains …

Whever i try and use the tfl api in my code and click a button it repeats unassigned

Im trying to add something like this in my website when the 2 stations are clicked but the api isnt working for me … anyone who why?

Hi

I presume you’re starting with https://api.tfl.gov.uk/Journey/JourneyResults/{from}/to/{to} such as https://api.tfl.gov.uk/Journey/JourneyResults/940GZZLUVIC/to/940GZZLUESQ - the results are JSON and your responsibly (as a coder) to display…

The details are here - APIs: Details - Transport for London - API

1 Like

yes im using the journey results api… this is my code but everytime i press the button it just displays unassigned multiple times

What’s the purpose of the “space+HTTP1.1” at the end of the query? Isn’t it going to be taken as toName=euston_HTTP/1.1 ?

i wouldnt know why… that is what was generated from the api website:

this is the last bit of the url:
&fromName=victoria&toName=euston%20HTTP/1.1

And if you remove it?

still displays:

Capture2

when button is click

I would start by using a console.log(data) when you first get the data to back as to help ascertain the problem’s root. Use F12 (or ctrl+shift+i) to see the console.

Capture3

when i do console.log(data) these come up. @briantist

OK, you can use the little “>” symbol to expand the information. It will expand the journeys: Array() into data that you can check against your display code.

I think the problem is you’re not looking in the right bit of the output. I think you might need iterate on something other than the top level returned object.

Can you try logging line, stop_name & destionation please?