Journey Planning API

I’m new to using API’s so I am trying to do a simple API call to plan a journey can anyone explain why I keep getting error code 500 and how to fix it?

Python Code:

url = ‘{w91pf}/to/{NW14SE}[?via][&nationalSearch][&date][&time][&timeIs][&journeyPreference][&mode][&accessibilityPreference][&fromName][&toName][&viaName][&maxTransferMinutes][&maxWalkingMinutes][&walkingSpeed][&cyclePreference][&adjustment][&bikeProficiency][&alternativeCycle][&alternativeWalking][&applyHtmlMarkup][&useMultiModalCall][&walkingOptimization][&taxiOnlyTrip][&routeBetweenEntrances]

response = requests.get(url, params={‘key’: API_KEY})

Check if the request was successful

if response.status_code == 200:
# Process the response data
data = response.json()
print(data) # Example: Print the data
print(“Error:”, response.status_code)

(My API key is stored in the variable and I have already imported requests)

Hello, welcome to the forum!

When reading API documentation, please note that {braces} denote required parameters and [square brackets] denote optional parameters. You should not actually include those bracket symbols in your request URL, and you should omit any optional parameters you aren’t using.

Therefore, you’d want to do something like:

url = ''

However, this request still fails. It looks like the postal code NW1 4SE is no longer in use and is therefore not recognised by Journey Planner.

I hope this helps. Please let us know if you have further questions. :slight_smile: