Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trouble Creating Users #360

Closed
MattMencel opened this issue Feb 16, 2016 · 3 comments
Closed

Trouble Creating Users #360

MattMencel opened this issue Feb 16, 2016 · 3 comments
Assignees
Labels
🚨 This issue needs some love. triage me I really want to be triaged.

Comments

@MattMencel
Copy link

I'm trying to generate user accounts with the API. I've run the sample code that does "list users" and get the first 10 users in my domain. When I try to do an insert with a test user object, I get back the "Invalid Given/Family Name". I can't figure out what I'm doing wrong here....

# Initialize the API
service = Google::Apis::AdminDirectoryV1::DirectoryService.new
service.client_options.application_name = APPLICATION_NAME
service.authorization = authorize
# List the first 10 users in the domain
user_object = {
  'primaryEmail' => 'help@here.edu',
  'name' => {
    'givenName' => 'Test',
    'familyName' => 'User'
  },
  'password' => initial_password,
  'changePasswordAtNextLogin' => true
}

response = service.insert_user(user_object)
puts response
exit

The error I get is this...

$ bundle exec ./prep_account.rb
/Users/matt/.chefdk/gem/ruby/2.1.0/gems/google-api-client-0.9/lib/google/apis/core/http_command.rb:202:in `check_status': invalid: Invalid Given/Family Name: FamilyName (Google::Apis::ClientError)
    from /Users/matt/.chefdk/gem/ruby/2.1.0/gems/google-api-client-0.9/lib/google/apis/core/api_command.rb:103:in `check_status'
    from /Users/matt/.chefdk/gem/ruby/2.1.0/gems/google-api-client-0.9/lib/google/apis/core/http_command.rb:170:in `process_response'
    from /Users/matt/.chefdk/gem/ruby/2.1.0/gems/google-api-client-0.9/lib/google/apis/core/http_command.rb:275:in `execute_once'
    from /Users/matt/.chefdk/gem/ruby/2.1.0/gems/google-api-client-0.9/lib/google/apis/core/http_command.rb:107:in `block (2 levels) in execute'
    from /Users/matt/.chefdk/gem/ruby/2.1.0/gems/retriable-2.1.0/lib/retriable.rb:54:in `block in retriable'
    from /Users/matt/.chefdk/gem/ruby/2.1.0/gems/retriable-2.1.0/lib/retriable.rb:48:in `times'
    from /Users/matt/.chefdk/gem/ruby/2.1.0/gems/retriable-2.1.0/lib/retriable.rb:48:in `retriable'
    from /Users/matt/.chefdk/gem/ruby/2.1.0/gems/google-api-client-0.9/lib/google/apis/core/http_command.rb:104:in `block in execute'
    from /Users/matt/.chefdk/gem/ruby/2.1.0/gems/retriable-2.1.0/lib/retriable.rb:54:in `block in retriable'
    from /Users/matt/.chefdk/gem/ruby/2.1.0/gems/retriable-2.1.0/lib/retriable.rb:48:in `times'
    from /Users/matt/.chefdk/gem/ruby/2.1.0/gems/retriable-2.1.0/lib/retriable.rb:48:in `retriable'
    from /Users/matt/.chefdk/gem/ruby/2.1.0/gems/google-api-client-0.9/lib/google/apis/core/http_command.rb:96:in `execute'
    from /Users/matt/.chefdk/gem/ruby/2.1.0/gems/google-api-client-0.9/lib/google/apis/core/base_service.rb:267:in `execute_or_queue_command'
    from /Users/matt/.chefdk/gem/ruby/2.1.0/gems/google-api-client-0.9/generated/google/apis/admin_directory_v1/service.rb:3108:in `insert_user'
    from ./prep_account.rb:62:in `<main>'
@sqrrrl
Copy link
Contributor

sqrrrl commented Feb 16, 2016

The ruby client uses snake case (as per ruby convention) in the generated interfaces.

# Initialize the API
service = Google::Apis::AdminDirectoryV1::DirectoryService.new
service.client_options.application_name = APPLICATION_NAME
service.authorization = authorize
# List the first 10 users in the domain
user_object = {
  'primary_email' => 'help@here.edu',
  'name' => {
    'given_name' => 'Test',
    'family_name' => 'User'
  },
  'password' => initial_password,
  'change_password_at_next_login' => true
}

response = service.insert_user(user_object)
puts response
exit

@sqrrrl sqrrrl closed this as completed Feb 16, 2016
@MattMencel
Copy link
Author

Ah thanks....I thought I'd tried that. Actually discovered you have to use the symbols, not just snake case strings which still didn't work.

As in...

user_object = {
  :primary_email => 'help@here.edu',
  :name => {
    :given_name => 'Test',
    :family_name => 'User'
  },
  :password => initial_password,
  :change_password_at_next_login => true
}

response = service.insert_user(user_object)
puts response

Also found the User and UserName class in the Representations file and that helped as well...

https://github.com/google/google-api-ruby-client/blob/master/generated/google/apis/admin_directory_v1/representations.rb

@felipe-branco
Copy link

felipe-branco commented Nov 16, 2016

Hi! I know this issue is closed, but i'm facing the same problem and the solutions suggested are not working for me.

The following solution works:

user_object = Google::Apis::AdminDirectoryV1::User.new
user_object.primary_email = 'help@here.edu'
user_object.name = Google::Apis::AdminDirectoryV1::UserName.new
user_object.name.given_name = 'Test'
user_object.name.family_name = 'User'
user_object.password = initial_password
user_object.change_password_at_next_login = true

Thanks.

@yoshi-automation yoshi-automation added triage me I really want to be triaged. 🚨 This issue needs some love. labels Apr 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚨 This issue needs some love. triage me I really want to be triaged.
Projects
None yet
Development

No branches or pull requests

4 participants