0

While creating gsuite user using directory api (python lib: google-api-python-client), values of certain parameters,viz., "emails", "externalIDs", "phones", "organisations", "gender", and all others that do not have simple string values, but rather accept values as an object or an array of objects, are not being uploaded despite using the described format in the references.

The python template is strictly followed from here and the values inserted are in accordance with the Request Body mentioned in this.

Although the user is being created successfully, but I am unable to feed values to the following parameters:

emails, phones, externalIds, gender

Even copying a json example from here, giving the appropriate values and executing here didn't produce required results.

Is this the issue with directory-api itself?

eg of body sent to the insert function as arg:

{'addresses': '',
'posixAccounts': '',
'thumbnailPhotoEtag': '',
'suspended': False,
'keywords': '',
'aliases': [],
'nonEditableAliases': [],
'suspensionReason': '',
'thumbnailPhotoUrl': '',
'isAdmin': False,
'relations': '',
'languages': '',
'ims': '',
'lastLoginTime': '',
'orgUnitPath': '',
'agreedToTerms': True,
'ipWhitelisted': True,
'sshPublicKeys': '',
'primaryEmail': 'abcdef@org.in',
'password': 'SXXXXXXXXU',
'emails': [{'customType': '',
'type': 'home',
'primary': False,
'address': 'abctest02@gmail.com'},
{'customType': '',
'type': 'work',
'primary': True,
'address': 'abcdef@org.in'}],
'organizations': '',
'kind': 'admin#directory#user',
'hashFunction': None,
'name': {'fullName': 'abcTT def',
'givenName': 'abcTT',
'familyName': 'def'},
'gender': {'customGender': '',
'type': 'male'},
'notes': '',
'creationTime': '',
'phones': ([{'type': 'work',
'value': '+91 123 456 7895'}],),
'locations': '',
'isDelegatedAdmin': False,
'id': '',
'customSchemas': {},
'deletionTime': '',
'isEnrolledIn2Sv': False,
'includeInGlobalAddressList': True,
'etag': '',
'externalIds': [{'type': 'organization',
'value': '22222222'}],
'isEnforcedIn2Sv': False,
'isMailboxSetup': False,
'websites': '',
'changePasswordAtNextLogin': True,
'customerId': ''}
aashu
  • 105
  • 1
  • 14
  • 1
    Possible similar question may be: https://stackoverflow.com/questions/32345670/cannot-update-user-email-addresses-via-google-admin-directory-api-client-library?rq=1 But is there any chance to make this work on python only – aashu Dec 24 '17 at 23:24
  • Have you tried Googling for [Executing cURL in Python](https://stackoverflow.com/a/25491297)? – ReyAnthonyRenacia Dec 26 '17 at 12:40
  • That I have kept it as the last resort. Thanks for the suggestion, but actually I am looking for any solution to the api problem. Because I need to use google-api's "batch http request" for a bulk of requests. – aashu Dec 26 '17 at 18:11

1 Answers1

0

This looks like (at least for three of the four) down to the way you're presenting the arguments and a couple of syntax errors:

  • Emails - you're listing 'type' work and then trying to use a null custom type when type isn't custom, which will stop the variable setting. You're also trying to set the same e-mail address as primary twice which it might object to.
  • Phones - extraneous round brackets
  • Gender again custom is showing where it may not be meant to.
  • External IDs is a little tricker, but I have it working my end with the code below

So a sample command that would create a user with those variables working might be (I like passing my data to a variable first):

userinfo = {'name': {'givenName': 'Test', 'familyName': 'User'}, 
'password': '456weakpass62£&', 'primaryEmail': 'Test.User@fakedomain.com',
'emails': [{'type': 'home', 'address': 'abctest02@gmail.com'}, 
{'type': 'work', 'value': 'Test.User@fakedomain.com'}], 'phones': 
[{'type': 'work', 'value': '567234890', 'primary': 'True'}], 'gender':
{'type': 'male'}, 'externalIds: [{'type': 'organization', 'value': '123'}]

service.users().insert(body=userinfo).execute()

This response may be a wee bit belated but hopefully it'll help.

TorTurner
  • 11
  • 4