Magento 2 rest api

magento 2 rest api

Today we discuss the Magento 2 rest API. API is also called web services.

API stands for the Application programming interface

Proccess of the prodcut add to cart usign rest API

  1. Create customer token
  2. Create an empty cart/quote using the token
  3. Add to product to the cart
  4. Fetch cart details
  5. Fetch cart totals
  6. Apply coupon code if you have
  7. Remove coupon code from the cart

See below steps to easy development.

Create Customer token:

Method:POST
URL: your_base_url/rest/V1/integration/customer/token
Param:-
{"username": "user@example","password": "user@123"}

Its return token

Create cart:-

Method :- POST
your_base_url/rest/default/V1/carts/mine
Authorization: Bearer token

Add to cart:-

Method :- POST

URL:your_base_url/rest/V1/carts/mine/items
Authorization: Bearer token
param
{
  "cartItem": {
    "sku": "80020",
    "qty": 1,
    "quote_id": "937"
  }
}

Get cart Detail:-

Method :- GET
Authorization: Bearer token

URL:your_base_url/rest/V1/carts/mine/items

Get cart totals:-

Method :- GET
Authorization: Bearer token
URL:your_base_url/rest/V1/carts/mine/totals

Apply coupon code:-

method : PUT
Coupon Code :
1. abc

URL: your_base_url/rest/default/V1/carts/mine/coupons/abc

Authorization:   Bearer xyz

Remove coupon code :-

Method :- DELETE
URL: your_base_url/rest/default/V1/carts/mine/coupons

Payload :
{
    "cartId" :937
}
// 937 is a cart id

Enjoy rest of the day!

Related Post : Add product to cart GraphQL Magento 2

Like us on Facebook and Linkedin for more updates.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top