Create product with published scope using GraphQL API

Solved
Ashu24
New Member
5 0 0

Shopify Rest APIs provides an attribute 'published_scope' that denotes where the product will be published, while creating a product, where the values could be either web (online store) or global (both online and POS).

https://shopify.dev/api/admin-rest/2021-10/resources/product#[post]/admin/api/2021-10/products.json

But I am using GraphQL APIs for creating a product. Do we have something similar in GraphQL API? I need to publish my product using API conditionally. Some could be only for web and others for both web and POS stores.

Below is the link for GraphQL API.

https://shopify.dev/api/admin-graphql/2021-10/mutations/productCreate

Accepted Solution (1)

Accepted Solutions
csam
Shopify Staff (Retired)
Shopify Staff (Retired)
267 40 46

This is an accepted solution.

Hi @Ashu24 

Publishing products via the API works a little differently with GraphQL, but you can definitely still do it. You'll want to use the publishablePublish mutation which you can about in our docs here: https://shopify.dev/api/admin-graphql/2021-10/mutations/publishablePublish 

Hope this is helpful! 

CS | API Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

View solution in original post

Replies 5 (5)
csam
Shopify Staff (Retired)
Shopify Staff (Retired)
267 40 46

This is an accepted solution.

Hi @Ashu24 

Publishing products via the API works a little differently with GraphQL, but you can definitely still do it. You'll want to use the publishablePublish mutation which you can about in our docs here: https://shopify.dev/api/admin-graphql/2021-10/mutations/publishablePublish 

Hope this is helpful! 

CS | API Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

Ashu24
New Member
5 0 0

@csam  Follow up question: where can i find publication id as mentioned in publishablePublish mutation.

 
{
"id": "",
"input": {
      "channelId": "",
      "publicationId": "",
      "publishDate": ""
   }
}
 
As mentioned there, id is the resource id, so that would br the Product ID. Where can I find this publication Id? can you give me some format or steps where to find this?
Ashu24
New Member
5 0 0

@csam Any update on this?

csam
Shopify Staff (Retired)
Shopify Staff (Retired)
267 40 46

Hi @Ashu24 

I believe that publicationId is being used now rather than the channelId field, which has been deprecated. Looking at the docs I believe you would use the same value as you would for channelId.

 

CS | API Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

kahli
Shopify Partner
4 1 0

Hi Csam, 

 

I'm trying to publish a product via the publishablePublish, like so:

mutation {
    publishablePublish (
      id: "gid://shopify/Product/${id}",
      input: {
        publicationId: "gid://shopify/Channel/${publication.publicationId}"
      }
    ) {
      userErrors {
        field
        message
      }
    }
  }

However I'm getting this back:

{
  message: 'invalid id',
  locations: [ { line: 2, column: 5 } ],
  path: [ 'publishablePublish' ]
}

I've triple checked the product id, and it appears right, any ideas?