22

I'm getting an error response from the API that I'm using, but Google scripts seems to truncate the message. How can I see the full message in Google scripts?

This is the message:

Request failed for https://api.myintervals.com/task/ returned code 400. Truncated server response: {"personid":"180761","status":"Bad Request","code":400,"error":{"code":18,"message":"Validation error has occurred (missing required field/paramet... (use muteHttpExceptions option to examine full response) (line 171, file "IntervalsPull")

Rubén
  • 34,714
  • 9
  • 70
  • 166
Takeshi Patterson
  • 1,207
  • 6
  • 15
  • 29

2 Answers2

42

Just as @DrSatan1 pointed in the comment, pass muteHttpExceptions option in the parameter to suppress the exception and get the error returned as HTTPResponse.

options = {muteHttpExceptions: true};
var response = UrlFetchApp.fetch("https://api.myintervals.com/task/", options);
Logger.log(response.getContentText()); 

Now view your logs to see the complete error response.

m5khan
  • 2,667
  • 1
  • 27
  • 37
2

While setting response to logger or console works, even that will be truncated if the response is too long. You may have to set the response to Drive in such cases.

options.muteHttpExceptions = true;
const res = UrlFetchApp.fetch(url, options);
console.log(res.getResponseCode());
console.log(res);
DriveApp
    .getFoldersByName('test'/*A folder in Drive*/)
    .next() 
    .createFile(res.getBlob().setName('response'))
TheMaster
  • 45,448
  • 6
  • 62
  • 85