Topics covering webhook creation & management, event handling, Pub/Sub, and Eventbridge, in Shopify apps.
To create a webhook with topic VARIANTS_OUT_OF_STOCK I use GraphQL https://shopify.dev/api/admin-graphql/2022-01/enums/WebhookSubscriptionTopic#value-variantsoutofstoc...
"The webhook topic for variants/out_of_stock events. Occurs whenever a variant becomes out of stock. Requires the read_products scope."
So, I use https://shopify.dev/api/admin-graphql/2021-10/mutations/webhookSubscriptionCreate
mutation {
webhookSubscriptionCreate(
topic: VARIANTS_OUT_OF_STOCK
webhookSubscription: {
callbackUrl: "https://server/path"
format: JSON
})
{
webhookSubscription {
id
}
userErrors {
message
}
}
}
It works fine in the GraphiQL app, but not in my own app.
This is what I do:
{
"data": {
"webhookSubscriptionCreate": {
"webhookSubscription": null,
"userErrors": [
{
"message": "Topic Invalid topic specified: variants/out_of_stock. Does it exist? Is there a missing access scope? Topics allowed: app/uninstalled, carts/create, carts/update, checkouts/create, checkouts/delete, checkouts/update, collections/create, collections/delete, collections/update, order_transactions/create, orders/cancelled, orders/create, orders/delete, orders/edited, orders/fulfilled, orders/paid, orders/partially_fulfilled, orders/updated, products/create, products/delete, products/update, refunds/create, shop/update, themes/create, themes/delete, themes/publish, themes/update, inventory_levels/connect, inventory_levels/update, inventory_levels/disconnect, inventory_items/create, inventory_items/update, inventory_items/delete, tender_transactions/create, app_purchases_one_time/update, app_subscriptions/update, locales/create, locales/update, domains/create, domains/update, domains/destroy, selling_plan_groups/create, selling_plan_groups/update, selling_plan_groups/delete, bulk_operations/finish\n"
}
]
}
},
"extensions": {
"cost": {
"requestedQueryCost": 10,
"actualQueryCost": 10,
"throttleStatus": {
"maximumAvailable": 1000.0,
"currentlyAvailable": 990,
"restoreRate": 50.0
}
}
}
}
I had the same issue and contacted Shopify about it. They have clarified the reason, here's their response:
I was able to replicate the behaviour you described on both the variants/in_stock and variants/out_of_stock topics and asked our developers for clarification. They have informed me that write_publications is also required to subscribe to either of those topics.
If you are working with a Plus merchant with a private app then having them contact Plus Support directly would be the easiest way to enable those scopes, and if you have any further questions relating to this issue, please don't hesitate to reach out.
Hope this helps anyone coming across the same issue.