George Mutti
George Mutti

Reputation: 11

I am getting Bad Request 400 when I try to access /users endpoint on Google OAuth 2.0 Playground

this is my first time I am using Google OAuth 2.0 Playground. I logged in using my personal @gmail.com account, under Admin SDK API directory_v1 I have selected this scope https://www.googleapis.com/auth/admin.directory.user.readonly, but I am not able to get the info that I need.

Possible operations for this scope includes listing users using this endpoint https://admin.googleapis.com/admin/directory/v1/users. But when I make request to the endpoint I am getting this error

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

I am also using this endpoint https://www.googleapis.com/oauth2/v2/userinfo to get user info, then get the user id(Which is the id field in the response), then use the id in this endpoint https://admin.googleapis.com/admin/directory/v1/users/{userKey}, but I am getting this response.

{
  "error": {
    "message": "Resource Not Found: userKey", 
    "code": 404, 
    "errors": [
      {
        "reason": "notFound", 
        "message": "Resource Not Found: userKey", 
        "domain": "global"
      }
    ]
  }
}

I have tried this using the default OAuth 2.0 credentials and also using my own OAuth credentials What am I doing wrong?

Upvotes: 0

Views: 755

Answers (1)

George Mutti
George Mutti

Reputation: 11

I figured out the issue. For this API https://admin.googleapis.com/admin/directory/v1/users, I needed to add a domain. So it should be https://admin.googleapis.com/admin/directory/v1/users?domain=sampled.com and also you need to ensure you have the ADMIN RIGHTS.

On the other endpoint https://admin.googleapis.com/admin/directory/v1/users/{userKey} it failed since I didn't have the ADMIN RIGHTS.

Upvotes: 0

Related Questions