gpt4 book ai didi

google-apps-script - 通过 Appmaker 在 JSON 中添加空格和 LR

转载 作者:行者123 更新时间:2023-12-03 05:03:30 26 4
gpt4 key购买 nike

我正在 AppMaker 中创建新的员工/用户配置工作流程。我正在创建一个新的 G Suite 用户,我的 JSON 中的空格遇到了一个非常奇怪的问题。它导致错误:GoogleJsonResponseException:API调用directory.users.insert失败,错误:

Invalid Input at provisionUser (AdminDirectory:5)

我已经对此进行故障排除一段时间了,似乎在 AppMaker 和 AdminDirectory 调用之间的某个地方,一些额外的空格和硬回车被插入到我的用户数据中。下面我将展示:

  1. 用于收集用户信息的客户端代码
  2. 服务器端用户创建脚本
  3. 用户 JSON 的控制台输出
  4. 发送到我的电子邮件以进行故障排除的用户 JSON 的输出
  5. 在 Notepad++ 中看到的通过电子邮件发送的输出

客户端代码

...a bunch of data gathering from a form, then...
var user = {
primaryEmail: email,
name: {
givenName: firstName,
familyName: lastName
},
addresses: [{
type: 'work',
formatted: address
}],
organizations: [{
title: title,
department: department,
fullTimeEquivalent: ftpt
}],
phones: [{
type: 'work',
value: phone
}],
locations: [{
buildingId: building,
type: 'desk',
area: 'desk'
}],
password: 'xxxxxxxx',
changePasswordAtNextLogin: true,
orgUnitPath: orgUnit,
relations: [{
type: 'manager',
value: supervisor
}],
customSchemas: {
sclsnj: {
startDate: effective,
mls: mls,
location: location
}
}
};
google.script.run.provisionUser(user, grouparray);

服务器端代码

function provisionUser(user, grouparray) {
user = JSON.stringify(user);
MailApp.sendEmail('lhoffman@xxxxxxxx.org', 'New Google User', user);
console.log(user);
user = AdminDirectory.Users.insert(user);
for (var g = 0; g < grouparray.length; g++) {
var groupEmail = grouparray[g] + '@xxxxxxxx.org';
var member = {
email: user,
role: 'MEMBER'
};
Logger.log(groupEmail);
AdminDirectory.Members.insert(member, groupEmail);
}
}

控制台输出

{"primaryEmail":"jsmith@xxxxxxxx.org","name":{"givenName":"John","familyName":"Smith"},"addresses":[{"type":"work","formatted":"Bound Brook branch\n402 E High Street, Bound Brook, NJ 08805"}],"organizations":[{"title":"Library Technician","department":"Adult Services","fullTimeEquivalent":100000}],"phones":[{"type":"work","value":"908-458-8410"}],"locations":[{"buildingId":"BBROOK","type":"desk","area":"desk"}],"password":"xxxxxxxx","changePasswordAtNextLogin":true,"orgUnitPath":"/Branches/Bound Brook branch","relations":[{"type":"manager","value":"msmith@xxxxxxxx.org"}],"customSchemas":{"sclsnj":{"startDate":"2019-05-20T04:00:00.000Z","mls":false,"location":"Bound Brook branch"}}}

电子邮件输出

{"primaryEmail":"jsmith@xxxxxxxx.org","name":{"givenName":"John","familyName":"Smith"},"addresses":[{"type":"work","formatted":"Bound  
Brook
branch\n402 E High Street, Bound Brook, NJ
08805"}],"organizations":[{"title":"Library Technician","department":"Adult
Services","fullTimeEquivalent":100000}],"phones":[{"type":"work","value":"908-458-8410"}],"locations":[{"buildingId":"BBROOK","type":"desk","area":"desk"}],"password":"xxxxxxxx","changePasswordAtNextLogin":true,"orgUnitPath":"/Branches/Bound
Brook
branch","relations":[{"type":"manager","value":"msmith@xxxxxxxx.org"}],"customSchemas":{"sclsnj":{"startDate":"2019-05-20T04:00:00.000Z","mls":false,"location":"Bound
Brook branch"}}}

Notepad++ 中的电子邮件输出(带控制字符)

Output with Control Characters.jpg

注意:我意识到 JSON 实际上在图像中表示了两次,但您绝对可以看到那里有多余的空格和左提要字符。

我已经确认,我可以使用 Google API Explorer 向用户配置控制台输出,并将其复制并粘贴到 Directory API Users.insert 的请求正文中。

我还确认,通过电子邮件发送的输出版本无法使用相同的方法工作。当我将该版本粘贴到 API Explorer 中的请求正文中时,我收到错误警报,并且从正文字段中的颜色编码可以清楚地看出它不正确。即使我不将输出通过电子邮件发送给自己,我也会得到相同的错误行为,因此我非常确定发送电子邮件的行为不会把事情搞砸。

救命!!

最佳答案

无效输入是由于特定字段格式不正确造成的。就您而言,我发现您正在使用自定义架构。自定义架构中有一个特定字段的格式不正确,即 startDate。只需使用 2019-05-20,而不是提供 2019-05-20T04:00:00.000Z 的值。

原因是该字段需要仅完整日期值,而不是完整日期加上小时和分钟。正如您在 ISO-8601 date format 上看到的那样,完整日期格式为YYYY-MM-DD

引用:https://developers.google.com/admin-sdk/directory/v1/reference/schemas/insert

关于google-apps-script - 通过 Appmaker 在 JSON 中添加空格和 LR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56065738/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com