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

Hi Aden,

My team is looking to create an app that would involve image recognition of dog photos, and we were excited to find this api! However, we’re having trouble with the https://api.thedogapi.com/v1/images/upload endpoint through your website.

We’re putting our API key in the header field x-api-key, checking the box next to Send requests directly from the browser (CORS must be enabled) in Settings, and for the body we’re putting:
{
“file”: “https://live.staticflickr.com/65535/47698046842_78ef1be8b7_b.jpg”,
“sub_id”: “EliasBichon”
}

However, upon clicking Send, it works on it for about 30 seconds and finally responds with:
{
“level”: “info”,
“message”: “Cannot read property ‘name’ of undefined”,
“status”: 500
}

What are we doing wrong? I’ve tried the images/search and it seems to be working fine, so I don’t think the server is down. I’ve also tried using Postman and it doesn’t seem to work either.

Interesting question.

The image/upload method expects an actual file, instead of a url to a file hosted elsewhere.

So quickest way is to download the file first, then use the upload method, either manually or building a little proxy script.

It’s a good feature suggestion though, so i’ll look at adding it as a core feature next week!

Best, Aden

n.b - the Postman collection has been updated to clarify the ‘file’ parameter - apologies, it was definitely not clear. - https://documenter.getpostman.com/view/5578104/RWgqUxxh

Thanks Aden for the quick response! I think updating the documentation will certainly help prevent confusion in the future (although I did notice you only updated The Cat API but not The Dog API documentation, neither on Postman nor thedogapi.com website).

Anyway I’ve now got everything working on Postman. Actually before I posted on this forum I did try using Postman to upload a file from my local machine, but I wasn’t able to get it to work. But after you posted the reply I tried troubleshooting again and it turned out the reason it wasn’t working was because I didn’t have TheDogAPI - live set as my environment.

Hello @Aden ,

I’m playing with Dog Api and have been very funny. My Suggestion is include a thumb url on body of Breeds Model, (Maybe the first image related or null ?) so we can have a preview of that breed without make an extra request.

I’m building an app that show the breeds and would be awesome to show the image thumb on a list, like pinterest or something.

Thanks for your project, its very well documented and fun !

Hi @Aden,

First I gotta say, love the api! Thanks!

I’ve implemented a python wrapper for thecatapi (catapi.py if you’re curious), and I have some questions on what a few parameters are for and feedback on the api at the moment.

Questions:
On docs.thecatapi.com/api-reference/breeds/breeds-list , what is the attach_breed parameter for? I couldn’t find anything on it.

What mime_types are available when searching for an image? How are the mime_types used? Do you have an example url that would show how to pass an array in for a parameter? Any attempts I’ve made at using mime_types have failed.

Feedback:
The image analysis data returned from /images/{image_id}/analysis doesn’t seem to match the example response shown. Rather than getting [image, labels, moderation labels, vendor, approved, rejected] attributes back, I get [image, labels, moderation labels, vendor, created at] without any approved/rejected status.

There’s a misspelling on images-search page in the docs, Iterate should only have one t.

Thanks again for the api!

Hi Aden,

When trying to get a specific image i don’t get the vote and favourite.
GET images/<IMG_ID>?image_id=<IMG_ID>&sub_id=<SUB_ID>

Atfer looking at the documentation, it appears that these properties are only returned if i’m the owner of the image, which i guess means that i uploaded it.

“If you are the owner then the full Image response will be present, and any Vote or Favourite matching your account & sub_id will be attached.”

Would it be possible to have these properties on the object event if i’m not the owner, like it’s already done on the route “GET /images/search” ?

Thanks !

Hey, just found your API! It’s cool, but I had a question:

If I have a list like this (attached image), I’d like to have an image of the breed to the left of the name.

Currently, the breed list doesn’t provide an image url.

Would it be possible to add one to the Breed model? Like a “cover photo”. I’d prefer not to make 50+ GET requests for an image for each list item :slight_smile:

Thanks!

34

Do I need API key to access any of the CAT API ? It seems endpoints - /images/search/ & /breeds is working without the key?

Hi @gpalanis,

Good question. You’re right, you don’t need an API to get data from most of the API endpoints.

The API key is only required to save data to the API, so that data stays with your Account - e.g. Votes, Favourites, Uploaded images etc.

You can then retrieve that data via the API using that same API key. Once i get time to turn on Analytics, you’ll be able to get your request counts using the key too.

All the best, Aden

Hello. I’ve ran into an issue today that I just can’t seem to fix by my own:
I am writing a python script that downloads pictures from this API.
It sends a GET request to https://api.thecatapi.com/v1/images/search, it then grabs the image URL, and tries to download it using wget.
The problem is that when I try to download it (via wget or urllib.requests), I always get HTTP Error 403: Forbidden, and the image isn’t downloaded.

I saw that someone was having the same issue here on this post, and they fixed it by adding a user agent, but it just doesn’t seem to work for me, no matter what user-agent i try to use.

Do you have any idea what could be causing this, or a pointer as to what I could do to possibly fix the issue?

