Topics covering webhook creation & management, event handling, Pub/Sub, and Eventbridge, in Shopify apps.
I am using Shopify Webhooks' Checkout and Order endpoints. Most of the time the payload contains all the required all the information. However, sometimes the payload has an empty cart_token value, which is essential to my project. Here is an example :
{"id":122929086488,"token":"1547eae7e5128cf84b2be207147120c9","cart_token":null,"email":null,"gateway":null,"buyer_accepts_marketing":true,"created_at":"2017-09-05T14:54:13-04:00","updated_at":"2017-09-05T14:54:13-04:00","landing_site":"\/6747923\/checkouts\/037c145829ef52f38cb2f35347f84362?cookies_blocked=1\u0026no_cookies_from_redirect=1\u0026previous_step=contact_information\u0026step=shipping_method","note":"","note_attributes":[],"referring_site":"https:\/\/hairsoflyshop.com\/6747923\/checkouts\/037c145829ef52f38cb2f35347f84362?no_cookies_from_redirect=1\u0026previous_step=contact_information\u0026step=shipping_method","shipping_lines":[],"subtotal_price":"17.99","taxes_included":false,"total_discounts":"0.00","total_line_items_price":"17.99","total_price":"17.99","total_tax":"0.00","total_weight":366,"currency":"USD","completed_at":null,"closed_at":null,"user_id":null,"location_id":null,"source_identifier":null,"source_url":null,"device_id":null,"phone":null,"customer_locale":"en","line_items":[{"applied_discounts":[],"key":"d1d9caef2d57c79bed4172770cce6bb1","compare_at_price":"45.99","destination_location_id":5551685656,"fulfillment_service":"manual","gift_card":false,"grams":366,"line_price":"17.99","origin_location_id":2853647630,"price":"17.99","product_id":9195426702,"properties":null,"quantity":1,"requires_shipping":true,"sku":"","tax_lines":[],"taxable":true,"title":"Sensationnel Gold 4x4 Silk Based Swiss Lace Wig - Porsha","variant_id":32563610190,"variant_title":"TT1B\/27","vendor":"SENSATIONNEL"}],"name":"#122929086488","source":null,"discount_codes":[],"abandoned_checkout_url":"https:\/\/checkout.shopify.com\/6747923\/checkouts\/1547eae7e5128cf84b2be207147120c9\/recover","tax_lines":[],"source_name":"web"}
Note that the cart_token is empty.
Hi there,
It is completely possible to hit the checkout without creating a cart first. A few examples of this are using the API, using Cart Permalinks (which, despite their name, direct customers straight to the checkout), and POS sales. I'd recommend relying on something else for what you are trying to accomplish.
Cheers,
To learn more visit the Shopify Help Center or the Community Blog.
Thanks for your reply. It makes sense. Can there be a scenario where the Order/Create payload's cart_token value is empty?
Yep! Orders created in any of the scenarios I outlined in my previous post would show a null cart token in the Order/Create payload. If there is no cart, there is no cart token.
To learn more visit the Shopify Help Center or the Community Blog.
Hello Busfox, in this concern my user_id is null in cart creation/updation webhook. Please help I need to get back user/customer_id
Hi Navdeep
If the customer isn't logged in, where would the ID come from? It is perfectly possible to have a cart as an anonymous visitor, so I wouldn't rely on being able to retreieve that info from the webhook.
Hello Karl,
Agree with you, but I was considering the case if user is logged in already and in this case user_id must be returned.
If above is not valid, then how i can get user_id in checkout_creation webhook callback?
Not sure I understand what the problem with that is - if the user is logged in, you will have the customer.id in the webhook - both for checkout_creation and checkout_update
{
"id": 5201345020019,
"token": "0cfca77dfbf36b5042be79f3ab70279c",
"cart_token": "6ef94143c64ca8685337b59d0267f626",
...
"customer": {
"id": 1223191691379,
...
}
}
The user_id is not for the customer who created the checkout. If you follow the docs
The ID of the user who created the checkout. This value is passed to the order. Default value:
null
.
Then check order docs
The ID of the user logged into the Shopify POS that processed the order, if applicable.
So it's the POS user.
Hope that helps clarify matters 😉
Really really appreciate this help. Yup i grabbed customer.id in my callback..
Thanks a lot bro.
No problem. Glad it's working out for you!
@zahid Did you ever find a solution to this problem? I also am stuck at the same point