I'm getting an error that google doesn't recognize the user names in the json. I cannot find a way to include the http header application/json. The return URL gives me another error code but I pass login authentication.
My code:
from __future__ import print_function
from apiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools
import requests
import json
import pprint
# Setup the Admin SDK Directory API
SCOPES = 'https://www.googleapis.com/auth/admin.directory.user'
#Global scope for access to all user and user alias operations.
store = file.Storage('credentials.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
creds = tools.run_flow(flow, store)
service = build('admin', 'directory_v1', http=creds.authorize(Http()))
# Call the Admin SDK Directory API
userInfo = {
"name" : {
"givenName" : "Donald",
"familyName" : "Dump",
},
"kind" : "user",
"primaryEmail" : "testUser@test.com",
"isAdmin": False,
"isDelegatedAdmin": False,
"agreedToTerms": True,
"password": "testpass1234",
"changePasswordAtNextLogin": True
}
response = service.users().insert(body=json.dumps(userInfo)).execute()