Thank you

Interesting question @Kaiyazaki. My assumption is the same as yours - the user-agent isn’t being applied for some reason…

Here’s a quick Python example i’ve tested this morning. Let me know if it doesn’t work for you.


import requests
import shutil

api_response = requests.get("https://api.thecatapi.com/v1/images/search")

image_url = api_response.json()[0]['url']
image_filename = image_url[image_url.rfind("/")+1:]

headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36'}

response = requests.get(image_url, headers=headers, stream=True)
with open(image_filename, 'wb') as out_file:
    shutil.copyfileobj(response.raw, out_file)
del response

Stepping through the code it:

  • makes a request for a random image from theCatApi
  • gets the URL of the image from the first element of the Array in the JSON response
  • gets the name of the file by splitting the URL on the ‘/’ character into an Array, and using the last element
  • defines a fake user-agent to use
  • requests the Image using the URL and the fake user-agent, with the stream parameter set to true
  • opens a new local file
  • saves the raw Image response to that file
  • cleans up the memory

Hope that helps, Aden

1 Like

Hello! This link: https://cdn2.thecatapi.com/images/dhu.jpg don’t return a cat image

Hello, I try write mobile app for on android. But if I send request I get in serponse ““message”:“Cannot read property ‘name’ of undefined”,“status”:500,“level”:“info”” what it does mean. I’m don’t understant. What I do not this way. Because in postman all queries work correctly. Help me please :slight_smile:
If you need code snipens for example i will send them. :’(

@rvyZ Please start a new thread, instead of hijacking this one. Include as many code samples as possible, and ensure your question pertains to the Cat API or the Dog API

@frexuz -this feature has just been released to both TheCatAPI and TheDogAPI.

Each “breed” in the ./breeds response now contains an “image” object - with a url to it’s picture.

Let me know if you have any issues.

All the best, Aden

Yay @Aden, awesome! :smiley:

1 Like

I’ve noticed a few possible bugs:

  1. Can’t upload dog image through upload tab on https://www.thedogapi.com/ - for some reason it’s expecting me to provide cat image (“Upload a .jpg or .png Cat Image”)

  2. /images “order” parameter doesn’t work - even if it’s set to ASC or DESC /images is still returning random set of images. Which basically breaks “page” parameter as well.
    For example the following url is providing random set of images every time:
    https://api.thedogapi.com/v1/images/search?limit=5&order=ASC&page=0

Hi Aden. The dog API is wonderful. However, the GET request to get all categories https://api.thedogapi.com/v1/categories returns an empty JSON array. Can this be fixed?

Hi Aden. Noticed something else as well.

A GET request to https://api.thedogapi.com/v1/breeds (for getting all breeds) results in an array of objects, each of which includes an element “image”, which further has a “url” attribute for the representative image of the breed.

{
        "weight": {
            "imperial": "80 - 150",
            "metric": "36 - 68"
        },
        "height": {
            "imperial": "27 - 29",
            "metric": "69 - 74"
        },
        "id": 18,
        "name": "Anatolian Shepherd Dog",
        "bred_for": "Livestock herding",
        "breed_group": "Working",
        "life_span": "11 - 13 years",
        "temperament": "Steady, Bold, Independent, Confident, Intelligent, Proud",
        "reference_image_id": "BJT0Jx5Nm",
        "image": {
            "id": "BJT0Jx5Nm",
            "width": 1216,
            "height": 1131,
            "url": "https://cdn2.thedogapi.com/images/BJT0Jx5Nm.jpg"
        }
 }

However, a GET request to the same URL but with a search term, e.g. https://api.thedogapi.com/v1/breeds/search?q=${searchTerm} results in an array of objects each of which is identical in structure except that it is missing the “image” element.

{
        "weight": {
            "imperial": "80 - 150",
            "metric": "36 - 68"
        },
        "height": {
            "imperial": "27 - 29",
            "metric": "69 - 74"
        },
        "id": 18,
        "name": "Anatolian Shepherd Dog",
        "bred_for": "Livestock herding",
        "breed_group": "Working",
        "life_span": "11 - 13 years",
        "temperament": "Steady, Bold, Independent, Confident, Intelligent, Proud",
        "reference_image_id": "BJT0Jx5Nm"
    }

As a result, one has to use the “reference_image_id” attribute to make another GET call, this time to https://api.thedogapi.com/v1/images/${refImageId} where refImageId contains the value of the reference_image_id, for the sole purpose of getting the image. And one has to do this individually for each breed.

Is there a reason that the search response is “lacking” the image data, and can this be fixed? Thanks.

Those are great questions @SomeGuy, thanks for posting.

  1. Categories: There’s no categories for theDogAPI, only for theCatApi, hence why the response is unfortunately an empty array. This will get expanded in future though.

2.) Breeds on breeds/search results: Great suggestion, definitely one that can get added. Here’;s the ticket for reference: https://trello.com/c/rSL2O1bN/158-add-image-to-breeds-search-response-just-like-currently-exists-on-the-breeds-breedid-response

All the best, Aden