Product Order Payload: How To Order Product Using Magento 2 REST API

In this Magento2 article, I am going to explain order flow using Rest API. Here, I am going to show you each step of the Magento 2 product order payload and their endpoint in detail.

It is mostly used for making mobile applications.

When we create a generic android mobile app time it is used to access and communicate data from the Magento 2 website and also used to implement basic features for any kind of mobile application using the Magento shopping framework.

Today there are so many options available to make payment in Magento, whether it is PayPal or Razorpay, or any other payment method when we want to pay it through rest API in the mobile application then usually we face the problem of transaction id or payment id. So this article will help you while Magento 2 payment gateway interaction in a Mobile application using REST API.

 

Step 1: Generate Customer Access Token

In the first step we need to generate the customer access token then only we can move to the next step to add a cart to a customer account.

In the POST request enter your store URL along with this endpoint.

Method: POST

Endpoint: www.wishusucess.com/rest/V1/integration/customer/token

Payload:

{  
"username": "cs.hemantsingh@gmail.com", 
"password": "Addddmin@#123" 
}

customer token creation api

Step 2: Create a Cart - Product Order Payload

Now, in the second step we will create a cart by using Magento 2 REST API, So in order to add items in the cart using rest API will contain the customer’s authorization token in the authorization header.

Method: POST

Endpoint:

https://wishusucess.com/rest/default/V1/carts/mine

Scope: default store view

Headers:

  • Content-Type: application/json
  • Authorization: Bearer n785dukrtbh4dhhuqfvc4aaito60ju1f

add to cart api

 


How to Get Quote ID in Magento 2 REST API

We can get the Quote ID by using rest/default/V1/carts/mine endpoint with the POST method.

Note: Now we have the response and the response quoteId is 119.

How to Check Product Availability?

We can check product availability by using the following rest API in Magento 2.

https://wishusucess.com/rest/default/V1/inventory/get-product-salable-quantity/SKU/2

Now we have ensured by checking the salable quantity that we have enough quantity of products in stock so we can order the potential order.


 

Step 3: Add Products to Cart Using REST API

So, in the third step, we can add products to the cart by using the following details.

Method: POST

Endpoint: 

https://www.wishusucess.com/rest/default/V1/carts/mine/items

Headers:

  • Content-Type: application/json
  • Authorization: Bearer <customer_token>

Payload:

{
"cartItem": {
"sku": "test-product-2",
"qty": 2,
"quote_id": "3"
}
}

rest api for add to cart using quote id

Read More: Add To Cart REST API for All Type of Products

 

Step 4: Get All Payment Information Using API

So, in the fourth step, we can check the list of available payment information to make payment done using API.

Method: GET

Endpoint: 

https://wishusucess.com/rest/V1/carts/mine/payment-information

Headers:

  • Content-Type: application/json
  • Authorization: Bearer <customer_token>

Payload:

  • Not Required

Product Order Payload

So now using the above Magento 2 REST API we can get all available payment methods in Magento 2.

 

Step 5: Save Payment Information and Order

In this step, we will use the post method to save the information and send the payment method type to complete the payment. Then only orders will be created by Magento 2 REST API. After successful order creation customer will receive the response of order confirmation.

Endpoint:

https://wishusucess.com/rest/V1/carts/mine/payment-information

Headers:

  • Content-Type application/json
  • Authorization Bearer ikdvclhbdr8a13473hyf3vdxq9m7ouh2

Payload:

{
"paymentMethod": {
"method": "cashondelivery"
},
"billing_address": {
"email": "cs.hemantsingh@gmail.com",
"region": "Uttar Pradesh",
"region_id": 566,
"region_code": "UP",
"country_id": "IN",
"street": [
"PMO Appartment"
],
"postcode": "201301",
"city": "Noida",
"telephone": "7992293862",
"firstname": "Hemant",
"lastname": "Singh"
}
}

Product Order PayloadResponse: 74


 

Related Article:

Cart Images: Get Product Image in Customer Cart Magento 2 REST API

How to Send Push Notifications on Android Application

Product Alert API: Get Magento 2 Product Alert Using API

Leave a Reply