---
title: "GraphQL API reference"
slug: "graphql-api-reference"
abstract: "Structure of a GraphQL query along with sample queries to fetch a variety of data."
---
# GraphQL API reference

We have provided the following GraphQL query examples to give you an idea of how to use available operators in the [GraphQL IDE](https://doc.sitecore.com/ch-one/en/developers/content-hub-one/preview-and-delivery-apis/graphql-ide.html "GraphQL IDE"). The [graphQL schema](https://doc.sitecore.com/ch-one/en/developers/content-hub-one/preview-and-delivery-apis/graphql-schema.html "GraphQL schema") provides an overview of how data is organized and structured in Content Hub ONE.

> [!important]
> You must [authenticate with an API key](https://doc.sitecore.com/ch-one/en/developers/content-hub-one/preview-and-delivery-apis.html "Preview and Delivery APIs") for all requests to the GraphQL APIs.

> [!tip]
> When working in the [GraphQL IDE](https://doc.sitecore.com/ch-one/en/developers/content-hub-one/preview-and-delivery-apis/graphql-ide.html "GraphQL IDE"), you can use the **DOCS** tab to access additional guidance on writing queries.

## Structure of a GraphQL query

[GraphQL queries](https://graphql.org/learn/queries/#queries-and-mutations) use a specific structure to represent the requested data. Each request is a standard POST request with a query in the body.

The main elements of a GraphQL query are:

- Query fields - fields in the target data that you want the query to evaluate when selecting results.
- Arguments - suffix that determines how the query evaluates the corresponding value. For example, **eq** means equals.
- Selection set - the fields returned in the query result.

In this example, the query examines all items of type *hotels* and fetches the content item that has an ID of *cTgzGGR8wEu1MCgfSqMThw* and a locale of *fr-CA*, including details about related items.

```graphql
query {
  hotels(id: "cTgzGGR8wEu1MCgfSqMThw" locale: "fr-CA") {
    id
    name
    industry
    heroImage {
     results {
          name
          description
          __sysCreatedAt
        }
    }
    description
    relatedItems {
      results {
        ... on Tour {
          id
          locale
          name
          shortDescription
        }
      }
    }
    locale
    __sysCreatedAt
    __sysCreatedBy
    __sysUpdatedAt
    __sysUpdatedBy
    __sysVersion
  }
}
```

> [!note]
> The Preview API does not support the `where` clause.

## Basic actions

These query examples illustrate basic actions for Content Hub ONE that show how to use precise criteria to fetch a variety of data, such as a specific hotel, a collection of hotels and destinations, or a series of images related to a destination.

> [!tip]
> You can use the GraphQL copy feature available in the app to obtain a graphQL query that you can use in the IDE. In Content Hub ONE, on the content item details page, click **More actions** ![more-actions-chone.png](https://doc.sitecore.com/api/markdown-image/ch-one/en/developers/content-hub-one/images/more-actions-chone.png) > ![graphql-chone.png](https://doc.sitecore.com/api/markdown-image/ch-one/en/developers/content-hub-one/images/graphql-chone.png)**GraphQL query**. In the GraphQL query side panel, click ![content-copy-chone.png](https://doc.sitecore.com/api/markdown-image/ch-one/en/developers/content-hub-one/images/content-copy-chone.png) **Copy** to copy the query to your clipboard.

### Get items of a specific type

This sample query returns all content items of the *Hotels* content type with a locale of *fr-CA*.

> [!note]
> If you do not include a locale, all items of the type *Hotel* with a locale of *null* are returned.

```graphql
query{
 allHotels(locale:"fr-CA") {
  results {
   name
   id
   locale
  }
 }
}
```

```json
{
  "data": {
    "allHotels": {
      "results": [
        {
          "name": "Luxury Hotel",
          "id": "cTgzGGR8wEu1MCgfSqMThw",
          "locale": "fr-CA"
        }
      ]
    }
  }
}
```

### Get item by ID and locale

This sample query returns the name of the hotel with an `ID` of *ecoInn* and a locale *en-US*. In a similar manner, you can fetch a media item using only the `ID`.

```graphql
{
  hotels(id: "ecoInn", locale: "en-US") {
      name
    }
}
```

```json
{
  "data": {
    "hotels": {
      "name": "Eco-Inn"
    }
  }
}{
  hotels(id: "ecoInn") {
      name
    }
}
```

### Get associated media

This sample query returns the ID and name of a hotel with an `ID` of `luxuryInn`, along with the file name and file type of the images associated with it.

```graphql
{
  hotels(id: "luxuryInn") {
      id
      name
      heroImage {
        results {
          name
          fileType
        }
      }
    }
  }
```

```json
{
  "data": {
    "hotels": {
      "id": "luxuryInn",
      "name": "Luxury-Inn",
      "heroImage": {
        "results": [
          {
            "name": "Luxury-Inn",
            "fileType": "image/jpeg"
          }
        ]
      }
    }
  }
}
```

### Get related items

This sample query uses a GraphQL fragment to return the `ID` and `name` of related items that have the *Destination* content type.

```graphql
{
  allHotels {
    results {
      name
      relatedItems {
        results {
          ... on Destination {
            id
            name
          }
        }
      }
    }
  }
}
```

```json
{
  "data": {
    "allHotels": {
      "results": [
        {
          "name": "Hostel-Inn",
          "relatedItems": {
            "results": [
              {
                "id": "thailand",
                "name": "Thailand"
              },
              {}
            ]
          }
        },
        {
          "name": "Comfort-Inn",
          "relatedItems": {
            "results": [
              {
                "id": "vietnam",
                "name": "Vietnam"
              },
              {},
              {}
            ]
          }
        },
        {
          "name": "Eco-Inn",
          "relatedItems": {
            "results": [
              {
                "id": "thailand",
                "name": "Thailand"
              }
            ]
          }
        },
        {
          "name": "Luxury-Inn",
          "relatedItems": {
            "results": [
              {
                "id": "japan",
                "name": "Japan"
              }
            ]
          }
        }
      ]
    }
  }
}
```

### Get all taxonomy values for a specific taxonomy

This sample query returns the `ID` of the taxonomy values that make up the taxonomy called *amenities*.

```graphql
{

  allTaxonomy_amenities {
    results {
      id
    }
  }
}
```

```json
{
  "data": {
    "allTaxonomy_amenities": {
      "results": [
        {
          "id": "taxonomy_amenities_airConditioning"
        },
        {
          "id": "taxonomy_amenities_parking"
        },
        {
          "id": "taxonomy_amenities_restaurant"
        },
        {
          "id": "taxonomy_amenities_wheelchairAccessible"
        },
        {
          "id": "taxonomy_amenities_wifi"
        }
      ]
    }
  }
}
```

### Get content based on specific taxonomy values

This sample query returns the name of hotels where the **amenities** taxonomy includes **Wifi** or **Air conditioning**. The query also returns the file name and file type of the images associated with the hotel, along with a list of the taxonomy value **ID** for all available amenities.

```graphql
{
  allHotels
  (where:{
    OR:[
   { amenities:{taxonomy_amenities_ids: "taxonomy_amenities_wifi"}}
    {amenities:{taxonomy_amenities_ids: "taxonomy_amenities_airConditioning"}}
    ]})
  {
    results {
      name
      heroImage {
        results {
          id
          name
          fileType
        }
      }
      amenities{
        results{
          id
        }
      }
    }
  }
}
```

```json
{
  "data": {
    "allHotels": {
      "results": [
        {
          "name": "Luxury-Inn",
          "heroImage": {
            "results": [
              {
                "id": "travelLuxuryInn",
                "name": "Luxury-Inn",
                "fileType": "image/jpeg"
              }
            ]
          },
          "amenities": {
            "results": [
              {
                "id": "taxonomy_amenities_airConditioning"
              },
              {
                "id": "taxonomy_amenities_restaurant"
              },
              {
                "id": "taxonomy_amenities_wifi"
              }
            ]
          }
        }
      ]
    }
  }
}
```

## Operators

These query examples illustrate how to use query operators to filter the data fetched.

### AND operators

This sample query returns the id, name, industry, and creation date of items that have the *Hotels* content type, are part of the travel industry, and have a name containing the word *eco*.

```graphql
{
  allHotels (
    where: {
       AND: [
             {industry_contains: "travel"}
             {name_contains:"eco"}
            ]
           }
        )
{
    results{
      id
      name
      industry
      __sysCreatedAt
    }
  }
}
```

```json
{
  "data": {
    "allHotels": {
      "results": [
        {
          "id": "ecoInn",
          "name": "Eco-Inn",
          "industry": "travel",
          "__sysCreatedAt": "2023-06-08T13:`15:03`.000Z"
        }
      ]
    }
  }
}
```

### OR operators

This sample query returns the name, rating, and price per night of items that have the *Hotels* content type, and either cost less than *60* USD or have a rating of *3* stars.

```graphql
{
  allHotels (
    where: {
       OR: [
             {pricePerNight_lt: 60}
             {ratingstars_eq:"3"}
            ]
           }
        )
{
    results{
      name
      ratingstars
      pricePerNight
      __sysCreatedAt
    }
  }
}
```

```json
{
  "data": {
    "allHotels": {
      "results": [
        {
          "name": "Hostel-Inn",
          "ratingstars": 3,
          "pricePerNight": 10,
          "__sysCreatedAt": "2023-06-12T17:`53:47`.000Z"
        },
        {
          "name": "Eco-Inn",
          "ratingstars": 4,
          "pricePerNight": 20,
          "__sysCreatedAt": "2023-06-08T13:`15:03`.000Z"
        }
      ]
    }
  }
}
```

### Nested operators

This sample query uses nested operators to return items with the *Hotels* content type that satisfy the following conditions:

- The price per night for the hotel is less than *100* USD.
- The hotel rating is 4 or the industry is *travel*.

```graphql
{
  allHotels (
    where: {
       AND: [
            {pricePerNight_lt: 100}
            {
               OR: [
                 {ratingstars_eq:"4"}
                 {industry_eq:"travel"}
               ]
            }
        ]
    }
)
{
    results{
      name
      pricePerNight
      ratingstars
      __sysCreatedAt
    }
  }
}
```

```json
{
  "data": {
    "allHotels": {
      "results": [
        {
          "name": "Comfort-Inn",
          "pricePerNight": 60,
          "ratingstars": 2,
          "__sysCreatedAt": "2023-06-08T13:`15:03`.000Z"
        },
        {
          "name": "Eco-Inn",
          "pricePerNight": 20,
          "ratingstars": 4,
          "__sysCreatedAt": "2023-06-08T13:`15:03`.000Z"
        }
      ]
    }
  }
}
```

## Arguments

The following examples use the arguments available on the **where** clause in the Content Hub ONE GraphQL implementation.

### anyOf

This sample query returns the **ID** and title of any item with the *Destination* content type and an **ID** that matches either *japan* or *thailand*.

```graphql
{
  allDestination(
    where: {id_anyOf: ["japan", "thailand"]})
    {
      total
      results {
        id
        name
      }
    }
  }
```

```json
{
  "data": {
    "allDestination": {
      "total": 2,
      "results": [
        {
          "id": "japan",
          "name": "Japan"
        },
        {
          "id": "thailand",
          "name": "Thailand"
        }
      ]
    }
  }
}
```

### noneOf

This sample query returns the **ID** and name of hotels with the *Hotels* content type that do not have an **ID** that matches *ecoInn* or *luxuryInn*.

```graphql
{
  allHotels(
    where: {id_noneOf: ["ecoInn", "luxuryInn"]})
    {
      total
      results {
        id
        name
      }
    }
  }
```

```json
{
  "data": {
    "allHotels": {
      "total": 1,
      "results": [
        {
          "id": "comfortInn",
          "name": "Comfort-Inn"
        }
      ]
    }
  }
}
```

### Contains

This sample query returns the name and **ID** of items with the *Tour* content type that have a name containing the ampersand (&) symbol.

```graphql
{
  allTour(where: {name_contains: "&"
  })  {
    results {
      name
      id
    }
  }
}
```

```json
{
  "data": {
    "allTour": {
      "results": [
        {
          "name": "Thailand & Indonesia ",
          "id": "thailandIndonesia"
        },
        {
          "name": "Vietnam & Malaysia",
          "id": "vietnamMalaysia"
        }
      ]
    }
  }
}
```

### Equals

This sample query returns the name and short description of items with the *Hotels* content type and a rating of 4 stars.

```graphql
{
  allHotels(
    where: {
      ratingstars_eq: 4
    }  )  {
    total
    results {
     name
     shortDescription
    }
  }
}
```

```json
{
  "data": {
    "allHotels": {
      "total": 2,
      "results": [
        {
          "name": "Eco-Inn",
          "shortDescription": "Eco-Inn is a family hotel located in the city center within easy walking access of the main tourist attractions of Athens, the business and commercial zone of the city, or the shopping and entertainment centre of Plaka. "
        },
        {
          "name": "Luxury-Inn",
          "shortDescription": "The first choice for the rich and famous, the Luxury-Inn is renowned for its large and lavish breakfasts."
        }
      ]
    }
  }
}
```

### Not Equal

This sample query returns the name, short description, and rating of items with the *Hotels* content type and a rating that is not 2.

```graphql
{
  allHotels(
    where: {
      ratingstars_neq: 2
    }  )  {
    total
    results {
     name
     shortDescription
      ratingstars
    }
  }
}
```

```json
{
  "data": {
    "allHotels": {
      "total": 2,
      "results": [
        {
          "name": "Eco-Inn",
          "shortDescription": "Eco-Inn is a family hotel located into the city centre within easy walking access to the main tourist attractions of Athens, the business and commercial zone of the city or the shopping and entertainment centre of Plaka. ",
          "ratingstars": 4
        },
        {
          "name": "Luxury-Inn",
          "shortDescription": "The first choice for the rich and famous, the Luxury-Inn is renowned for its large and lavish breakfasts.",
          "ratingstars": 4
        }
      ]
    }
  }
}
```

### Less than

This sample query returns items with the *Hotels* content type that cost less than *55* USD per night.

```graphql
{
  allHotels(where: {pricePerNight_lt: 55
  })  {
    results {
     name
     pricePerNight
    }
  }
}
```

```json
{
  "data": {
    "allHotels": {
      "results": [
        {
          "name": "Eco-Inn",
          "pricePerNight": 20
        }
      ]
    }
  }
}
```

### Greater than

This sample query returns items with the *Hotels* content type that cost more than *75* USD per night.

```graphql
{
  allHotels(where: {pricePerNight_gt: 75
  })  {
    results {
     name
     pricePerNight
    }
  }
}
```

```json
{
  "data": {
    "allHotels": {
      "results": [
        {
          "name": "Luxury-Inn",
          "pricePerNight": 100
        }
      ]
    }
  }
}
```

### Between

This sample query returns items with the *Hotels* content type that were created between June 1, 2023 and July 1, 2023.

```graphql
{
  allHotels(where: {__sysCreatedAt_between:  [
    "2023-06-01T19:`26:15`.000Z"
    "2023-07-01T19:`26:15`.000Z"]
  })  {
    results {
     name
     __sysCreatedAt
    }
  }
}
```

```json
{
  "data": {
    "allHotels": {
      "results": [
        {
          "name": "Hostel-Inn",
          "__sysCreatedAt": "2023-06-12T17:`53:47`.000Z"
        },
        {
          "name": "Comfort-Inn",
          "__sysCreatedAt": "2023-06-08T13:`15:03`.000Z"
        },
        {
          "name": "Eco-Inn",
          "__sysCreatedAt": "2023-06-08T13:`15:03`.000Z"
        },
        {
          "name": "Luxury-Inn",
          "__sysCreatedAt": "2023-06-08T13:`15:03`.000Z"
        }
      ]
    }
  }
}
```

### OrderBy

This sample query returns items with the *Destination* content type in descending order based on the [system-defined field](https://doc.sitecore.com/ch-one/en/developers/content-hub-one/preview-and-delivery-apis/data-model.md "Data model") **SYSCREATEDAT**, which is the date the item was created.

```graphql
{
  allDestination(
    orderBy: [
      __SYSCREATEDAT_DESC
    ]
  )  {
    results {
     name
     __sysCreatedAt
    }
  }
}
```

```json
{
  "data": {
    "allDestination": {
      "results": [
        {
          "name": "Vietnam",
          "__sysCreatedAt": "2023-06-08T13:`15:07`.000Z"
        },
        {
          "name": "Thailand",
          "__sysCreatedAt": "2023-06-08T13:`15:06`.000Z"
        },
        {
          "name": "Malaysia",
          "__sysCreatedAt": "2023-06-08T13:`15:06`.000Z"
        },
        {
          "name": "Japan",
          "__sysCreatedAt": "2023-06-08T13:`15:06`.000Z"
        },
        {
          "name": "Indonesia",
          "__sysCreatedAt": "2023-06-08T13:`15:05`.000Z"
        }
      ]
    }
  }
}
```

### First

This sample query returns the first three items with the *Destination* content type.

```graphql
{
  allDestination(
    first: 3,
  )  {
    results {
     name
    }
  }
}
```

```json
{
  "data": {
    "allDestination": {
      "results": [
        {
          "name": "Indonesia"
        },
        {
          "name": "Japan"
        },
        {
          "name": "Malaysia"
        }
      ]
    }
  }
}
```

### Total

This sample query returns the total number of items of type *TourEvents* that have a title containing the symbol "&".

```graphql
{
  allTourEvents(
    where: {
      name_contains: "&"
    }  )  {
    total
    results {
     name
    }
  }
}
```

```json
{
  "data": {
    "allTour": {
      "total": 2,
      "results": [
        {
          "name": "Thailand & Indonesia "
        },
        {
          "name": "Vietnam & Malaysia"
        }
      ]
    }
  }
}
```

### Typename

This sample query returns items of type *Hotels* where the title contains either "hostel" or "comfort". For each item, it also returns a list of items that are associated using references.

```graphql
{
  allHotels (
    where: {
       OR: [
             {name_contains: "hostel"}
             {name_contains:"comfort"}
            ]
           }
        )
{
    results {
      name
      relatedItems
      {
      results{
      ... on Destination {
        name
      }
      ... on Tour {
        name
      }
      contentType: __typename
    }
   }
  }
 }
}
```

```json
{
  "data": {
    "allHotels": {
      "results": [
        {
          "name": "Hostel-Inn",
          "relatedItems": {
            "results": [
              {
                "name": "Thailand",
                "contentType": "Destination"
              },
              {
                "name": "Vietnam & Malaysia",
                "contentType": "Tour"
              }
            ]
          }
        },
        {
          "name": "Comfort-Inn",
          "relatedItems": {
            "results": [
              {
                "name": "Vietnam",
                "contentType": "Destination"
              },
              {
                "name": "Vietnam & Malaysia",
                "contentType": "Tour"
              },
              {
                "name": "Thailand & Indonesia ",
                "contentType": "Tour"
              }
            ]
          }
        }
      ]
    }
  }
}
```

## Pagination

These query examples illustrate how to paginate the response body and how to fetch the next page of results.

### PageInfo

This sample query returns the first three items of the type *Destination*. It uses the **pageInfo** object to fetch information needed for pagination, including the **endCursor** field, which indicates the final item in the response; and the **hasNext** field, which indicates whether more results are available.

```graphql
{
  allDestination(first:3)
    {
    results {
      id
      name
    }
    pageInfo {
      endCursor
      hasNext
    }
   }
  }
```

```json
{
  "data": {
    "allDestination": {
      "results": [
        {
          "id": "indonesia",
          "name": "Indonesia"
        },
        {
          "id": "japan",
          "name": "Japan"
        },
        {
          "id": "malaysia",
          "name": "Malaysia"
        }
      ],
      "pageInfo": {
        "endCursor": "eyJzZWFyY2hBZnRlciI6WyJtYWxheXNpYSIsIm1hbGF5c2lhIl0sImNvdW50IjozfQ==",
        "hasNext": true
      }
    }
  }
}
```

### After

This sample query returns the next three items of the type *Destination* after the `endCursor` point of the previous example. It uses the `pageInfo` type to fetch information needed for pagination, including the `endCursor` field and `hasNext` fields described in the previous example.

```graphql
{
  allDestination(first:3, after:"eyJzZWFyY2hBZnRlciI6WyJtYWxheXNpYSIsIm1hbGF5c2lhIl0sImNvdW50IjozfQ==")
    {
      total
    results {
      id
      name
    }
    pageInfo {
      endCursor
      hasNext
    }
   }
  }
```

```json
{
  "data": {
    "allDestination": {
      "total": 5,
      "results": [
        {
          "id": "thailand",
          "name": "Thailand"
        },
        {
          "id": "vietnam",
          "name": "Vietnam"
        }
      ],
      "pageInfo": {
        "endCursor": "eyJzZWFyY2hBZnRlciI6WyJ2aWV0bmFtIiwidmlldG5hbSJdLCJjb3VudCI6NX0=",
        "hasNext": false
      }
    }
  }
}
```

## Sorting

These query examples illustrate how to fetch items and order the results.

### Get items and sort in ascending order

This sample query returns the name of items of the type *Destination*. These results are sorted by title in ascending order.

```graphql
{
  allDestination(
    orderBy: NAME_ASC
  ) {
    results {
      name
    }
  }
}
```

```json
{
  "data": {
    "allDestination": {
      "results": [
        {
          "name": "Indonesia"
        },
        {
          "name": "Japan"
        },
        {
          "name": "Malaysia"
        },
        {
          "name": "Thailand"
        },
        {
          "name": "Vietnam"
        }
      ]
    }
  }
}
```

### Get items of various content types and sort in descending order

This sample query returns the name of all items of the type *Destination*, and the IDs of all the items with the type *Tour*, along with the total count of each. It sorts both sets of results in descending order.

```graphql
{
  allDestination(
    orderBy: NAME_DESC
  ) {
    total
    results {
      name
    }
  }

  allTour(
    orderBy: ID_DESC
  ) {
    total
    results {
      id
    }
  }
}
```

```json
{
  "data": {
    "allDestination": {
      "total": 5,
      "results": [
        {
          "name": "Vietnam"
        },
        {
          "name": "Thailand"
        },
        {
          "name": "Malaysia"
        },
        {
          "name": "Japan"
        },
        {
          "name": "Indonesia"
        }
      ]
    },
    "allTour": {
      "total": 3,
      "results": [
        {
          "id": "vietnamMalaysia"
        },
        {
          "id": "thailandIndonesia"
        },
        {
          "id": "japan2weeks"
        }
      ]
    }
  }
}
```