Get a user by ID

Look up a user by ID and read their name, email, and username when you share an organization.

Before You Begin

🔗 Use the GraphQL Playground to execute the query in this guide.

➡️ New to GraphQL? Learn how to navigate the Playground with our Playground Basics Guide.

Prerequisites

  1. Authentication: Use a Service Account token (Personal Access Tokens are deprecated).
  2. Shared organization: You can read a user only when your token's user and that user both belong to the same organization.
  3. User ID: The numeric ID of the user you want to load.

Step 1: Query the user

Use the user query with the user ID. The example below returns the fields most callers need:

query user($id: ID!) {
  user(id: $id) {
    id
    name
    email
    username
  }
}
{
  "id": "123456"
}

Key fields explained

  • id: Unique identifier of the user.
  • name: The user's name.
  • email: The user's email.
  • username: The user's username.

Step 2: Execute and interpret the response

A successful lookup returns the user under data.user:

{
  "data": {
    "user": {
      "id": "123456",
      "name": "Ada Lovelace",
      "email": "[email protected]",
      "username": "ada"
    }
  }
}

Key Notes

  • A caller who does not share an organization with the target receives user: null and no error.
  • An unknown user ID also returns user: null and no error.