Take the 2-minute tour ×

I've been trying a few combinations but can't seem to come up with something that works. More information about the API I'm asking about can be found here https://developers.google.com/admin-sdk/directory/v1/reference/users/insert . I have a feeling I'm just not setting up the request correctly. The following bit of code is known to work. I use it to set up the client that is able to query all the users.

client = Google::APIClient.new(:application_name => "myapp", :version => "v0.0.0")
client.authorization = Signet::OAuth2::Client.new(
     :scope => "https://www.googleapis.com/auth/admin.directory.user",
     :issuer => issuer,
     :signing_key => key,
     :person => user + "@" + domain)
api = client.discovered_api("admin", "directory_v1")

When I try to use the following code

parameters = Hash.new
parameters["password"] = "ThisIsAPassword"
parameters["primaryEmail"] = "tstacct2@" + domain
parameters["name"] = {"givenName" => "Test", "familyName" => "Account2"}
parameters[:api_method] = api.users.insert
response = client.execute(parameters)

I always get back the same error "code": 400, "message": "Invalid Given/Family Name: FamilyName"

I've observed a few things while looking into this particular API. If I print out the parameters for both the list and the insert functions e.g

puts "--- Users List ---"
puts api.users.list.parameters
puts "--- Users Insert ---"
puts api.users.insert.parameters

Only the List actually displays the parameters

--- Users List ---
--- Users Insert ---

This leaves me wondering if the ruby client is unable to retrieve the api and therefore unable to submit the request correctly or if I'm just doing something completely wrong.

I'd appreciate any idea's or direction that might help set me on the right path.

Thank you,


share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

You need to supply an Users resource in the request body, which is also the reason why you don't see it in the params. So the request should look like:

# code dealing with client and auth

api = client.discovered_api("admin", "directory_v1")

new_user = api.users.insert.request_schema.new({
  'password' => 'aPassword',
  'primaryEmail' => 'testAccount@myDomain.mygbiz.com',
  'name' => {
    'familyName' => 'John',
    'givenName' => 'Doe'

result = client.execute(
  :api_method => api.users.insert,
  :body_object => new_user
share|improve this answer
I should have realized that from using the Drive API. Thank you for the help. I successfully created a user following your example. –  James Woodward Aug 30 '13 at 13:07
add comment

Your Answer


