Shop has one-time purchase products and subscription products. If user selected one-time product we want to upsell him to subscription on the cart page. Like 'If you buy this product as a subscription it will 15% off'
on the Cart page request all products
if user clicked 'ok want subscription'
find similar product by SKU probably
add it to cart
delete one-time product
how to get all products? I tried admin api, it didn't work, I registered custom app, still no success.
Can anyone please provide the code that will request products for me?
You're probably looking for the Shopify AJAX API.
With this API, you're able to fetch the user's cart, and fetch the details of any of your store's products.
I believe this will be enough to build the features you're after : )
Funnily enough, I'm actually building an app based solution for this.
Feel free to check it out here – https://bag.supply/
Yeah I know about Cart API. My problem is - I can't find a way to request products from /admin/2020-10/products.json. I'm getting an error in response. I tried to add all types of authorization with this request but it didn't work.
One more time:
I have a script file on the Cart page - custom.js. In this script file I'm doing ajax request to products API but can't get a response from it.
The Admin API is not designed to be accessed directly via AJAX from your online store. I believe the only way to access the Admin API from your website would be to create and use a server as a proxy for these requests (Website → Server → Admin API) – this requires some technical experience. If you don't do this, you'll be exposing your access token on your frontend (which is something you never want to do under any circumstance).
The AJAX API, on the other hand, doesn't require authentication, and therefore can be accessed directly from your frontend.
Actually, I forgot to mention, another alternative is the Storefront API (you can also access this directly from your frontend), have you looked into this?