Solved

Storefront API: "add to basket" instead of creating a checkout?

xosofox
Tourist
11 0 5

Hello,

 

using the storefront API's checkoutCreate mutation, I managed to add products to a Checkout that gives me a checkout.webUrl in return.

 

However, I'd like to not directly create a checkout and send the user to the payment process but rather would be able to add products (via a custom frontend app) to "the basket", so I could send users to the web shop where they still would be able to add other products before getting to the checkout.

 

Is there any way to achieve this? Any pointers would be appreciated

 

Peter

Accepted Solution (1)

Alex
Shopify Staff
1561 81 341

This is an accepted solution.

You can create and manage carts using the Ajax API. This is however only meant to be used in the storefront context, so you can't do this from your server side (at least very easily/in a supported way). Other than that, you're going to have to use the web checkout unless you simulate a cart yourself on your end.

 

Cheers.

Alex | 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 the Shopify Help Center or the Shopify Blog

View solution in original post

Replies 6 (6)

Alex
Shopify Staff
1561 81 341

This is an accepted solution.

You can create and manage carts using the Ajax API. This is however only meant to be used in the storefront context, so you can't do this from your server side (at least very easily/in a supported way). Other than that, you're going to have to use the web checkout unless you simulate a cart yourself on your end.

 

Cheers.

Alex | 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 the Shopify Help Center or the Shopify Blog

xosofox
Tourist
11 0 5

Hi,

 

thanks for the pointer onto the AJAX API.

 

Why is this API so well hidden or somehow even kept a secret?

 

I've been digging through the documentations and somehow I never found it - is there a reason why this API is not simply listed on the API refence list https://help.shopify.com/en/api/guides ?

xosofox
Tourist
11 0 5

Am I understanding correctly that there is no CORS support for the AJAX API, so I cannot call the endpoints from another domain but only from inside my shop?

Is there a plan on supporting CORS for whitlisted domains?

Alex
Shopify Staff
1561 81 341

Correct there is not currently any CORS support for the Ajax API, as it depends on the storefront session being set on the domain you're calling it from.

 

The Ajax API is designed as more of a theme concern, so I can't speak to its discoverability on the theme design documentation since I specialize in the API docs.

 

It might be handy to surface it on the API docs too, so I'll pass that feedback along. Truthfully, this API has not been iterated upon in quite some time. There aren't any near future plans to refine it that I'm aware of, so priorities are likely not on this at the moment. The least we can consider doing though is making it more discoverable, so I'll start talking about that internally.

 

Cheers.

Alex | 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 the Shopify Help Center or the Shopify Blog

xosofox
Tourist
11 0 5

Hi @Alex ,

 

accepting your "AJAX API" reply as a solution 'for now'.

 

I still would like to add that there is a rise of "native like" JavaScript apps (like PWA, ...) - which are terrible to manage when limited to the same domain as the shop itself from a security perspective (origin issues, CDN urls, tainted canvases, ...)

 

What I would really like to see - and this migh be a selling point for shopify - is the "simple" ability to enable CORS (with accepted origins) for the AJAX API so JS apps can be hosted "somewhere known and accepted" and still fill a customers shopping basket through the simple yet powerful JSON API

 

Good luck in mentioning this internally...

Alex
Shopify Staff
1561 81 341

Hey @xosofox.

 

Sorry for the delayed reply, my team's been real busy leading into and during Unite. I just wanted to pop by to thank you for the feedback, it's not the first time I've heard this request. I'll make sure it's passed along.

 

Cheers.

Alex | 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 the Shopify Help Center or the Shopify Blog