Challenge obtaining a shapefile

Hi

I’m attempting to grab a shapefile (.shp) of traffic volumes from the API but I am unable to authenticate my calling application to be able to do so. The shapefile response is status: 200 from the user but 401 for the token when I use https://api.np.transport.nsw.gov.au/auth/oauth/v2/token.

I have a red exclamation mark just under the implementation notes of the expand operations requesting I authenticate where I use my apikey as the client ID but I have no idea where to find my secret or if this step is even required.

I generated a new application in the hope this would fix the issue but no it has not.

Is someone please able to look at this please.

Thank you
Chris

Hi @chris.wheldon, we recommend using the API key method of authentication, not oauth Troubleshooting | TfNSW Open Data Hub and Developer Portal.

Also that URL doesn’t look right. I suggest trying out the API in our API explorer to get a sense of how it works and then building your API call from there.

Thanks,
Alex

Hi Alex

I am utilising the API key method. Here is a sample curl.

curl -X GET --header ‘Accept: application/zip’ --header ‘Authorization: apikey HIDDEN API KEY’ ‘https://api.transport.nsw.gov.au/v1/roads/spatial?format=shp&q=select%20*%20from%20road_traffic_counts_station_reference%20limit%205

The response body returns this
image

Do you know what I do with the response ? I also have this exclamation mark which pertains to my original oauth2 query. Not sure if the two are related.
image

Chris

Hi @chris.wheldon, the response is in binary/protobuf format since it’s a shapefile. Our API explorer gives you a preview of the data but it’s not always useful as in this case.

What you need to do is download the response body as a zip file. The zip file will contain the actual shapefiles that you will be able to load into the software/tool of your choice.

For other APIs that serve data in binary format, you will need to convert the data into a readable format to use. You can read more about this on our Troubleshooting page.

Thanks,
Alex

Hi Alex

The response body yes contains binary and I presume at this stage the .shp component of the shapefile only. If so, where are the .shx and .dbf components please ? Are these tied up in the binary somewhere and if so how do I identify them ?

Your troubleshooting page reveals nothing in this area unfortunately.

Chris

Hi @chris.wheldon, so the response actually returns a zip file, if you download that you will get the components you’re referring to. In other words, you can add " > vehiclecounts.zip " to the end of your curl command or use an API tool and you will get a zip file. In the zip file you will see the following:
image

Thanks,
Alex

Thanks Alex. The response I’m receiving cannot resolve the authentication whether it be by curl or http call. Could be a permissions thing at work so will give it a try at home and let you know next week.

Chris