I found a bug or two in the API.
For now it’s only possible to get votes and favourites for uploaded images. Quiet weird if you consider that you can favourite images not uploaded by the user.
Bug 1
Favourites
and votes
on existing images are never returned.
Reproduce for existing images
- Favourite an existing cat image using
https://api.thecatapi.com/v1/favourites with sub_id
- Notice that this cat image appears in
https://api.thecatapi.com/v1/favourites?sub_id=my_sub_id
- Using
https://api.thecatapi.com/v1/images/:image_id?sub_id=my_sub_id
will return the image with breeds but without votes and favourites
Reproduce for uploaded images
- Favourite an uploaded cat image using
https://api.thecatapi.com/v1/favourites with sub_id
- Notice that this cat image appears in
https://api.thecatapi.com/v1/favourites?sub_id=my_sub_id
- Using
https://api.thecatapi.com/v1/images/:image_id?sub_id=my_sub_id
will return the image withoutbreeds
(of course) but withvotes
andfavourites
Solution
- Disable voting and favouriting on existing images
- Return vote and favourite for existing images where needed
- Most reliable solution would be to implement
include_vote
andinclude_favourite
on all endpoint for fetching images, including search (See bug 2)
Bug 2
tltr; Favourites
and votes
on existing images are always returned (when sub_id
is provided)
Referring to the postman documentation we can provide https://api.thecatapi.com/v1/images/:image_id?sub_id=my_sub_id
with the Query Params include_vote
and include_favourite
. The are both not working at all. If we provide a sub_id
we are getting the votes and favourites, if we don’t we don’t. Again it’s the sub_id
which change this behavior.
Reproduce
- Favourite an uploaded cat image using
https://api.thecatapi.com/v1/favourites
withsub_id
- Notice that this cat image appears in
https://api.thecatapi.com/v1/favourites?sub_id=my_sub_id
- Using
https://api.thecatapi.com/v1/images/:image_id?sub_id=my_sub_id
will return the image withoutbreeds
(of course) but withvotes
andfavourites
only ifsub_id
is provided - Notice that
https://api.thecatapi.com/v1/images/:image_id?sub_id=my_sub_id&include_vote=false&include_favourite=0
doesn’t change the behavior at all no matter what values are given for include_vote and include_favourite.
Solution
- Make them work (l0l)
- Or remove them from the documentation and provide information about the behavior behind
sub_id
- Most beautiful solution would be to make them work and provide them on other endpoints like mentioned in
Bug 1
My user case
I have a grid of cat images on which every image can be favourited by the user. This is shown in de grid on each image. But because the search
API doesn’t provide votes
and favourites
I have to fetch
the favourites as well and iterate over that array to check if the current image_id is on one of the objects.
The problem is that both search results and favourites results are paged. So if the favourite of image 1 was not found on page 0, I’ll have to fetch page 1, maybe page 2 and so on. For each image on the grid. Or maybe limit the amount of favourites for each account
and sub_id
.
Or I have to search for images, and for each image shown on the grid a have to refetch it using the image/:image_id
endpoint and provide the sub_id
. Again for each cat image shown on the grid. Both solutions are not ideal and will result in tens or maybe hundreds of API calls for data that can be provided out of the box when include_vote
and include_favourite
are implemented like I mentioned…
Hope I made myself clear and maybe I’m wrong. Would be glad to here from you!