Я потратил большую часть дня, пытаясь выяснить правильное тело JSON и аргументы для обновления OU; Я на самом деле пытаюсь переименовать OU. Я близко, но в любом случае решение до сих пор ускользнуло от меня.
Я уже ссылался на эти документы:
Я пробовал несколько вариантов аргументов в объекте с параметрами, передаваемыми в AdminDirectory.Orgunits.update. В конечном счете, примеров нет, поэтому я не на 100% уверен в правильности параметров.
Вот и моя тестовая функция:
function test_renameOU(){
/* Args:
customerId: string, Immutable ID of the G Suite account (required)
orgUnitPath: string, Full path of the organizational unit or its ID (required) (repeated)
body: object, The request body. (required)
The object takes the form of:
{ # JSON template for Org Unit resource in Directory API.
"kind": "admin#directory#orgUnit", # Kind of resource this is.
"parentOrgUnitPath": "A String", # Path of parent OrgUnit
"name": "A String", # Name of OrgUnit
"etag": "A String", # ETag of the resource.
"orgUnitPath": "A String", # Path of OrgUnit
"parentOrgUnitId": "A String", # Id of parent OrgUnit
"blockInheritance": True or False, # Should block inheritance
"orgUnitId": "A String", # Id of OrgUnit
"description": "A String", # Description of OrgUnit
}
*/
/* Function to perform rename */
function renameOU(customerId, orgUnitPath, body){
Logger.log(customerId + ", " + orgUnitPath + ", " + JSON.stringify(body))
try{
var org = AdminDirectory.Orgunits.update(customerId, orgUnitPath, body)
}catch(e){
Logger.log(JSON.stringify(e));
}
}
/* Arguments */
var customerId = 'my_customer';
var oldOUname = "Education";
var parentOrgUnitPath = "/Users/200 COGS";
var orgUnitId = "id:03ph8a2z39wdr3v";
var orgUnitPath = parentOrgUnitPath + "/" + oldOUname;
var parentOrgUnitId = "id:03ph8a2z1lakohp";
var newOUname = "255 Education";
Logger.log(orgUnitPath);
var body = { //# JSON template for Org Unit resource in Directory API.
"kind": "admin#directory#orgUnit", //# Kind of resource this is.
"parentOrgUnitPath": parentOrgUnitPath, //# Path of parent OrgUnit
"name": newOUname, //# Name of OrgUnit
"orgUnitPath": parentOrgUnitPath + "/" + newOUname, //# Path of OrgUnit
"parentOrgUnitId": parentOrgUnitId, //# Id of parent OrgUnit
"blockInheritance": false, //# Should block inheritance
"orgUnitId": orgUnitId, //# Id of OrgUnit
}
/* Call Rename Function */
Logger.log(customerId + ", " + orgUnitId + ", " + JSON.stringify(body))
renameOU(customerId, orgUnitId, body)
}
Я ожидаю, что результат OU изменится с "/ Users / 200 COGS / Education" на "/ Users / 200 COGS / 255 Education".
Вывод является ошибкой разбора:
[19-06-17 17:39:39:165 PDT] /Users/200 COGS/Education
[19-06-17 17:39:39:166 PDT] my_customer, id:03ph8a2z39wdr3v, {"kind":"admin#directory#orgUnit","parentOrgUnitPath":"/Users/200 COGS","name":"255 Education","orgUnitPath":"/Users/200 COGS/255 Education","parentOrgUnitId":"id:03ph8a2z1lakohp","blockInheritance":false,"orgUnitId":"id:03ph8a2z39wdr3v"}
[19-06-17 17:39:39:166 PDT] my_customer, id:03ph8a2z39wdr3v, {"kind":"admin#directory#orgUnit","parentOrgUnitPath":"/Users/200 COGS","name":"255 Education","orgUnitPath":"/Users/200 COGS/255 Education","parentOrgUnitId":"id:03ph8a2z1lakohp","blockInheritance":false,"orgUnitId":"id:03ph8a2z39wdr3v"}
[19-06-17 17:39:39:198 PDT] {"message":"API call to directory.orgunits.update failed with error: Parse Error","name":"GoogleJsonResponseException","fileName":"GSuiteOrgUnits","lineNumber":573,"stack":"\tat GSuiteOrgUnits:573 (renameOU)\n\tat GSuiteOrgUnits:600 (test_renameOU)\n","details":{"message":"Parse Error","code":400,"errors":[{"domain":"global","reason":"parseError","message":"Parse Error"}]}}