Orders/paid webhook not firing when created through the Shopify API

Solved
mandolin-david
Tourist
5 1 0

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?

0 Likes
Greg_Kujawa
Shopify Partner
1016 83 237

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... 

0 Likes
mandolin-david
Tourist
5 1 0

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. 

0 Likes
Greg_Kujawa
Shopify Partner
1016 83 237

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!

 

armurray
Shopify Staff
Shopify Staff
7 1 0

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

0 Likes
Greg_Kujawa
Shopify Partner
1016 83 237

@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.

0 Likes
mandolin-david
Tourist
5 1 0

Thanks! That makes sense. I'll try that and get back. 

0 Likes
mandolin-david
Tourist
5 1 0

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(),
      },
    });
0 Likes
Greg_Kujawa
Shopify Partner
1016 83 237

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... 

Greg_Kujawa
Shopify Partner
1016 83 237

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. 

0 Likes