I've been reading this documentation on how to update custom attributes for users. From how this is written, it seems as though I would be able to do the following:
email = "[email protected]"
results = service.users().list(domain="a.com",projection="full",query='email={0}'.format(email)).execute()
if len(results["users"]) == 1:
user = results["users"][0]
user["customSchemas"]["TEST"] = "TEST"
try:
userResponse = service.users().update(userKey=email, body=user).execute()
except HttpError, e:
print(e)
However, I am thrown the error:
https://www.googleapis.com/admin/directory/v1/users/test%40test.com?alt=json returned "Not Authorized to access this resource/api">
I'm not sure if the error is because I am trying to update the fields incorrectly, if the escaping of the @
in the url is causing issues, or if I don't have the proper scopes (I am using https://www.googleapis.com/auth/admin.directory.user, https://www.googleapis.com/auth/admin.directory.domain, https://www.googleapis.com/auth/admin.directory.userschema
).
How can I create custom attributes (for everyone) and update them for a user using the python SDK?