GraphQL API: Creating webhook with topic VARIANTS_OUT_OF_STOCK fails

GraphQL API: Creating webhook with topic VARIANTS_OUT_OF_STOCK fails

JeroenB
Shopify Partner
3 0 0


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:

  • Install GraphiQL app, only grant products_read (as this is the access scope needed). Creating this webhook via the GraphiQL app works. I am aware of app scope. This is just for in the GraphiQL app.
  • Install my own app, grant products_read and a few more. Check via a GraphQL query that indeed there are zero webhooks (fresh app install on test shop). Then, creating this webhook from my own app's code using the GraphQL mutation listed above gives the response displayed below.
  • To be clear: creating a PRODUCTS_UPDATE webhook from my app using the GraphQL API works fine. This issue seems to be specific to topic: VARIANTS_OUT_OF_STOCK
  • is there another scope besides read_products that is needed? Documentation states read_products scope is needed only. I tried all other scopes available, still the same message.
  • edit:just to be clear, my app uses both an offline token (for cron job related calls) as well as online token (dashboard-based user interaction). In this example, I use the offline token.

 

 

 

{
  "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
      }
    }
  }
}

 

 

 

 

 

 

Reply 1 (1)

JayAdra
Shopify Partner
147 14 38

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.