nationalparkservice / nps-api-samples

Sample Code using calls to the NPS API
32 stars 9 forks source link

Passing HEADERS object with valid API key returns 403 Forbidden issue #2

Closed TotallyNotTito closed 1 year ago

TotallyNotTito commented 1 year ago

HEADERS = {"Authorization":"INSERT-API-KEY-HERE"} req = urllib.request.Request(endpoint,headers=HEADERS)

response = urllib.request.urlopen(req).read()

TotallyNotTito commented 1 year ago

I'm able to use the same API key as an environmental variable and pass that to the url endpoint to work with NPS API, but passing it via the above method hasn't worked with the request.Request() method

tamills commented 1 year ago

Hello, Tito

Based on what I can see, it looks like there might be a mismatch between the documentation (i.e. https://www.nps.gov/subjects/developer/guides.htm) and the implementation.

I've been able to confirm the HTTP Basic Auth Username method does not work, but the GET Query parameter approach does. The HTTP Header approach works, but only when I use "X-Api-Key" and not when I use "Authorization"

May I ask you to please give that a try on your end to confirm, and let me know if it is successful, so I can update the code examples in the documentation accordingly? Thank you.

tamills commented 1 year ago

Good morning, @TotallyNotTito

Following up to see if you've had a chance to change your code from "Authorization" to "X-Api-Key", and if so, was the result successful?

TotallyNotTito commented 1 year ago

Hey just seeing these. Apologies for the delayed response. I did confirm your results. I'm going to close this issue.

Happy New Year and hope you have been well. Thank you for following up!