googleapis / google-api-php-client

A PHP client library for accessing Google APIs
Apache License 2.0
9.2k stars 3.52k forks source link

Basic Question: Method Roles Get #2529

Closed derekritchison closed 6 months ago

derekritchison commented 7 months ago

Hey there- Not a bug, just a question. I feel like I am using the roles.get method (example below) properly according to Google's docs (also below). However, I am getting a 400. I've tried passing the role's ID as roleId and as resource_id but always get the same response. Has anyone used this method with the PHP client before? Am I missing something obvious?


My code:

try { // Retrieve role assignments for the user
    $roleAssignments = $service->roleAssignments->listRoleAssignments($customerID, ['userKey' => $user['primaryEmail']]);

    foreach ($roleAssignments as $roleAssignment) {
        try {
            $roleName = $service->roles->get($customerID, ['roleId' => $roleAssignment['roleId']]);
            ...and so on.

Response:

HTTP Status Code: 400 Errors: [ { "message": "Invalid data: RolesGetRequest.resource_id", "domain": "global", "reason": "invalid" } ]


Google's docs:

https://developers.google.com/admin-sdk/directory/reference/rest/v1/roles/get

derekritchison commented 7 months ago

I figured this out. The API does not want the roleId sent in an array, but rather just a string. Somewhat confusing given the first call requires the array but whatever.

$roleName = $service->roles->get($customerID, $roleAssignment['roleId']);

saranshdhingra commented 6 months ago

Glad you figured it out.

We don't have samples for all API calls, so sometimes the only way to be sure is to see the signature of the method call.

Often IDEs/editors help with that.

Thanks.