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


#1

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 Aden@TheAPIGuy.com


#2

#3

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.


#4

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


#5

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.


#6

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)

#7

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?


#8

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.


#9

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.


#10

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


#11

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


#12

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.