google-api-nodejs-client icon indicating copy to clipboard operation
google-api-nodejs-client copied to clipboard

Required Parameter "resource" gets deleted in apirequest.js

Open sankulka opened this issue 9 years ago • 4 comments

I am trying to use API cloudresourcemanager.projects.getIamPolicy which expects "resource" as required parameter in the request. However, "delete params.resource;" statement in apirequest.js deletes this "resource" parameter and the request fails.

My code snippet is as follows: var params = { auth: googleClient, resource: project, fields: 'bindings' }; googleapis.cloudresourcemanager('v1').projects.getIamPolicy (params, function (err, roles) { });

This call to getIamPolicy fails as the resource parameter is deleted by apirequest.js Kindly fix this or suggest a workaround.

Thanks! Santosh

sankulka avatar Mar 28 '17 11:03 sankulka

@tcoffee-google The example for getIamPolicy() looks ambiguous (specifically resource vs resource_) - can you take a look?

@sankulka Have you tried using resource_ (with an underscore at the end) instead of resource?

ace-n avatar Mar 28 '17 20:03 ace-n

@ace-n is correct, the confusion is due to renaming in the Node.js client library (these libraries are autogenerated, and happen to use the name resource for the request body, so parameters named resource are renamed to resource_).

You can see a Node.js code example for this method in the last tab under "Examples" at https://cloud.google.com/resource-manager/reference/rest/v1beta1/projects/getIamPolicy .

tcoffee-google avatar Mar 28 '17 21:03 tcoffee-google

Yes, resource_ worked well. In that case, the documentation/example should be modified stating resource_ is mandatory and it should remove "resource". The API Explorer should also remove resource and swap it with resource_.

Thanks, Santosh

sankulka avatar Mar 29 '17 06:03 sankulka

It looks to me like the comments in the example for Node.js do indicate that resource_ is the required field. At present, the API Explorer and the remaining documentation on the reference page are not language-specific, and show the correct name for every other language, so it probably does not make sense to change these.

While it would be breaking to change the name of this field to something less conflict-prone, it would be helpful to add a warning in the situation you encountered. Filed https://github.com/google/google-api-nodejs-client/issues/721.

tcoffee-google avatar Mar 29 '17 15:03 tcoffee-google