Building a cart: admin API vs storefront API

Building a cart: admin API vs storefront API

Jānis_Elmeris
Tourist
6 0 3

I would like to use a custom (out-of-Shopify) page for a user to build their highly customised product and then add it to a Shopify cart and redirect the user to it to do the actual payment, confirmation etc.

It looks like I can create a cart (a checkout?) in both APIs:

* admin API (POST /admin/checkouts.json): https://help.shopify.com/api/reference/checkout
* storefront API ("mutation{checkoutCreate.."): https://help.shopify.com/api/storefront-api/guides/checkout-guide#creating-the-checkout

And there is a "web_url"/"webUrl" property in both cases which I would use to redirect the user to the checkout page.

So, why should I choose one API over the other?

On the admin API page about managing checkout there is even a note "You can't use the Checkout API to create a new checkout user experience for an individual store. For that you need to use an SDK that's powered by the Storefront API instead". So, why can't I use that API?

UPDATE Oh, I got a checkout creation working and it turns out wat I actually want is to create a cart not a checkout. Is that even possible? I did not see a reference to carts in the API docs, only checkouts.

Replies 3 (3)

Ariel_Estrin
Excursionist
15 0 6

what you need is Cart API. you just need to send information to the cart of the specific user. 

When the user enters the checkout shopify will fetch all the products from the cart stored in their database and put it in the checkout.

you can even do it directly from AJAX calls on the site, if you wish to or do direct calls to the shopify api from your own external api.

 

 

Jānis_Elmeris
Tourist
6 0 3

Thank you for the pointer!

I could not do AJAX calls from my site (another domain), but I also found the .json entrypoints (the same as the AJAX ones, but replace ".js" by ".json") and the JSONP requests worked, so all seems to look all right for now.

Zia_Web
Tourist
7 0 1

Hi @Janis Elmeris

Could you please explain how you used cart api 

I'm developing a mobile app using ionic, I need to add item to cart using admin api

 

thank you