Queries

The API reference 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 section, alternately if you wanted to build a custom query then you would start in the Queries section.

Performing a query

For example, to get a list of accounts your query will look like this.

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.

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}}'

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.

Success! No errors.

{
    "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. You may also get data validation errors so please check your query and the variables being sent and try again.

{
    "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"
            }
        }
    ]
}

Last updated

Was this helpful?