# Get User accounts based on authority

Each <mark style="color:yellow;">user account</mark> is associated with an authority, which is the owner of the account. To query the user details associated with an authority, we query the User account’s authority field using the *<mark style="color:yellow;">\_eq</mark>* filter. Please note, the User account fields can be handpicked as per your applications requirements.

You can directly copy paste this code on <mark style="color:yellow;">replit</mark> and see it in action.

#### Fetch User Details for an Authority

{% tabs %}
{% tab title="Code Snippet" %}
{% code overflow="wrap" %}

```javascript
const SHYFT_API_KEY = "YOUR-API-KEY";

async function getDataByGraphQl(authorityAddress) {
  //get user by authority
  const operationsDoc = `
      query MyQuery {
        drift_User(
          limit: 10
          where: {authority: {_eq: ${JSON.stringify(authorityAddress)}}}
        ) {
          delegate
          subAccountId
          pubkey
          authority
        }
      }
    `; //graphQl query
  const result = await fetch(
    `https://programs.shyft.to/v0/graphql/accounts?api_key=${SHYFT_API_KEY}&network=mainnet-beta`, //SHYFT's GQL endpoint
    {
      method: "POST",
      body: JSON.stringify({
        query: operationsDoc,
        variables: {},
        operationName: "MyQuery",
      }),
    },
  );

  return await result.json();
}

async function getUserDetailsByAuthority(authorityPubkey) {
  const { errors, data } = await getDataByGraphQl(authorityPubkey);

  if (errors) {
    console.error(errors);
    console.log("Some Error Occured, please check your API key or try again");
  }

  console.dir(data, { depth: null });
}
getUserDetailsByAuthority("Ctae6pxZZYKQ2tZRavw1tEVhVN5YNRJRhTBFGDbipmtw")
//authority address of the user to be fetched
```

{% endcode %}
{% endtab %}

{% tab title="Response" %}

```json
{
  drift_User: [
    {
      delegate: "11111111111111111111111111111111",
      subAccountId: 0,
      pubkey: "Bh5YUnMnVyrHVNo9TpBpZJLn6eMAPmhMATLod4AUoSMG",
      authority: "Ctae6pxZZYKQ2tZRavw1tEVhVN5YNRJRhTBFGDbipmtw"
    }
  ]
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.shyft.to/solana-indexers/case-studies/drift/get-user-accounts-based-on-authority.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
