Why is the Kimono API responding to 404?

I am trying to update my kimono API via google script in sheets. There are a lot of URLs on the worksheet, but for this example, I showed only 2.

I get a 404 HTTP error. I checked, and apikey and id are ok.

How can I determine what is really wrong?

function PostParameters2() {

  var parameters = {
    apikey: "--apikey--",
    urls: [
      "https://twitter.com/search?q=%23running",
      "https://twitter.com/search?q=%23swimming"
    ]
  };

  var data = JSON.stringify(parameters);

  var url = 'https://kimonolabs.com/kimonoapis/--apiId--/update';

  var options = {
    'method': 'POST',
    'content-Type': 'application/json',
    'payload': data
  };

  var response = UrlFetchApp.fetch(url, options);
  Logger.log(response.getResponseCode());


}
+4
source share
1 answer

When debugging an external host connection, UrlFetchAppseveral tools are available.

  • muteHttpExceptions, . (, , , throw , .)

    'muteHttpExceptions' : true fetch.

    , fetch , HTTPResponse. ( ).

    , :

      var response = UrlFetchApp.fetch(url, options);
      var rc = response.getResponseCode();
      if (rc !== 200) {
        // HTTP Error
        Logger.log("Response (%s) %s",
                   rc,
                   response.getContentText() );
        // Could throw an exception yourself, if appropriate
      }
    

    , :

    [15-08-27 11:18:06:688 EDT] Response (404.0) {
      "error": true,
      "message": "Could not find API"
    }
    

    API- . , . , URL, API, . , , .

  • fetch, getRequest(). fetch() fetch().

    var test = UrlFetchApp.getRequest(url, options);
    

    , , test.

    POST. # %23 JSON.stringify(), .

    , , contentType 'application/json'.

    view debugger

, , contentType content-Type. .

, .

- encodeURIComponent(), fetch, . , "" , # UTF-8, %23.

:

function PostParameters2() {

  var parameters = {
    apikey: "--apikey--",
    urls: [
      encodeURIComponent("https://twitter.com/search?q=#running"),
      encodeURIComponent("https://twitter.com/search?q=#swimming")
    ]
  };

  var data = JSON.stringify(parameters);

  var url = 'https://kimonolabs.com/kimonoapis/--apiId--/update';

  var options = {
    'method': 'POST',
    'contentType': 'application/json',
    'payload': data,
    'muteHttpExceptions' : true
  };

  var test = UrlFetchApp.getRequest(url, options);
  var response = UrlFetchApp.fetch(url, options);
  var rc = response.getResponseCode();
  if (rc !== 200) {
    // HTTP Error
    Logger.log("Response (%s) %s",
               rc,
               response.getContentText() );
    // Could throw an exception yourself, if appropriate
  }
  else {
    // Successful POST, handle response normally
    var responseText = response.getContentText();
    Logger.log(responseText);
  }

}
+5

All Articles