Magento 2: How to login as Customer and place new order via REST APIs
In order to place a new order as a logged in customer using REST APIs in Magento 2, please follow below steps:
You can Download the Postman Tool from here: www.postman.com
Now, Open Post man and create below Requests: MAGENTO 2 REST APIs:
CUSTOMER LOGIN:
CREATING CUSTOMER QUOTE:
ADD ITEMS TO CART
COLLECT CART TOTALS
GET AVAILABLE SHIPPING METHODS & ESTIMATING SHIPPING CHARGES
SET BILLING AND SHIPPING ADDRESS OF ORDER
PLACE ORDER
Now check your admin panel and there will be a new COD order placed.
You can Download the Postman Tool from here: www.postman.com
Now, Open Post man and create below Requests: MAGENTO 2 REST APIs:
CUSTOMER LOGIN:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Request Type: POST
Request URL: {{baseUrl}}/{{storecode}}/V1/integration/customer/token
Body:
{
"username": {{customerNumber}},
"password": {{customerPassword}}
}
Headers:
Content-Type: application/json
Authorization: Bearer {{token}}
Response:
CustomerToken
CREATING CUSTOMER QUOTE:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Request URL: {{baseUrl}}/{{storecode}}/V1/carts/mine
Request Type: POST
Headers:
Authorization: Bearer {{customerToken}}
Response:
Quote ID
ADD ITEMS TO CART
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Request URL: {{baseUrl}}/{{storecode}}/V1/carts/mine/items
Request Type: GET
Headers:
Content-Type: application/json
Authorization: Bearer {{customerToken}}
Body:
{
"cartItem": {
"sku": "item-sku-1",
"qty": 1,
"quote_id": {{cartId}}
}
}
COLLECT CART TOTALS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Request URL: {{baseUrl}}/{{storecode}}/V1/carts/mine/totals
Request Type: GET
Headers:
Content-Type: application/json
Authorization: Bearer {{customerToken}}
Authorization Type: Inherit Auth from Parent
GET AVAILABLE SHIPPING METHODS & ESTIMATING SHIPPING CHARGES
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Request URL: {{baseUrl}}/{{storecode}}/V1/carts/mine/estimate-shipping-methods
Request Type: POST
Headers:
Content-Type: application/json
Authorization: Bearer {{customerToken}}
Body:
{
"cartId": {{cartId}},
"address": {
"region": {{region_title}},
"region_id": {{region_id}},
"region_code": {{region_code}},
"country_id": {{country_id}},
"street": [
"123 Oak Ave"
],
"postcode": "10577",
"city": {{city_id}},
"firstname": "Reena",
"lastname": "Parekh",
"customer_id": {{customerNumber}},
"email": {{customerEmail}},
"telephone": {{customerNumber}},
"same_as_billing": 1
}
}
SET BILLING AND SHIPPING ADDRESS OF ORDER
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Request URL: {{baseUrl}}/{{storecode}}/V1/carts/mine/shipping-information
Request Type: POST
Body:
{
"addressInformation": {
"shipping_address": {
"region": {{region_title}},
"region_id": {{region_id}},
"region_code": {{region_code}},
"country_id": {{country_code}},
"street": [
"123 Oak Ave"
],
"postcode": "10577",
"city": {{city_code}},
"firstname": "Reena",
"lastname": "Parekh",
"email": {{customerEmail}},
"telephone": {{customerNumber}}
},
"billing_address": {
"region": {{region_title}},
"region_id": {{region_id}},
"region_code": {{region_code}},
"country_id": {{country_code}},
"street": [
"123 Oak Ave"
],
"postcode": "10577",
"city": {{city_code}},
"firstname": "Reena",
"lastname": "Parekh",
"email": {{customerEmail}},
"telephone": {{customerNumber}}
},
"shipping_carrier_code": "freeshipping",
"shipping_method_code": "freeshipping"
}
}
PLACE ORDER
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Request URL: {{baseUrl}}/{{storecode}}/V1/carts/mine/payment-information
Request Type: POST
Headers:
Content-Type: application/json
Authorization: Bearer {{customerToken}}
Body:
{
"paymentMethod": {
"method": "cashondelivery"
},
"billing_address": {
"region": {{region_title}},
"region_id": {{region_id}},
"region_code": {{region_code}},
"country_id": {{country_id}},
"street": [
"123 Oak Ave"
],
"postcode": "10577",
"city": {{city_id}},
"firstname": "Reena",
"lastname": "Parekh",
"email": {{customerEmail}},
"telephone": {{customerNumber}}
}
}
Now check your admin panel and there will be a new COD order placed.
Comments
Post a Comment