Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Create a section on a theme with GraphQL API

Create a section on a theme with GraphQL API

leoruppert
Shopify Partner
3 0 1

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

Replies 0 (0)