Api key not working

I’ve tried several times to get the cat api to work with the api key and I keep getting an auth error. Please note that when I pass the api key as a param in the query it works fine. When I make a curl call it works fine. It’s just not working with my python code.

Here is my code.

headers = {
‘Content-Type’: “application/json”,
‘x-api-key’: “MY KEY”
response = requests.request(“POST”, “https://api.thecatapi.com/v1/images/search”, headers=headers)

return response.text

Nothing extraordinary here. The code matches your sample exactly.

Please show me the error of my ways.

Hey @loisgh, assuming you’re replacing “MY KEY” with the key from your welcome email, then it looks like you’re using a POST instead of GET.

Here’s a live Python example you can play with.


Use POST when sending data to an API e.g. Votes or Favourites, Use GET when retrieving data from an API, in this case searching for an image.

Let me know if you have any other issues.

Best, Aden

Thanks so much Aden,
It worked beautifully.