Sitecore XM Cloud Marketplace: Reading and Changing Items with GraphQL
How to use Sitecore ClientSDK to read and mutate items in a Sitecore Marketplace Application
Start typing to search...
How to use Sitecore ClientSDK to read and mutate items in a Sitecore Marketplace Application
Working with Sitecore XM Cloud through the Marketplace platform opens up powerful possibilities for content management extensions. In this post, we'll explore how the Sitecore ClientSDK performs GraphQL queries and mutations within a marketplace extension.
Note: This blog post focuses specifically on how to read and manipulate Sitecore items using the ClientSDK and Authoring API. We won't be covering how to set up a marketplace application from scratch — instead, we'll concentrate on the core concepts of working with Sitecore content through GraphQL operations once your marketplace extension is already established.
You can find a complete working example of the concepts discussed in this blog post in our sample repository:
Sitecore XM Cloud Marketplace Sample – Item Query & Mutation
This sample repository demonstrates the XM Cloud Full Screen integration point, showing how to build a complete marketplace extension that can read and modify Sitecore content items.

Before diving into code examples, it's crucial to understand the architecture behind Sitecore XM Cloud Marketplace Extensions.
Sitecore XM Cloud Marketplace Extensions operate as micro-frontends that run inside the Sitecore authoring environment as iframes.
This architecture provides several key benefits:
The ClientSDK acts as a communication bridge between your extension (iframe) and the parent Sitecore XM Cloud interface.
Here's how the flow works:
Your Extension (iframe) → ClientSDK → Parent Sitecore App → Sitecore APIs
When you want to perform GraphQL operations:
postMessageThis API communication can be visualized in the in the Browser’s Development Tool Console. At the time of writing this post, I could not find a way to disable that console logging.

This architecture provides several security advantages:
Let's look at how to perform GraphQL queries to read content items from Sitecore XM Cloud.
It's important to note that we're working with the Authoring API here, not the Delivery API.
This means you cannot use the Sitecore GraphQL Playground to validate these queries, as the playground uses the Delivery API which has a different schema and capabilities.
import { useMarketplaceClient } from "@/src/utils/hooks/useMarketplaceClient";
export function QueryExample() {
const { client, isInitialized, error } = useMarketplaceClient();
const fetchItemData = async (itemPath: string) => {
if (!client || !isInitialized) return;
// First, get the application context
const contextResponse = await client.query("application.context");
const appContext = contextResponse.data as ApplicationContext;
// Extract the Sitecore Context ID
const sitecoreContextId = appContext.resourceAccess?.[0]?.context?.preview;
// Define your GraphQL query
const graphqlQuery = {
query: `
query {
item(
where: {
database: "master",
path: "${itemPath}"
}
) {
itemId
name
path
fields(ownFields: true, excludeStandardFields: true) {
nodes {
name
value
}
}
}
}
`
};
// Execute the query through the ClientSDK
const response = await client.mutate("xmc.authoring.graphql", {
params: {
query: {
sitecoreContextId,
},
body: graphqlQuery,
},
});
return response.data?.data?.item;
};
}
sitecoreContextIdNow let's explore how to modify content items using GraphQL mutations.
const updateItemField = async (
itemId: string,
itemPath: string,
fieldName: string,
newValue: string
) => {
if (!client || !appContext) return false;
try {
const sitecoreContextId = appContext.resourceAccess?.[0]?.context?.preview;
const mutationQuery = {
query: `
mutation {
updateItem(
input: {
fields: [
{
name: "${fieldName}",
value: "${newValue.replace(/"/g, '\\"')}",
reset: false
}
]
database: "master"
itemId: "${itemId}"
language: "en"
path: "${itemPath}"
version: 1
}
) {
item {
name
itemId
fields(ownFields: true) {
nodes {
name
value
}
}
}
}
}
`
};
const response = await client.mutate("xmc.authoring.graphql", {
params: {
query: {
sitecoreContextId,
},
body: mutationQuery,
},
});
return response.data?.data?.updateItem?.item;
} catch (error) {
console.error("Mutation failed:", error);
return false;
}
};
input object with specific parametersname, value, and reset propertiesitemId, path, or bothWhen working with Sitecore XM Cloud Marketplace extensions: