Questions / Feedback / Bugs for the Cat or Dog APIs?

Feel free to post anything related to theCatAPI.com or theDogAPI.com - or any requests for upcoming Public service APIs

Other people can then post more info, or use it for future reference.

Feel free to email me personally at [email protected]

Hi Aden.

Iā€™m trying to use a new API instead of old one. At this moment I stuck on getting favourites for specific user, my request looks like this:

@Headers(ā€œContent-Type: application/jsonā€)
@GET(ā€œv1/favouritesā€)
Call favourites(@Header(ā€œx-api-keyā€) String apiKey, @Query(ā€œsub_idā€) String sub_id);

Iā€™m getting data back with list of image objects, but they donā€™t contain all necessary data as it was in legacy API. For example, there is no ā€œurlā€ field, so I canā€™t display the favourite image itself. They contain only ā€œidā€, ā€œuser_idā€, "image_id, ā€œsub_idā€ (why we need it if I passed it to the request already, they are the same) and ā€œcrated_atā€. Well, I probably can get the ā€œurlā€ posting one more request with ā€œimage_idā€, but in this case if my user has 100 images favourited I have to make 100 additional requests, which is definitely a bad idea.

That is a great question Stepan! Iā€™ve updated the API to include the Image for each Favourite returned via /favourites.

You can see this in action over at the new website: https://thecatapi.com
And look through the code for it: https://github.com/AdenForshaw/theCatAPI-website

Any other requests just let me know,

All the best, Aden

Hi Aden,

Iā€™m trying to use your API (dog or cat) to generate some test material for a proof of concept. But I cannot use POST under any circumstances. Even using your Python code from the documentation does not work.

Can you please help me out. All I am getting is:
400 - Unexpected token a in JSON position 14

I have been able to use both APIā€™s but with different code

DOG API Payload:
payload = ā€˜{ā€œimage_idā€:ā€œb54ā€, ā€œvalueā€:ā€œb54ā€}ā€™
This only works if by some odd chance i put in a value parameter in the JSON. Otherwise I get the message ā€œmissing ā€œvalueā€ parameterā€

CAT API Payload:
payload = ā€˜{ā€œimage_idā€:ā€œb54ā€}ā€™

This one works without the value parameter.

Under no circumstances does your python code in the documentation work.

Sorry to hear that Vypeer,

Iā€™ve just reviewed the /votes documentation and youā€™re right, there was a mistake in the example. Iā€™ve added a couple more code examples and checked they work in Python.

Hereā€™s an example Python script showing how to Up & Down vote which iā€™ve testing in 3.7

Just:

  • swap out ā€œDEMO-API-KEYā€ for your own API Key,
  • save the code below into a file called ā€˜vote-example.pyā€™
  • run it in the terminal/cmd with ā€˜python vote-example.pyā€™
  • your should see something likeā€¦

Making an up-vote
{ā€œmessageā€:ā€œSUCCESSā€,ā€œidā€:36496}
Making an down-vote
{ā€œmessageā€:ā€œSUCCESSā€,ā€œidā€:36497}

Let me me know if you have any other issues, Iā€™m always trying to refine the documentation.

vote-example.py

import requests

print("Making an up-vote")

url = "https://api.thecatapi.com/v1/votes"

# Escape the string charaters - "value":1 means vote up
payload = "{\n\t\"image_id\":\"asf2\",\n\t\"sub_id\": \"my-user-1234\",\n\t\"value\":1\n}"
headers = {
    'Content-Type': "application/json",
    'x-api-key': "DEMO-API-KEY"
    }

response = requests.request("POST", url, data=payload, headers=headers)

print(response.text)


print("Making an down-vote")

# Escape the string charaters - "value":0 means vote down
payload = "{\n\t\"image_id\":\"asf2\",\n\t\"sub_id\": \"my-user-1234\",\n\t\"value\":0\n}"
headers = {
    'Content-Type': "application/json",
    'x-api-key': "DEMO-API-KEY"
    }

response = requests.request("POST", url, data=payload, headers=headers)

print(response.text)

Thanks for this update.
The next question is, if one of my users (sub_id) does /images/search and gets a list of images I need to know if Image was already favourited by this user, now I canā€™t see how I can do that. It would be great to add a new field to Image object ā€œfavourite_idā€ which will contain a favourite_id if current user already favourited this image or can be empty if not. What do you think?

1 Like

Great Question Stepan.

Iā€™ve added both the ā€˜voteā€™ and ā€˜favouriteā€™ objects that match the (account + ā€˜image_idā€™ + ā€˜sub_idā€™) key to every response from the ā€˜/imagesā€™ routes.

You can see it in action here: https://thecatapi.com/?id=JdMcWHjhB&sub_id=stepan-test

