Create a cart which is specific to the user

10 0 2

Hi All,
Currently am using below added code snippet to create cart with item and fetching the cart items which ever added but how to restrict to the user?
for an example if one user added items to the cart and other user can also able to see them now? How to restrict the other user not to fetch the same cart items which created by user(first)?

Add items to the cart method:

addtoCart = () => {
this.setState({ loading: 'true' });
var that = this;
var data = 'id=' + variantId + '&quantity=1'
//POST request 
fetch('', {
method: "POST",//Request Type 
body: data,//post body 
headers: {//Header Defination 
'Content-Type': 'application/x-www-form-urlencoded',
'x-shopify-access-token': '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',
}).then((response) => response.json())
.then((responseJson) => {
console.log("Cart Response", responseJson);
//If response is not in json then in error
.catch((error) => {
this.setState({ loading: 'false' })


Fetch items from the created cart(method):

fetchCart = () => {
var data = [];
var that = this;
console.log('Fetching items from cart');
//GET request 
fetch('', {
method: "GET",//Request Type 
.then((response) => response.json())
//If response is in json then in success
.then((responseJson) => {
console.log("Cart Response", responseJson.items);
.catch((error) => {


Reply 1 (1)
15 1 3

dont use AJAX API

try `js-buy-sdk`

`client.checkout.create()` which allows to create multiple checkouts

then based on checkoutId you can add product to specific checkout

See => "Adding Line Items" for details

- Was my response helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution!