Reputation: 1303
I'm trying to insert a new user under my Google Admin account:
def insertNewUser(directory_service):
params = {
'name': {
'familyName': 'Testfamilyname',
'givenName': 'TestgivenName',
},
'password': 'testpassword',
'primaryEmail': 'testemail@mycompanydomain',
}
result = directory_service.users().insert(body=params).execute()
After executing this code I get the following error message:
googleapiclient.errors.HttpError: <HttpError 404 when requesting https://www.googleapis.com/admin/directory/v1/users?alt=json returned "Resource Not Found: domain">
I have no idea what can it mean and how to solve the problem? Are there any examples of inserting users using Google Admin API?
I tried adding the domain in the request but it didn't help, e.g.:
params = {
'name': {
'familyName': 'Testfamilyname',
'givenName': 'TestgivenName',
},
'password': 'testpassword',
'primaryEmail': 'testemail@mycompanydomain',
'organizations': {
'domain': 'mycompanydomain',
}
}
or:
params = {
'name': {
'familyName': 'Testfamilyname',
'givenName': 'TestgivenName',
},
'password': 'testpassword',
'primaryEmail': 'testemail@mycompanydomain',
'domain': 'mycompanydomain',
}
I'm quite sure I'm authenticating correctly, since I'm able to execute get-like requests, like list all current users under my account.
I tried to execute the same query using Google API explorer: https://developers.google.com/admin-sdk/directory/v1/reference/users/insert and it works fine there.
I've also seen the following post: 404 Resource Not Found: domain with Google Direcotry API and maybe the solution is similar, however I couldn't find how to create a user object with the API in Python. There are no examples available either.
Upvotes: 1
Views: 868
Reputation: 1303
I found the mistake. The domain should of course end with ".com". The correct request is:
def insertNewUser(directory_service):
params = {
'name': {
'familyName': 'Testfamilyname',
'givenName': 'TestgivenName',
},
'password': 'testpassword',
'primaryEmail': '[email protected]',
}
result = directory_service.users().insert(body=params).execute()
Upvotes: 1