Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Hello,
I am in the process of creating products through the API, and I have encountered a challenge in activating all the sales channels for each product. When I use the admin panel, the process is straightforward: I simply open a product, select ‘Sales Channels,’ and check all the checkboxes.
However, I am uncertain about how to replicate this process using the API. I have done some research and found a discussion on this topic at Shopify Community. Unfortunately, it appears that the channels API endpoint mentioned in the discussion is now deprecated.
I was wondering if anyone in the community has experience or knowledge on how to accomplish this task using the current API endpoints? Your assistance and guidance would be greatly appreciated.
Thank you in advance for your help!
Did you find any solution?
Hello, I had a very similar problem. I want to open all sales channels of a product using the API. The documentation is not very clear to me. I finally found a solution, so I'm sharing it to help other developers.
async function shopifyGraphQL(query, variables) {
const response = await fetch(`https://${shopName}.myshopify.com/admin/api/2025-01/graphql.json`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Shopify-Access-Token': accessToken,
},
body: JSON.stringify({ query, variables }),
});
const responseBody = await response.json();
if (responseBody.errors) {
throw new Error('Erreur request GraphQL');
}
}
async function publishProductToAllChannels() {
try {
const channelsQuery = `
{
channels(first: 100) {
edges {
node {
id
name
}
}
}
}
`;
const channelsData = await shopifyGraphQL(channelsQuery);
const channels = channelsData.channels.edges.map(edge => edge.node);
const publishMutation = `
mutation publishProduct($productId: ID!, $channelId: ID!) {
publishablePublish(id: $productId, input: { channelId: $channelId }) {
userErrors {
field
message
}
}
}
`;
for (const channel of channels) {
const variables = {
productId: idProduct, // like gid://shopify/Product/675256852
channelId: channel.id,
};
await shopifyGraphQL(publishMutation, variables);
}
} catch (error) {
console.error('Erreur:', error);
}
}
Shopify and our financial partners regularly review and update verification requiremen...
By Jacqui Mar 14, 2025Unlock the potential of marketing on your business growth with Shopify Academy's late...
By Shopify Mar 12, 2025Learn how to increase conversion rates in every stage of the customer journey by enroll...
By Shopify Mar 5, 2025