API to Enable “Add to Cart” for products displayed in Customer Account Extension

Hi everyone,
I’m developing a Shopify app that manages a wishlist. Using a Customer Account Extension, I’ve successfully displayed the wishlist items (product variants) in the customer profile area.

Now, I’d like to add an “Add to Cart” button next to each item.
Which Shopify API or method should I use to implement this functionality?

Any guidance or examples would be greatly appreciated!

Thanks in advance,
Alessandro

Hi Alessandro ,

The Admin API is typically not used for cart operations, if you can access the Storefront API you could use the cartLinesAdd mutation to add items to the cart.

I don’t want to use the Admin API, the extension that I’m writing is a customer account extension that targets the customer page hosted on shopify.com

@Alessandro_Marino
Hi, have you found a solution? I need to create a custom “buy again” button in the user account to pass additional attributes to products. I have everything ready, but I don’t know how to write the logic for adding to cart.

@Marcin_Rycko You’d need to use the Storefront API’s cartCreate mutation, which returns a cart.checkoutUrl value you can use to redirect the customer to checkout when they click your “Buy again” button.

@Alessandro_Marino Adding to the online store cart is a little trickier unfortunately, since there’s no reference to the online store cart from customer accounts. We do plan to fix this, but in the meantime is a workaround using the Shopify AJAX API, by redirecting to the online store when someone clicks your “Add to cart” button, something like https://store.myshopify.com/cart/add?id[]=44308076396835&quantity=1 where id is the variant id.

@Kenza_Iraki

By adding an item to your cart as in the link:
https://store.myshopify.com/cart/add?id[]=44308076396835&quantity=1
Can I add an attribute to an item using searchParams?