Content variation
Query content variations in Optimizely Graph to retrieve original content, specific variations, or personalized versions based on user context.
Optimizely Graph supports querying for Optimizely Content Management System (CMS) (SaaS) content variations, so Graph clients can deliver the right A/B test arm, personalized version, locale, or campaign experience for each request. Use the queries in this article to fetch all variations, a specific variation, or only the original content based on user context.
Prerequisites
Before querying variations, confirm that the variations exist in CMS (SaaS) and that the API key used for the query has read access to the affected content types. See Create content variation for the editorial workflow that produces variation keys.
How content variations work
Content variations let editors deliver multiple versions of the same content item from a single source, which keeps personalization, A/B tests, and localization aligned with the canonical record. In CMS (SaaS), editors can create one or more variations of a page or content item, and each variation is identified by a unique string stored in the variation field on the content item.
Default behavior
The default query behavior controls how much variation content Graph returns when the client does not opt in, which protects callers from accidentally serving experimental content. By default, GraphQL queries do not include variations. To get variation content (and preview variation), specify it in the query using variation: { include: ALL}, or specify the variation key.
Query variations
The following queries cover the three common patterns: fetching every variation, fetching specific variations, and fetching only the original content. Pick the pattern that matches the experience you are building.
Get all variations of a content item
Use this query when the calling layer needs every variation, including the original, so it can apply its own selection logic. To return all content variations (including the original), add a filter or field selector to include the variation property.
query GetAllVariations {
_Content(variation: { include: ALL, includeOriginal: true }) {
items {
_metadata {
key
displayName
}
}
}
}
Query specific variations
Use this query when the calling layer already knows which variation keys to target, for example, a campaign segment or a personalization rule. To get a specific variation, filter by the variation field.
query GetSomeVariations($variations: [String], $includeDefaultContent: Boolean = true) {
_Content(variation: { include: SOME, value: $variations, includeOriginal: $includeDefaultContent }) {
items {
_metadata {
key
displayName
}
}
}
}
Pass the following variables when executing the query:
{
"variations": ["WinterCampaign", "SummerCampaign"],
"includeDefaultContent": true
}Query only default content (no variations)
Use this query to fetch only the original content that has no variation value.
query GetOnlyDefaultContent {
_Content(variation: { include: NONE, includeOriginal: true }) {
items {
_metadata {
key
displayName
}
}
}
}
Updated 8 days ago
