【问题标题】:Insert an Org Unit with Google Apps Script getting Bad Request error插入带有 Google Apps 脚本的组织单位收到错误请求错误
【发布时间】:2021-03-22 23:44:06
【问题描述】:

我已按照 API 文档插入组织单位,但收到“错误请求”错误。这是我的代码的 sn-p。

function orgUnitCreate() {
  var resource = {
    name: first+' '+init,
    parentOrgUnitPath: '/Students/'+unit,
    blockInheritance: false
  };
  
  AdminDirectory.Orgunits.insert(resource, "myCustomerID redacted for privacy");//This is the line throwing the error
}

感谢您的帮助

编辑:我的客户 ID 确实有错误,谢谢

【问题讨论】:

  • 您的 sn-p 对我来说工作得很好,但我可以通过给它一个无效的客户 ID 来重现“错误请求”,因此您可能需要检查您是否使用了正确的 ID。

标签: google-apps-script google-admin-sdk organizational-unit


【解决方案1】:
function orgUnitCreate() {
   var resource = {
       name: first+' '+init,
       parentOrgUnitPath: '/Students/'+unit,
       blockInheritance: false
   };
   try {
      resp= AdminDirectory.Orgunits.insert(resource, "my_customer"); 
   } catch (e) {
      resp = e; //Catch The error
   }
   Logger.log(resp);
}

【讨论】:

    【解决方案2】:

    此错误可能是由于

    • 未提供必填字段或参数。
    • 提供的值或提供的字段组合无效。

    400 Bad Request response status code indicates that the server cannot or will not process the request due to something that is perceived to be a client error

    总结

    如评论部分所述,此问题可能是由缺少/不正确的客户 ID 引起的。

    参考

    【讨论】:

      猜你喜欢
      • 2019-12-09
      • 2019-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多