# 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 %}
