A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
Hi,
For a custom project, I try to create and push a section to a specific theme.
It used to work with REST API but I wonder how to make it with GraphQL.
Here's a code that worked with REST :
const pushFileUrl = `https://${shop.myshopify}/admin/api/2023-07/themes/${themeId}/assets.json`;
const sectionToAdd = {
asset: {
key: "sections/new-section.liquid",
value: "<div>New section content</div>",
},
};
const shopifyRes = await fetch(pushFileUrl, {
method: "PUT",
headers: {
"Content-Type": "application/json",
"X-Shopify-Access-Token": shop.token,
},
body: JSON.stringify(sectionToAdd),
});
Thanks for your help.
Have a good day 🙂
Léo