Topics covering webhook creation & management, event handling, Pub/Sub, and Eventbridge, in Shopify apps.
How can I create checkout id by checkout creation webhook? I'd like to create checkout id like this: gid://shopify/Checkout/foo?key=bar to fetch checkout via storefront API.
JSON from checkout creation webhook is below:
{ "id": 12345, "token": "token", "cart_token": "cart_token", "email": null, "gateway": null, "buyer_accepts_marketing": true, "created_at": "2019-11-26T12:47:46-08:00", "updated_at": "2019-11-26T12:47:46-08:00", "landing_site": "/", "note": null, "note_attributes": [], "referring_site": "", "shipping_lines": [], "taxes_included": false, "total_weight": 500, "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": "key", "destination_location_id": null, "fulfillment_service": "manual", "gift_card": false, "grams": 500, "origin_location_id": 1234, "product_id": 1234, "properties": [], "quantity": 1, "requires_shipping": true, "sku": "SKU", "tax_lines": [], "taxable": false, "title": "Title", "variant_id": 1234, "variant_title": "", "variant_price": "16.00", "vendor": "Vendor", "user_id": null, "unit_price_measurement": { "measured_type": null, "quantity_value": null, "quantity_unit": null, "reference_value": null, "reference_unit": null }, "country_hs_codes": [], "country_code_of_origin": null, "province_code_of_origin": null, "harmonized_system_code": null, "compare_at_price": null, "line_price": "16.00", "price": "16.00", "presentment_title": "Title" } ], "name": "#12345", "source": null, "abandoned_checkout_url": "https://mystore.com/12345/checkouts/foo/recover?key=bar", "discount_codes": [], "tax_lines": [], "source_name": "web", "presentment_currency": "USD", "total_discounts": "0.00", "total_line_items_price": "16.00", "total_price": "16.00", "total_tax": "0.00", "subtotal_price": "16.00" }
I tried to fetch checkout with id in the JSON, but I couldn't get checkout.
According to docs at below link:
https://help.shopify.com/en/api/storefront-api/reference/scalar/#id-2019-10
For storefront-api, IDs don't work like "gid://shopify/Product/10079785100".
P.S. Webhooks data adhere to Shopify Admin API data format.
For storefront-api, IDs don't work like "gid://shopify/Product/10079785100".
Yeah, I know we should make ID base64 format for storefront API.
You are right... if you have "gid" you can base64 encode it and get id for storefront-api.
In order to have a "gid" for Checkout, it should be on GraphQL Admin API.
Referring to GraphQL Admin API docs, I didn't find "Checkout" in Queryable objects section.
https://help.shopify.com/en/api/graphql-admin-api/reference/object
When I created checkout via storefront API refer to checkoutcreate , I got checkout id like this: Z2lkOi8vc2hvcGlmeS9DaGVja291dC9mb28/a2V5PWJhcg== which means gid://shopify/Checkout/foo?key=bar. If I can create checkout id like that, I can use the id for storefront API. Therefore, I'd like to know if I can create the id by JSON of checkout creation webhook. Especially I want to know what foo and bar are.
Not sure about this one... What's your end goal wit this? you have the "checkout id" from storefront-api, do you want it for later use?? If yes, store it in database while you are creating the checkout... it could be one way to do it?
The goal is to get checkout id for storefront API by JSON of checkout creation webhook. I will use the checkout id for checkoutDiscountCodeApplyV2
I am not sure if its possible to via checkout/create webhook's json data.
Since you are receiving webhooks, I am assuming you have an app and a server and most probably database. So one workaround would be to store the checkout id while creating the checkout in database and get it whenever you want for later use.
Let's wait for someone else's input too on this one.
Cheers.
how did you do it assuming it had been implemented by now
??
From the webhook you can get abandoned_checkout_url
abandoned_checkout_url=https://????.com/11111/checkouts/xxxx/recover?key=yyyy
xxxx is the token of checkout
The checkout ID using Storefront API is
base64_encode("gid://shopify/Checkout/xxxx?key=yyyy");
This solution is not working. The Checkout query still return "node": null.
Here is the query I am using
query {
node(id: "Z2lkOi8vc2hvcGlmeS9DaGVja291dC9iYTMzNTk0YmI2ZDM1NTQ5NWY2YTIyMTQwN2ZlMGRlND9rZXk9ZDI3YTgzNmQxYjg1ZDQ4OTdjZWEzNDgwZWQ1ZDQwZDc="){
id ... on Checkout {
id
email
webUrl
}
}
}
same issue, any luck going forward?
Hey Rishi,
I noticed that when I used the GraphiQL app on my store, it wouldn't work fetching the checkout.
Then, I realised that storefronts are segmented; the GraphiQL app has a storefront API token that can manage its own checkouts, and my other app had a different storefront API token that manages its own checkouts as well.
The other one is UNABLE TO access the checkouts created by the other token.
Hope this helps