Trip Planner API - need help


#1

Hello,

I’m using the API explorer on the site but for some reason, whenever I click ‘Try it out’ it doesn’t work for me - I keep getting 401, ‘The calling application is unauthenticated’. I have selected my application and it’s enabled and the API key is appearing. When I go to other APIs it works, but only Trip Planner API is giving me troubles.

EDIT: I also have another question – I’m planning to create a web app (mainly frontend) using the APIs available, is this possible without a server? I say this because I haven’t been able to make a simple API request work with just XMLHttpRequest() because the API doesn’t accept ‘Allow-Control-Access-Origin’.

Any help would be greatly appreciated.

Many thanks,
Joseph


#2

Hi Joseph,

Looks like the API explorer (Swagger) for the Trip Planner API is pointed at the wrong API server. We’ll need someone from the Open Data team to fix it up.

In the meantime, you can still make requests directly to the API endpoint (not using the API explorer) if you remove “np” from the domain name (i.e. https://api.transport.nsw.gov.au not https://api.np.transport.nsw.gov.au).

Re CORS, it’s not currently supported by the API – you’ll need to set up some form of intermediary proxy. Also, it might not be a good idea to expose your API key publicly.

Ken


#3

Thanks Ken. I think this is now fixed (re the pointing to the wrong server).


#4

Thanks for the help jxeeno and yvonne :slight_smile:


#5

setting up to communicate with this API is rather difficult :frowning:

are there any other custom headers besides “Authorization” that I should be aware of?


#6

Authorization should be sufficient… If you’re having 401 errors, make sure you have it in the format:

Authorization: apikey <API Key>

#7

finally got it to work, I was missing ‘apikey’ before the actual API Key :man_facepalming:

Thanks heaps !