1

I'm getting the below error while sending request to cloudsight api

{"error":{"image":["at least one of image or remote_image_url must be set"]}}

Can you please let me know what is missing.

Code snippet:

var xhr = new XMLHttpRequest();
var url = "http://api.cloudsightapi.com/image_requests";

xhr.open("POST", url, true);
xhr.setRequestHeader('Content-type', 'application/json');
xhr.setRequestHeader('authorization', 'CloudSight <MY_API_KEY>');
xhr.setRequestHeader('cache-control', 'no-cache');

xhr.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
        var myArr = JSON.parse(this.responseText);
        alert(http.responseText);
    }
};

xhr.send(JSON.stringify({"remote_image_url":"http://englishbookgeorgia.com/blogebg/wp-content/uploads/2015/08/husky.jpg" ,"locale":"en_US"}));
Mohammad Kanan
  • 4,452
  • 10
  • 23
  • 47

1 Answers1

2

You'll want to use the v1 api that is documented here: https://cloudsight.docs.apiary.io/#reference/0/images-collection

Here is the corrected block using the v1 API.

var xhr = new XMLHttpRequest();
var url = "http://api.cloudsightapi.com/v1/images";

xhr.open("POST", url, true);
xhr.setRequestHeader('Content-type', 'application/json');
xhr.setRequestHeader('authorization', 'CloudSight <Your API Key>');
xhr.setRequestHeader('cache-control', 'no-cache');

xhr.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
        var myArr = JSON.parse(this.responseText);
        alert(this.responseText);
    }
};

xhr.send(JSON.stringify({"remote_image_url":"http://englishbookgeorgia.com/blogebg/wp-content/uploads/2015/08/husky.jpg" ,"locale":"en_US"}));

The v0 api that you were using requires a root image object in the JSON, so:

{
  image: {
    remote_image_url: "example",
    locale: "en_US"
  }
}

Which is the reason for the error.

mccalljt
  • 786
  • 3
  • 14
  • Also I've tried passing the parameters in the image block as you have mentioned and it still throws the same error. ` xhr.send(JSON.stringify({"image":{"remote_image_url":"http://englishbookgeorgia.com/blogebg/wp-content/uploads/2015/08/husky.jpg","locale":"en_US"}}));` – seetha lakshmi May 23 '18 at 15:25
  • 1
    Try `http://api.cloudsight.ai/v1/images`. Also when you say it didn't work, what error did you get? – mccalljt May 23 '18 at 22:46