Topics covering webhook creation & management, event handling, Pub/Sub, and Eventbridge, in Shopify apps.
Hi, I'm currently creating unit tests around the orders/paid webhook in my Shopify App. When I test manually with my test store by completing an order the webhook fires successfully, but when I create an order programmatically using the Shopify API no webhook is fired. The order appears as 'Paid' on the admin/orders page of my Shopify store. Are orders created through the API unable to fire webhooks?
Solved! Go to the solution
This is an accepted solution.
Thanks for all the help! The solution for me ended up being to first create a draft_order instead of an order, and then to just hit
PUT
/admin/api/2020-10/draft_orders/${orderId}/complete.json
which moves the order over to 'paid' and activates the webhook.
I might be wrong, but I think that webhooks created via the API will fire when triggered via an API call. But if they are created via the web UI then they will fire when triggered through the web UI. Someone can feel free to correct me if I'm mistaken however...
I don't think this is right, because I created the webhook using my node Shopify App and it still fires whenever an order is paid in the store.
You're right. I was thinking more about how webhooks created via the API aren't visible in the web admin from a management sense. None of that affects their actual firing. Duh!
With respect to the method of subscription creation affecting how webhooks trigger, you both are correct: There is no relation between the two. An `orders/paid` subscription will fire under the same conditions as any other `orders/paid` subscription.
With respect to `orders/paid` webhooks in general: They fire when an Order transitions to a paid state. This is an important distinction because creating a paid Order through the API will not trigger that webhook because there is no previous state from which to transition. In contrast, creating a paid Order through the merchant admin actually happens in two steps: The Order is created, and then it is marked as paid. You can confirm this by subscribing to `orders/create` webhooks and re-testing.
armurray | Developer @ 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
@armurray thanks for the clarifications. That makes perfect sense, in that creating a new/paid order is just a single step. I assume the OP will need to utilize the API for two separate requests --- one to create the new order, then another to modify the existing order to flag as paid --- in order for his expected webhook to be fired off.
Thanks! That makes sense. I'll try that and get back.
Update: I changed my Order api request to set the financial_status to 'authorized' instead of 'paid' and then did a put request with the returned id of the order, but the order was not updated to 'paid' and stayed in the 'authorized' state. Is there something special I have to do to change the financial_status? Here's what my request looks like. It returns 200.
return axios.put(`https://{my_store's_name}.myshopify.com/admin/api/2020-10/orders/${orderId}.json`,
{
order: {
id: orderId,
financial_status: 'paid',
},
},
{
headers: {
'content-type': 'application/json',
'X-Shopify-Access-Token': await getAccessToken(),
},
});
Here is another thread regarding this topic --> https://community.shopify.com/c/Shopify-APIs-SDKs/Marking-order-transaction-as-paid-with-REST-Admin-.... There might need to be a different hoop to jump through in order to achieve what you're looking for. Unfortunately...
If you want to try the GraphQL API (https://shopify.dev/docs/admin-api/graphql/reference/orders/ordermarkaspaid), I do see there is a order mutation that appears to accomplish this. Haven't tried it to verify if it's viable though.
Can confirm, it works (https://shopify.dev/docs/admin-api/graphql/reference/orders/ordermarkaspaid)
This is an accepted solution.
Thanks for all the help! The solution for me ended up being to first create a draft_order instead of an order, and then to just hit
PUT
/admin/api/2020-10/draft_orders/${orderId}/complete.json
which moves the order over to 'paid' and activates the webhook.