Getting 403 Forbidden on calls to Road Real Time API

Whether via the API Explorer or from a script on my site I get 403 Forbidden or 401 “Unauthorized”.

I’ve got all the headers in there for Accept, Authorization, Content-Type, and User-Agent…

Calls to other API’s are working (e.g. Trip Planner API’s).

Any pointers on what I might be missing appreciated.

HTTP ERROR 401

Problem accessing /route. Reason:

    Unauthorized


Powered by Jetty://

Hi @pedantix, which API are you getting the error in? Also, what type of authentication are you using? We recommend using the API Key, you can find full instructions here User Guide | TfNSW Open Data Hub and Developer Portal

Thanks,
Alex

Hey Alex,

Thanks for coming back to me on this query.

I’m calling the “route” method on the Road Real Time API and I am using the API Key authentication.

Here’s a sample of what I’m trying:

response = requests.post(
url=“https://api.transport.nsw.gov.au/v1/ttds/route”,
headers={
“Accept”: “application/vnd.ttds-route+json”,
“Authorization”: “apikey xxxx-my-api-key-goes-here-xxxx”,
“Content-Type”: “application/vnd.ttds-route+json”,
“User-Agent”: “MyApp/1.0”,
},
data={
“encoded-paths”: “[|lolE}qiy[btCxtAzrAzKxz@a{@p}AgxB]”,
“departure-time”: “1695168000”,
}

And the error I get is as follows:

Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/requests/packages/urllib3/connectionpool.py", line 572, in urlopen
    self._prepare_proxy(conn)
  File "/usr/local/lib/python3.5/dist-packages/requests/packages/urllib3/connectionpool.py", line 780, in _prepare_proxy
    conn.connect()
  File "/usr/local/lib/python3.5/dist-packages/requests/packages/urllib3/connection.py", line 267, in connect
    self._tunnel()
  File "/usr/lib/python3.5/http/client.py", line 832, in _tunnel
    message.strip()))
OSError: Tunnel connection failed: 403 Forbidden

Hey @pedantix,

Have you got “Roads Real Time API” selected for your application API key?

Hi @pedantix, there seems to be an issue with the API at the source. We’re looking into it and will keep you updated on the progress.

Thanks,
Alex

Hi @pedantix, we’ve investigated this and it seems like everything is working correctly at the source. The 403 you got looks like it’s coming from your proxy or server. I’ve tried using curl with your parameters and it worked. Please try the following:

curl -X POST --header ‘Content-Type: application/vnd.ttds-route+json’ --header ‘Accept: text/plain’ --header ‘X-User-Agent: xxxx/xxxx’ --header ‘Authorization: apikey xxxxxx’ -d ‘{ “encoded-paths”: [“|lolE}qiy[btCxtAzrAzKxz@a{@p}AgxB”], “departure-time”: 1695168000 }’ ‘https://api.transport.nsw.gov.au/v1/ttds/route

Thanks,
Alex