cancel
Showing results for 
Search instead for 
Did you mean: 

How can i apply Coupon code in magento2 using REST API

SOLVED

How can i apply Coupon code in magento2 using REST API

How can i apply Coupon code in magento2 using REST API. which order should i call the rest apis in order to get totals after applying coupon codes.

1 ACCEPTED SOLUTION

Accepted Solutions

Re: How can i apply Coupon code in magento2 using REST API

Hello @pratap_penmetsa

 

If you are not aware with API's Kindly refer to Swagger from Magento2
http://devdocs.magento.com/swagger/#/


Here you can find
quoteCouponManagementV1
Coupon management service interface.
PUT /V1/carts/{cartId}/coupons/{couponCode}

 

You can use this API once your quote is ready you can apply after that.

Manish Mittal
https://www.manishmittal.com/

View solution in original post

5 REPLIES 5

Re: How can i apply Coupon code in magento2 using REST API

Hello @pratap_penmetsa

 

If you are not aware with API's Kindly refer to Swagger from Magento2
http://devdocs.magento.com/swagger/#/


Here you can find
quoteCouponManagementV1
Coupon management service interface.
PUT /V1/carts/{cartId}/coupons/{couponCode}

 

You can use this API once your quote is ready you can apply after that.

Manish Mittal
https://www.manishmittal.com/

Re: How can i apply Coupon code in magento2 using REST API

Hi @Manish Mittal 

 

I am using the same PUT /V1/carts/{cartId}/coupons/{couponCode} Api to apply coupon for a cart. But I am getting below error.

{
   "message": "No such entity with %fieldName = %fieldValue",
   "parameters": {
      "fieldName": "cartId",
      "fieldValue": 2
   }
}

 

As mentioned by you, I should be using this api only once the quote is ready. How can I check or which API response will show me that the quote is ready?

 

Re: How can i apply Coupon code in magento2 using REST API

@Manish Mittal Any update on this?


@sarita_furtado wrote:

Hi @Manish Mittal 

 

I am using the same PUT /V1/carts/{cartId}/coupons/{couponCode} Api to apply coupon for a cart. But I am getting below error.

{
   "message": "No such entity with %fieldName = %fieldValue",
   "parameters": {
      "fieldName": "cartId",
      "fieldValue": 2
   }
}

 

As mentioned by you, I should be using this api only once the quote is ready. How can I check or which API response will show me that the quote is ready?

 


 

Re: How can i apply Coupon code in magento2 using REST API

Hello @pratap_penmetsa 

 

The Magento 2 REST API identifies various functions which can be used to perform requests and receive responses. A developer can perform these interactions by using the HTTP protocol.

 

  1. First of all, you need to create a new cart price rule and set it up in Marketing > Promotions > Cart Price Rules.
  2. Then open the Rule Information section and choose Specific Coupon in the Coupon dropdown.
  3. Enter the needed value in the field Coupon Code.

Re: How can i apply Coupon code in magento2 using REST API

To apply Coupon code in Magento 2, Firstly you will have to set up a new cart price rule that is used to count the discount. 

- Create the new cart price rule and set it up in Marketing > Promotions > Cart Price Rules. 

- Open the Rule Information and select the particular Coupon.

- Enter the value in Coupon Code.

- Specify how much time the coupon can be used.

- Configure the rest of the Cart Price Rule and save all the changes that you have made.