Determining the parameters for "discovered_api"

1k views Asked by At

This might be a really stupid question, but how do you determine the parameters to pass in the client "discovered_api" call? and then what is the executed "api_method"

For instance, I'm trying to call the Admin SDK Users List call which is "GET https://www.googleapis.com/admin/directory/v1/users".

There doesn't seem to be a clear way of extracting this from the API reference, or am I just looking in the wrong place?

2

There are 2 answers

1
James Woodward On BEST ANSWER

I misunderstood the original question. I still think the other post is potentially valuable so I thought I'd add a new answer.

I experimented a bit and this will display the Title, id and whether or not it is preferred. The ID has a colon which seems to be where you separate the first and second argument when calling discovered_api.

puts "Title \t ID \t Preferred"
client.discovered_apis.each do |gapi| 
  puts "#{gapi.title} \t #{gapi.id} \t #{gapi.preferred}"
end
1
James Woodward On

I had this exact question. And for methods like get I figured it out.

Create your client and then do the following

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

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

puts "--- Users Get ---"
puts api.users.get.parameters

This will print off the parameters. You can also use api.users.get.parameter_descriptions

Something that could be helpful if you are trying to probe into issues like this is to print off all the available methods. I typically do it like this.

puts api.users.insert.methods - Object.methods

If you try that one you will see that api.users.insert has the following methods after you take away the ones that are common to every object.

discovery_document
api
method_base
method_base=
description
id
http_method
uri_template
media_upload
request_schema
response_schema
normalize_parameters
generate_uri
generate_request
parameter_descriptions
parameters
required_parameters
optional_parameters
validate_parameters

I hope that helps.

James