# Queries

The [API reference](https://github.com/bunnyapp/docs-developer/blob/main/using-the-graphql-api/broken-reference/README.md) section of these docs gives you a comprehensive list of all of the objects, queries and mutations that can be performed.

There are a lot of pages in the API reference so its important as a first step that you think about what it is that you want to achieve. If you want to update an object then you will want to go to the [Mutations](/developer/api-reference/mutations.md) section, alternately if you wanted to build a custom query then you would start in the [Queries](/developer/api-reference/queries.md) section.

### Performing a query

For example, to [get a list of accounts](https://github.com/bunnyapp/docs-developer/blob/main/using-the-graphql-api/broken-reference/README.md) your query will look like this.

```graphql
query accounts ($first: Int, $filter: String) {
  accounts (first: $first, filter: $filter) {
    edges {
      cursor
      node {
        id
        name
      }
    }
    totalCount
    pageInfo {
      startCursor
      endCursor
      hasNextPage
      hasPreviousPage
    }
  }
}
```

### Request

You then need to combine the query with any parameters that it requires (in this case a **filter** and **limit**) then send the request along with a [valid access token](/developer/using-the-graphql-api/authorizing-api-requests.md#generate-an-access-token).

{% tabs %}
{% tab title="Curl" %}
{% code overflow="wrap" %}

```bash
curl -XPOST 'https://<subdomain>.bunny.com/graphql' \
--header 'Authorization: Bearer <access_token>' \
--header 'Content-Type: application/json' \
--data-raw '{"query":"query accounts ($filter: String, $limit: Int) {\n    accounts (filter: $filter, limit: $limit) {\n        id \n        name\n    }\n}","variables":{"filter":"","limit":10}}'
```

{% endcode %}
{% endtab %}

{% tab title="Ruby" %}

```ruby
query = <<~'GRAPHQL'
    query accounts ($filter: String, $limit: Int) {
        accounts (filter: $filter, limit: $limit) {
            id 
            name
        }
    }
GRAPHQL

variables = {
  filter: '',
  limit: 10
}

response = BunnyApp.query(query, variables)
```

{% endtab %}

{% tab title="Javascript" %}
{% code overflow="wrap" %}

```javascript
const query = `query accounts ($filter: String, $limit: Int) {
    accounts (filter: $filter, limit: $limit) {
        id 
        name
    }
}`;

const variables = {
  filter: "",
  limit: 10,
};

const response = await bunny.query(query, variables);
```

{% endcode %}
{% endtab %}
{% endtabs %}

### Response

Unless you've got an expired token then most of the time you will get a HTTP 200 response but dont immediately assume that the request worked as expected. You need to check the body of your request to see if any errors were returned.

{% tabs %}
{% tab title="200 Ok" %}
Success! No errors.

```json
{
    "data": {
        "accounts": [
            {
                "id": "25",
                "name": "Collins Group"
            },
            {
                "id": "29",
                "name": "D'Amore and Sons"
            },
            {
                "id": "27",
                "name": "Franecki Inc"
            },
            {
                "id": "30",
                "name": "Gleichner, Marvin and Buckridge"
            }
        ]
    }
}
```

**Failure!** In this case we've requested a field in our query that doesnt exist on the [Account object](/developer/api-reference/types/account.md). You may also get data validation errors so please check your query and the variables being sent and try again.

{% code overflow="wrap" %}

```json
{
    "errors": [
        {
            "message": "Field 'bogus' doesn't exist on type 'Account' - did you mean 'invalidField'?",
            "locations": [
                {
                    "line": 5,
                    "column": 9
                }
            ],
            "path": [
                "query accounts",
                "accounts",
                "bogus"
            ],
            "extensions": {
                "code": "undefinedField",
                "typeName": "Account",
                "fieldName": "bogus"
            }
        }
    ]
}
```

{% endcode %}
{% endtab %}

{% tab title="401 Unauthorized" %}
Token expired, you need to [generate a new access token](/developer/using-the-graphql-api/authorizing-api-requests.md#generate-an-access-token).

```
[
    {
        "description": [
            "Token is expired"
        ]
    }
]
```

{% 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.bunny.com/developer/using-the-graphql-api/sending-a-graphql-request.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.
