使用应用程序脚本更改 gsuite 签名 returns "isDefault cannot be toggled to false"
Changing gsuite signature with apps script returns "isDefault cannot be toggled to false"
正在尝试使用 Google Apps 脚本为用户设置签名。我已经设置了一个服务帐户并确保范围正确,但是当我测试代码时 returns 出现以下错误:
"error": {
"errors": [
{
"domain": "global",
"reason": "invalidArgument",
"message": "isDefault cannot be toggled to false"
}
],
"code": 400,
"message": "isDefault cannot be toggled to false"
}
}
代码如下:
function setUserSignature() {
var resource ={
"sendAsEmail": "email@mycompany.be",
"displayName": "Name Lastname",
"replyToAddress": "email@mycompany.be",
"signature": "Test Signature",
"isDefault": true,
"treatAsAlias": true
}
var service = serviceAccount("serviceaccount@mydomain.be");
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@mycompany.be' +'/settings/sendAs/'+'email@alias.be';
var response = UrlFetchApp.fetch(url,options);
Logger.log(response.getContentText());
}
}
如果其他人遇到同样的问题:
显然使用 PATCH 而不是 PUT 解决了这个问题。
正在尝试使用 Google Apps 脚本为用户设置签名。我已经设置了一个服务帐户并确保范围正确,但是当我测试代码时 returns 出现以下错误:
"error": { "errors": [ { "domain": "global", "reason": "invalidArgument", "message": "isDefault cannot be toggled to false" } ], "code": 400, "message": "isDefault cannot be toggled to false" } }
代码如下:
function setUserSignature() {
var resource ={
"sendAsEmail": "email@mycompany.be",
"displayName": "Name Lastname",
"replyToAddress": "email@mycompany.be",
"signature": "Test Signature",
"isDefault": true,
"treatAsAlias": true
}
var service = serviceAccount("serviceaccount@mydomain.be");
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@mycompany.be' +'/settings/sendAs/'+'email@alias.be';
var response = UrlFetchApp.fetch(url,options);
Logger.log(response.getContentText());
}
}
如果其他人遇到同样的问题:
显然使用 PATCH 而不是 PUT 解决了这个问题。