Cloudsight API not recognizing the parameters

157 Views Asked by At

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"}));
1

There are 1 best solutions below

2
On

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.