1
votes

Trying to set a signature for users using Google Apps Script. I've set up a service account and made sure the scopes are right, but when I test the code it returns the following error:

"error": { "errors": [ { "domain": "global", "reason": "invalidArgument", "message": "isDefault cannot be toggled to false" } ], "code": 400, "message": "isDefault cannot be toggled to false" } }

Code is as below:

function setUserSignature() {
      var resource ={
  "sendAsEmail": "[email protected]",
  "displayName": "Name Lastname",
  "replyToAddress": "[email protected]",
  "signature": "Test Signature",
  "isDefault": true,
  "treatAsAlias": true
}


var service = serviceAccount("[email protected]");
service.reset();
if (service.hasAccess()) {
    var options = {
      "muteHttpExceptions":true,
"method":"PUT",
"headers": {"authorization": "Bearer " + service.getAccessToken()},
      "body":resource


}
        var url = 'https://www.googleapis.com/gmail/v1/users/'+ '[email protected]' +'/settings/sendAs/'+'[email protected]';
        var response = UrlFetchApp.fetch(url,options);
        Logger.log(response.getContentText());
    }
}
1

1 Answers

2
votes

In case anyone else is having the same problem:

Apparently using PATCH instead of PUT solved the issue.