Just Fav/Un-Fav to see the ā€˜favouriteā€™ little heart icon on the Image added & removed, and Vote Up/ Vote Down, then refresh the page youā€™ll see the ā€˜voteā€™ thumb icon change.

This will work for the ā€˜/imagesā€™ ā€˜/images/:image_idā€™ and ā€˜/images/searchā€™ routes.

Let me know if you need anything else to support your use-case.

1 Like

Is there any way to search for photos of a particular breed on the dog API?
This seems to be in place for the cat API, but not the dog APIā€¦

It would be nice to be able to do /breeds/:breed_id/images, or /search, and get image results of that dog breed.

Great question. There absolutely is, both APIs share the same codebase. I just need to update it to the latest version.

As you suggested youā€™ll be able to search for Dog images by breed in the same way as the Cats via /images/search?breed_id={breed.id}

Hereā€™s a live example - https://docs.thecatapi.com/example-by-breed

I expect this to be done early next week, once the new /breeds data for theCatApi is complete.

Hereā€™s the Trello ticket to track it. https://trello.com/c/6Rleanhr/90-release-new-codebase-to-thedogapicom

EDIT: Problem solved, original question below.! I just needed to add a user-agent header to my urllib.request. Itā€™s still weird that the dog API doesnā€™t require this.

Hey Aden,

Iā€™m trying to search for random cat pictures using your cat API with my Discord bot. Or, I have used it for a few months so far without any issues. Just recently I have noticed this weird issue where the API gives a 200 response code with requested data, as it should, but it also gives an 403 forbidden error as well. I used this as the request, found from the official docs: https://api.thecatapi.com/v1/images/search?limit=3&page=100&order=DESC. I also have my API key in the request headers, I even tried requesting a new one and using that but so far no luck.

So, I get a response from the API, but at the same time my request fails with 403 error code. Iā€™m also using your dog API for the same purpose, and it works with pretty much identical code.

EDIT: Also, Iā€™m trying to read the image as bytes for uploading the image directly to Discord. Iā€™m using Pythonā€™s urllib.request.urlopen for this. I think this might cause the problem, but Iā€™m using the same solution with the dog API and itā€™s working there properly.

Do you have any tips what might cause this?

Troikku

Thanks for posting your issue @Troikku . Really interesting issue, havenā€™t been able to reproduce it yet, however i have a sneaky suspicion based on what youā€™ve said that it may be Cloudflare related.

I integrated Cloudflare as a new CDN a few days ago and am still working out the kinks. Itā€™s cut the daily Cloudfront/S3 costs from ~$3 to ~$0.50 a day, but thrown complications into the stack which could be responsible for this odd occurrence

Iā€™ll tweak the settings and let it run for another few days, after which Iā€™ll rollback if thereā€™s still any issues.

Thanks for your patience, and please do let me know if you see any other issues.

Hi Aden

I am creating App by thecatapi. Could I get the image size from the entry?

Could you add two properties, width and height in the Cat object?

Hi Aden,

Loving the cat and dog apis! Quick question on whether there is rate limiting for the REST calls.

Great suggestion, Iā€™ve added it to the roadmap and aim to get to it in the next 2 weeks.

Hereā€™s the ticket for updates: https://trello.com/c/IeMsTD8Z/129-add-width-height-of-image-to-response

Great question @chewwwwwwwwww, I try to let people use the API for as many different use-cases as possible. So while thereā€™s no hard limit, there is a soft limit for behaviour flagged as malicious.

Thereā€™s plenty of apps using the API that have gone viral and sent massive spikes of traffic, all fine and handled without limits. However if it canā€™t realistically be attributed to this, of even someone infrequently load testing testing their app, then the rate-limiter could kick in.

For instance behaviour that looks like a DDOS attack, or even more basic patterns like 1000ā€™s of request per second from the same IP without waiting for a response.

If youā€™re getting erroneously rate-limited (429 or 5XX response code depending on the use-case), then just send me an email with the details and iā€™ll have a look.

Hi Aden,

I checked that but Iā€™m not getting a ā€œfavouriteā€ object inside Image object returned by search, but the picture was already favourited by the user. Could you please check that and by the way update the models in documentation?

1 Like

Hi Aden,

Recently I got hit with the following error

SSL_connect returned=1 errno=0 state=error: certificate verify failed

I realised that Iā€™ve been hitting your APIs without an API key all along! Iā€™ve tried to sign up for a free API but itā€™s giving me this error.

image

Thanks again for this great API and looking forward to the bug fix!

Thanks for the post @chewwwwwwwwww, looks like there was some issues with the SSL cert auto renewal.

Fixed the DNS issue, just waiting for AWS to renew the cert. Should be in the next hour or so. This will fix both the API and signup issues.

Will ping another update once itā€™s finished.

New cert for the Dog API (api.thedogapi.com) has been approved, and service is back as normal.

Anything else just let me know.

Best, Aden