google-apigoogle-appsgoogle-workspacegsuite-addons

G Suite Users: list api call fails with response 400:Bad Request


Following is the request

GET /admin/directory/v1/users? HTTP/1.1
Host: www.googleapis.com
Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Content-Type: application/json

Following is the response

{
    "error": {
        "errors": [
            {
                "domain": "global",
                "reason": "badRequest",
                "message": "Bad Request"
            }
        ],
        "code": 400,
        "message": "Bad Request"
    }
}

This request is correct according to their documentation. If you try the "Try it!" feature on the left top corner in the documentation page you will still get this issue. What's wrong with my request please help.


Solution

  • After some effort, I found the answer. The issue was with the customer parameter, even though it's specified as optional in the documentation you have to provide it. Following is the successful request to retrieve users under my account.

    GET /admin/directory/v1/users?customer=my_customer HTTP/1.1
    Host: www.googleapis.com
    Authorization: Bearer ya29.a0Adw1xeWNBqbsl1krQ0vdnIlKzWLROC0xe-jW7TvHvljX3M3DAw_fXR5xgy2Msfif2WtdBILEjRDwSIUfC9v-2F1ssV9TQJ-lu-O1yywHUuDn5Eb8oiyyaNkBRUyIVDAuZkH2Q4EbYUCYFJzcVzyFYBIqmeCc0KzNv3Kb-qE2awHulI_Mm1LhyDJqtIPnFnMxngx7QoD0qJsDHgysphGYdg
    Content-Type: application/json