For GET and POST requests for a private server I work with I use in Google Sheets, do something like this, and I get a proper response. I use that response to update data and just as importantly for error checking by evaluating response.getResponeCode().

function postDataToServer(params){
  let myjdService = getService();
  let orgId = getOrgIdForSelectedOrg();
  let link = https://GoodURLForPrivateDataIWorkWithALot/neededurlParameter/anotherNeededURLParameter;
  let options = {
    'method': 'put',
    'payload': JSON.stringify(params),
    'headers': {
      'Accept': 'application/vnd.PRIVATE.v3+json',
      'Content-Type': 'application/vnd.PRIVATE.v3+json',
      'authorization': 'Bearer ' + myPrivateService.getAccessToken()
    }
  };
  let response = UrlFetchApp.fetch(link, options);
  return response.getResponseCode();

For all the GET and POST requests I do, I get a response. And from that response I can parse a response code. But for the specific server I work with, when I edit a record using PUT, a successful edit returns this:

204 No Content

And further, the last line return response.getResponseCode() returns an error the response is undefined.

Here's the error I get for doing anything with response:

ReferenceError: response is not defined

The PUT is working. I only know this because 1) when I check if edits are made with the server, they are 2) testing the PUT in Postman at least shows me the words "204 No Content" and 3) the documentation says that's exactly what I should expect.

But I still would like to find out how to evaluate this no-content response in my Google Sheets App for proper error tracking. At least some way to get the string "204". Any ideas? I can't even get Google Sheets to do say 204.

0

There are 0 answers