Sales Channel via GraphQL API?

Highlighted
Excursionist
26 0 1

Right now, all the products in my online store are getting added via ascript that uses GraphQL API.

 

Yet I just realized that none of the products are getting showed on the store itself.

I modifed one product, and in "Product Availability" I added "Online Store".

I believe this is the "sales channel".

 

At the moment that single product shows up on the online store.

Yet how can I add via GraphQL API all products to the online store?

 

The script I created uses the mutation productCreate.

That mutation uses an input object called ProductInput.

On the input fields, there is a field called productPublications which has the information:

A list of the channels where the product is published. This argument is deprecated: Use PublishablePublish instead.

So... MY DOUBT:

Do I have to use instead the new mutation publishablePublish?

This page for  publishablePublish (link above) tells me to use "publicationId".

Is this the same as the sales channel?

 

I'm a little bit confused by all these terms.

 

EOL

1 Like
Highlighted
Excursionist
26 0 1

So I believe the mutation to be used is this one publishablePublishToCurrentChannel.

From there, I am using the GraphiQL application inside the Shopify admin section.

 

Yet I receive an error stating:

"message": "PublishablePublishToCurrentChannel access denied"

Any idea what could be going on?

 

Below is the mutation, then the variable, then the response from the API.

Any help is greatly appreciated.

mutation publishablePublishToCurrentChannel($id: ID!) {
  publishablePublishToCurrentChannel(id: $id) {
    publishable {
      availablePublicationCount
      publicationCount
      publishedOnCurrentPublication
    }
    shop {
      id
    }
    userErrors {
      field
      message
    }
  }
}

Variable (used in GraphiQL application isnde Shopify admin):

{
  "id": "gid://shopify/Product/4944224878730"
}

And finally, the response stating that access denied:

{
  "data": {
    "publishablePublishToCurrentChannel": null
  },
  "errors": [
    {
      "message": "PublishablePublishToCurrentChannel access denied",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "publishablePublishToCurrentChannel"
      ]
    }
  ],
  "extensions": {
    "cost": {
      "requestedQueryCost": 10,
      "actualQueryCost": 10,
      "throttleStatus": {
        "maximumAvailable": 1000,
        "currentlyAvailable": 990,
        "restoreRate": 50
      }
    }
  }
}

 

0 Likes
Highlighted
Excursionist
26 0 1

So... this is going to sound insane, yet the best solution at the moment is:

Create manually a product from within the Shopify administration page.

Set this product inside the Sales Channel you want.

 

Then, via the GraphQL API, duplicate this product.

Once the product is duplicated, once again make yet another api call to set all the details about the item as you want.

 

Bananas.

0 Likes
Highlighted
Shopify Partner
6 0 5

It's crazy the new way isn't publicly available for use after all this time. 

I think the easiest solution is to set

 

'published: true,'

productCreate(input: {
            title: "Green Tea Ginger Twist",
            productType: "test",
            published: true
}
0 Likes
Highlighted
Tourist
6 0 1

The problem with "published: true" is that it only publishes for "online store" which is usually not the only intent

0 Likes
Highlighted
Shopify Partner
6 0 5

Of course it's a problem. I'd be embarrassed if I was shopify.

But OP only mentioned adding to online. This post is what came up first when I was searching to do the same thing yesterday. It took some effort to figure this disaster out.

1 Like