Search code examples
restgoogle-apps-scriptzoom-sdk

How can i resolve an error occurring when sending a patch from the Zoom API using Google Apps Script


I attempted to send a patch of the Zoom API update user setting using GAS(Google-apps-script). However, the following error occurs.

it has been confirmed that the API operates without problems in Postman. there appears to be no problem with the OAuth token itself.

Given the following code :

function test_updateUserSetting(){

  let userEmail = "Zoom User Email"
  let url = 'https://api.zoom.us/v2/users/' + userEmail + '/settings'

  const token = getToken() // get OAuth token
  Logger.log(token)


  let raw = JSON.stringify({
    "feature": {
      "webinar": true,
      "webinar_capacity": 500
    }
  });

  let requestOptions = {
    'method' :  'PATCH',
    'contentType': 'application/json',
    'headers': {'Authorization' : 'Bearer ' + token},
    'payload': raw
  };

  let response = UrlFetchApp.fetch(url, requestOptions);
  let user = JSON.parse(response.getContentText());
  console.log(user)
}

Error message that occurred :

SyntaxError: Unexpected end of JSON input

what part of the code needs to be modified to make it work properly?

I'm trying the Update User Setting API of ther Zoom API. The relevant reference URL for that API is as follows : https://developers.zoom.us/docs/api/rest/reference/zoom-api/methods/#operation/userSettingsUpdate


Solution

  • I solved this problem by modifying the code as follows.
    The cause of the error was that the return value of the API transmission returned as blank.
    To solve this problem, the code was modified to treat the API transmission as successful if the response code was 204.

    function test_updateUserSetting(){
    
      let userEmail = "Zoom User Email"
      let url = 'https://api.zoom.us/v2/users/' + userEmail + '/settings'
    
      const token = getToken() // get OAuth token
      Logger.log(token)
    
    
      let raw = JSON.stringify({
        "feature": {
          "webinar": true,
          "webinar_capacity": 500
        }
      });
    
      let requestOptions = {
        'method' :  'PATCH',
        'contentType': 'application/json',
        'headers': {'Authorization' : 'Bearer ' + token},
        'payload': raw
      };
    
      try{
        let response = UrlFetchApp.fetch(url, requestOptions);
        if(response.getResponseCode() === 204){
          console.log("update successed")
          return true
        }else{
          console.log("update failed")
          return false
        }
      } catch(e){
        console.log(e)
        return false
      }
    }