Get started with the GraphQL API
How to get started with the GraphQL API, which is used in the Optimizely querying service to retrieve content in Optimizely's solutions.
Use Optimizely Graph to retrieve structured content from your Optimizely-powered sites through a single GraphQL API. Connect to the API, explore your content model, and run your first query to power fast, flexible content delivery.
Prepare your environment
Before you can use the GraphQL API, you must sync your content types and content with Optimizely Graph.
See Installation and configuration for instructions on enabling synchronization and obtaining your API access key. Synchronize content types and content from the site using the provided access key for the GraphQL API to work.
Access the API endpoint
Access the GraphQL API through the URL https://cg.optimizely.com/content/v2?auth={singlekey}. Replace {singlekey} with the access key you received when creating your account. This key authenticates your requests.
Access the interactive GraphiQL page
When accessing the GraphQL API through the provided endpoint, you can also try Optimizely Graph through the GraphiQL page https://cg.optimizely.com/app/graphiql?auth={singlekey}. This is a built-in tool for the GraphQL integrated development environment that can be used when working with queries.
If you use Optimizely Graph integrated with Optimizely Content Management System (CMS), you can access GraphiQL directly by choosing Optimizely Graph/GraphiQL from the menu.
NoteFor the page to work correctly in Firefox, you must toggle off Enhanced Tracking Protection.
Using GraphiQL
The GraphiQL interface includes the following key features:
- Query editor – Write and modify GraphQL queries.
- Response viewer – See results instantly in the JSON format.
- Schema explorer – Browse available types, fields, and relationships using the Docs tab or auto-complete.
Explore the schema
Understanding GraphQL schema is necessary to form valid queries. The schema reflects your CMS content model and includes:
- Types (for example, Article, Product, BlogPost)
- Fields available on each type
- Relationships between types, like references or embedded content
- Arguments and filters for querying specific content
See GraphQL schema documentation for guidance on exploring and using the schema. You can also use introspection queries or the Docs tab in GraphiQL to examine the schema interactively.
Example query
The following query retrieves articles with their title and publish date:
{
Article {
total
items {
title
publishDate
}
}
}
This query returns a list of articles along with the total count and selected fields for each item.
Updated 16 days ago

