Photo by Douglas Lopes on Unsplash
Complete Order Flow for Guest and LoggedIn Customer Using REST API
Guest
1. Create Empty Cart
End Point = http://magento.local/en-uae/rest/V1/guest-carts
Method = POST
Output = token(hFJ9dQO4nkyTwWJFoiAdk9Bp4SF9aJo7)
2. Get Cart ID By Token
End Point = http://magento.local/en-uae/rest/V1/guest-carts/(token)
Method = GET
Output = Cart Details
3.Add Item to Cart
End Point = http://magento.local/en-uae/rest/V1/guest-carts/(token)/items
Method = POST
Body = `{ "cartItem": {
"sku": "ABC1088",
"qty": 1,
"quote_id": "6261"
}
}`
Output = Added Product Details
4.Fetch Shipping Method Details
End Point = http://magento.local/en-uae/rest/V1/guest-carts/(token)/estimate-shipping-methods
Method = POST
Body = `{
"address": {
"region": "Dubai",
"country_id": "AE",
"street": [
"L-142, 5th Main Rd"
],
"postcode": "560102",
"city": "Hsr Layout",
"firstname": "john",
"lastname": "herry",
"customer_id": null,
"email": "admin@example.com",
"telephone": "020394238",
"same_as_billing": 1
}
}`
OutPut = Added Shipping Methods
5. Fetch Available Payment Methods
End Point = http://magento.local/en-uae/rest/V1/guest-carts/(token)/shipping-information
Method = POST
Body = `{
"addressInformation": {
"shipping_address": {
"region": "Dubai",
"country_id": "AE",
"street": [
"L-142, 5th Main Rd"
],
"postcode": "560102",
"city": "Hsr Layout",
"firstname": "herry",
"lastname": "herry",
"customer_id": null,
"email": "admin@example.com",
"telephone": "888888884454"
},
"billing_address": {
"region": "Dubai",
"country_id": "AE",
"street": [
"L-142, 5th Main Rd"
],
"postcode": "560102",
"city": "Hsr Layout",
"firstname": "John",
"lastname": "herry",
"customer_id": null,
"email": "Example@gmail.com",
"telephone": "77676657567567"
},
"shipping_carrier_code": "instore",
"shipping_method_code": "pickup"
}}`
Output = Available Payment Methods
6. Place Order
End Point = http://magento.local/en-uae/rest/V1/guest-carts/(token)/payment-information
Method = GET
Body = `{
"email": "admin@gmai.com",
"paymentMethod": {
"method": "cashondelivery"
},
"billing_address": {
"email": "exmaple@gmai.com",
"region": "CHd",
"region_id": 612,
"region_code": "",
"country_id": "AE",
"street": [
"123 Dublin street"
],
"postcode": "560102",
"city": "Hsr Layout",
"telephone": "007432423423",
"firstname": "Herry",
"lastname": "Kddd"
}
}`
LoggedIn
1. Get Customer Token
End Point = http://magento.local/en-uae/rest/V1/integration/customer/token
Method = POST
Body = `{
"username":"test@gmail.com",
"password":"Test123@@"
}`
Output = Bearer Token
2. Get Cart Details
End Point = http://magento.local/en-uae/rest/V1/carts/mine
Method = GET
Output = cart details
3. Add Product to Cart
End Point = http://magento.local/en-uae/rest/V1/carts/mine/items
Method = POST
Header = Bearer Token = ( Pass token from step -1(logged-in))
Body = `{
"cartItem": {
"sku": "ABC1088",
"qty": 1,
"quote_id": "6255"
}
}`
Output = Added Product Details
4. Add Billing Address
End Point = http://magento.local/en-uae/rest/V1/carts/mine/billing-address
Method = POST
Header = Bearer Token = ( Pass token from step -1(logged-in)
Body = `{
"address": {
"city": "Hsr Layout",
"company": "Company",
"countryId": "AE",
"email": "Example@gmai.com",
"firstname": "Herry",
"lastname": "John",
"postcode": "560102",
"region": "Chd",
"saveInAddressBook": 1,
"street": ["L-142, 5th Main Rd"],
"telephone": "0036564324"
},
"useForShipping": true
}`
Output = You will get added details
5. Get Shipping methods
End point = http://magento.local/en-uae/rest/V1/carts/mine/shipping-methods
Method = GET
Header = Bearer Token = ( Pass token from step -1(logged-in)
6. Get Shipping Information
End point = http://magento.local/en-uae/rest/V1/carts/mine/shipping-information
Method = POST
Header = Bearer Token = ( Pass token from step -1(logged-in))
Body = `{
"addressInformation": {
"shipping_address": {
"region": "Dubai",
"country_id": "AE",
"street": [
"L-142, 5th Main Rd"
],
"postcode": "560102",
"city": "Hsr Layout",
"firstname": "John ",
"lastname": "herry",
"customer_id": null,
"email": "exmpale@gmail.com",
"telephone": "073743434"
},
"billing_address": {
"region": "Dubai",
"country_id": "AE",
"street": [
"L-142, 5th Main Rd"
],
"postcode": "560102",
"city": "Hsr Layout",
"firstname": "herry ",
"lastname": "poter",
"customer_id": null,
"email": "exmape@gmao.com",
"telephone": "083843434"
},
"shipping_carrier_code": "instore",
"shipping_method_code": "pickup"
}}`
7. Place Order
End Point = http://magento.local/en-uae/rest/V1/carts/mine/order
Method = PUT
Header = Bearer Token = ( Pass token from step -1(logged-in)
Body = `{
"paymentMethod":{"method":"checkmo"},
"shippingMethod":
{
"method_code":"freeshipping",
"carrier_code":"freeshipping",
"additionalProperties":{},
"region_id":""
}}`