【问题标题】:Clearing DATE field in Google Admin SDK API清除 Google Admin SDK API 中的 DATE 字段
【发布时间】:2021-09-21 21:59:02
【问题描述】:

这里有任何 Google 工作区开发人员吗? 我有一些我想通过 API 清除的用户字段。 使用
方法:users.update

https://developers.google.com/admin-sdk/directory/reference/rest/v1/users/update

如果我以“”的形式传递一个空值,它会尝试清除某些字段的用户属性。它适用于布尔值和字符串(到目前为止我已经测试过) 但不适用于 DATE 字段。 这是我发送的 JSON

{
    "customSchemas":  {
                          "includeInGlobalAddressList":  "true",
                          "OffBoarding":  {
                                                 "abooleanvalue1":  "",
                                                 "astringvalue1":  "",
                                             },
                          "General":  {
                                             "aDateValue":  ""
                                         }
                      }
}

返回

{
  "error": {
    "code": 400,
    "message": "Invalid Input",
    "errors": [
      {
        "message": "Invalid Input",
        "domain": "global",
        "reason": "invalid"
      }
    ]
  }
}

如果我使用相同的格式设置一个值,它会成功更新该值

{
    "customSchemas":  {
                          "includeInGlobalAddressList":  "true",
                          "OffBoarding":  {
                                                 "abooleanvalue1":  "",
                                                 "astringvalue1":  "",
                                             },
                          "General":  {
                                             "aDateValue":  "2020-01-01"
                                         }
                      }
}

会正常工作。

我尝试使用 GAM 对其进行测试。一样 gam 更新用户 test.user@comany.com OffBoarding.astringvalue1 "" 会起作用,但如果我在日期字段上做同样的事情。
gam 更新用户 test.user@comany.com General.aDateValue ""
错误:400:无效输入 - 无效

到目前为止,我的谷歌搜索没有找到任何相关的东西,或者我需要更多的咖啡。我能找到的最接近的是这个线程 Unable to clear Google user property completely 但这归因于实际问题,我已尝试发送

[] [""] 空值 正如他们在那里建议的那样,到目前为止还没有运气。

【问题讨论】:

    标签: google-admin-sdk google-workspace


    【解决方案1】:

    重置date 类型的用户属性的方法是将其设置为null

    {
        "customSchemas":  {
                              "includeInGlobalAddressList":  "true",
                              "OffBoarding":  {
                                                     "abooleanvalue1":  "",
                                                     "astringvalue1":  "",
                                                 },
                              "General":  {
                                                 "aDateValue":  null
                                             }
                          }
    }
    

    【讨论】:

    • 谢谢,这是正确的。昨晚我也从一个redditor那里得到了一些帮助。我忽略了我使用 Powershell 作为我的代码语言的事实,并且我在尝试时错误地设置了 NULL 值。因为我已经使用 converto-json 将我的对象转换为 json 格式。我尝试了 value = "null" 或 value = null 当我不得不使用 convert-tojson 时不起作用,正确的方法是设置 value = $null 然后转换为提供不带引号的 null 的 JSON。这提供了预期的结果。
    猜你喜欢
    • 2015-09-23
    • 2013-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-17
    • 2013-06-07
    • 2013-10-25
    相关资源
    最近更新 更多