When a customer first adds an item to their shopping cart, Magento produces a quote. Magento uses a quotation to perform tasks such as:
- Collect customer records, including billing and shipping addresses.
- Determine the cost of shipping.
- Calculate the subtotal, incorporate costs (shipping fees, taxes, etc.) and submit coupons to calculate the total number.
- Determine the method of payment.
- Place the order so that the merchant can fill it in.
Type of carts
There are 3 type of user that can create a shopping cart:
- Admin can create a cart for customer
- A customer that log in with his/her account
- A user who doesn’t log in, a guest user
Create a cart for log-in user
I will use Postman to interact with Magento 2 API and create a quote. First you have to generate a customer access token with this endpoint:
POST /rest/<store_code>/V1/integration/customer/token
{
"username": "string",
"password": "string"
}
Create a Post request with this endpoint
POST /rest/<store_code>/V1/carts/mine
Enter access token as Bearer token in Authorization section
Then click Send
The response is the quoteId
You have created cartId for your quote. QuoteId appears nowhere on the website or in Admin. Therefore, you don’t have to verify this id.
I have shown you how to create a quote for your customer account using Magento 2 API. With this quote, you can add items to carts and much more. Read our posts to learn more about Magento API. For more information please read Magento DevDocs.