Search code examples
google-admin-sdkgoogle-workspace

Clearing DATE field in Google Admin SDK API


Any Google workspace DEV's here? I have some fields for my users I am trying to clear via the API. using
Method: users.update

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

If I pass a null value in the form of "" it to try and clear some fields user attributes. It works for Boolean values and Strings (that I've tested so far) But not for DATE fields. Here is the JSON i Am sending

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

returns

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

if i use the same format to set a value , it updates the value successfully

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

will work fine.

I tried to test it out with GAM . Same thing gam update user [email protected] OffBoarding.astringvalue1 "" will work but if I do the same on a date field.
gam update user [email protected] General.aDateValue ""
ERROR: 400: Invalid Input - invalid

My google searching thus far has not turned up anything relevant, either that or I need more coffee. Closest I could find was this thread Unable to clear Google user property completely But that was attributed to an actual issue, and i've tried sending

[] [""] null as they suggested there , so far no luck.


Solution

  • The way to reset a user property of type date is setting it to null :

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