Query content using GraphQL

To verify that the setup was successful, let's create some test queries. Because the new content you just added has not yet been published, you can use the Preview API endpoint.

RequestResponse

https://content-api.sitecorecloud.io/api/content/v1/preview/graphql/

To query the content, you need to authenticate. In the Integrated Development Environment (IDE), on the HTTP HEADERS tab, add the API key using the following format (replacing the example API key):

RequestResponse

{
  "X-GQL-Token":"aEtSNzBsTaEtSNzBMA"
}

Get all events and event details

This sample query gets all events, along with their details. This includes the event name, description, location, date, image, and agenda.

RequestResponse

query {
 allEvent { 
  total
  results {
   id
   name
   eventName
   eventDescription
   eventLocation
   eventDate
   eventImage {
    results {
     fileName
    }
   }
   agenda {
    results {
     __typename
    }
   }
  }
 }
}

Note

Because the eventImage and agenda fields are returned as objects or lists of objects, you need to fetch the specific fields from these objects.

Get information on the event, agenda, and speakers

The content model for this tutorial includes information on the event, agenda, and speakers. The following query fetches this information.

RequestResponse

query {
  allEvent { 
    total
    results {
      id
      name
      eventName
      eventDescription
      eventLocation
      eventDate
      eventImage {
        results {
          fileId
          fileName
        }
      }
      agenda {  
        total
    results {
      __typename
     ... on Talk {
      id
      name
      talkTitle
      talkDescription
      image {
       results {
        fileId
        fileName
       }
      }
      duration
      time
      speaker {
       __typename
       results{
        ... on Speaker {
         id
         name
         speakerName
         speakerBio
         speakerImage {
          results {
           fileId
           fileName
          }
         }
        }
       }
      }
     }
        }
      }
  }
 }
}

Do you have some feedback for us?

If you have suggestions for improving this article,