0

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 test.user@comany.com OffBoarding.astringvalue1 "" will work but if I do the same on a date field.
gam update user test.user@comany.com 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.

k0d3r3d
  • 23
  • 1
  • 4

1 Answers1

0

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

{
    "customSchemas":  {
                          "includeInGlobalAddressList":  "true",
                          "OffBoarding":  {
                                                 "abooleanvalue1":  "",
                                                 "astringvalue1":  "",
                                             },
                          "General":  {
                                             "aDateValue":  null
                                         }
                      }
}
ziganotschka
  • 25,866
  • 2
  • 16
  • 33
  • 1
    Thanks, this is correct. I also got some help with this last night as well from a redditor. I omitted the fact that I was using Powershell as my code language and I was incorrectly setting the NULL value when I tried it. As I have convert my objects to json format using converto-json . I tried value = "null" or value = null which did not work when I had to use convert-tojson the correct approach is to set value = $null and then convert to JSON which provided null without quotes. This provided the desired results. – k0d3r3d Sep 22 '21 at 15:30