Publish Shopify Products to Facebook Channel via API

Markus Tripp
3 min readOct 19, 2021

--

One of my clients owns a Shopify store (Advanced Shopify Plan) with around 15k products. We manage the products in an external system and create/update the products in Shopify via a custom private app using the REST API.

Shopify dialog to manually publish a product to sales channels.

Facebook marketing is an essential part of our marketing strategy. Shopify offers a standard integration with Facebook via a Sales Channel. So far, we are pretty happy with the integration and the possibilities this opens for the future.

Because we want to market only 80% of the product catalog on Facebook, we cannot manage all the 15k relationships manually on Shopify.

Therefore we wanted to update the Facebook relationship via the API during the synchronization from our external system.

REST API

The Product resource in the REST API has a property called published_scope with the available values web and global. Unfortunately, this does not give us the option to update the relationship to the Facebook channel.

GraphQL API

I love the Shopify GraphQL API. And it offers the mutation publishablePublish (and publishableUnpublish) to publish resources to a channel. In the GraphQL Explorer app, I tried to update the Facebook channel via the following GraphQL query on a development store:

mutation publishablePublish(
$id: ID!,
$input: [PublicationInput!]!) {
publishablePublish(id: $id, input: $input) {
userErrors {
field
message
}
}
}

Query variables:

{
"id": "gid://shopify/Product/123456",
"input": {
"publicationId": "gid://shopify/Publication/7890123"
}
}

And it worked!

But then I discovered it requires the write_publications access scope. And this scope is currently available to private apps installed on Shopify Plus stores only.

What can I do now?

I found a workaround that is acceptable as an intermediate solution to this problem.

  1. The synchronization interface adds the tag “Facebook” to all products that need to be published on the Facebook channel.
  2. After the synchronization process (2 to 3 times per week), a shop admin has to navigate to the product overview page, select all products with the “Facebook” tag and call the action “Add available channels”.
Steps to “Add available channels” to products

That’s it. It is not the perfect solution, but acceptable until the GraphQL API for publishablePublish gets available to all merchants.

--

--

Markus Tripp
Markus Tripp

Written by Markus Tripp

I ❤️ Shopify, Laravel, Next.js.

No responses yet