Magento 2: How to place order as a guest customer using Magento 2 REST API

In order to place a new order as a guest customer using REST APIs in Magento 2, please follow below steps:

MAGENTO 2 REST APIs:

CREATE GUEST CART:
REQUEST TYPE: POST
REQUEST URL: {{baseUrl}}/{{storecode}}/V1/guest-carts
REQUEST HEADERS: Content-Type : application/json
SAMPLE RESPONSE: "HbJIrSdnPuSQMZdJjq6chEFHQiImPdTs"

NOTE: Quote/Cart ID here is received from Step 1 of creating guest cart.

ADD ITEMS TO GUEST CART:
REQUEST TYPE: POST
REQUEST URL: {{baseUrl}}/{{storecode}}/V1/guest-carts/{{cartId}}/items
REQUEST HEADERS: Content-Type : application/json
REQUEST BODY:
{
"cartItem": {
"sku": "test-sku",
"qty": 1,
"quote_id": "{{cartId}}"
}
}
SAMPLE RESPONSE:
{
"item_id": {{item-id}},
"sku": "test-sku",
"qty": 1,
"name": "test-item-1",
"price": 314,
"product_type": "simple",
"quote_id": "{{quote-id}}"
}

GET TOTALS OF GUEST CART:
REQUEST TYPE: GET
REQUEST URL: {{baseUrl}}/{{storecode}}/V1/guest-carts/{{cartId}}/totals
REQUEST HEADERS: Content-Type : application/json
SAMPLE RESPONSE:
{
"grand_total": 628,
"base_grand_total": 628,
"subtotal": 628,
"base_subtotal": 628,
"discount_amount": 0,
"base_discount_amount": 0,
"subtotal_with_discount": 628,
"base_subtotal_with_discount": 628,
"shipping_amount": 0,
"base_shipping_amount": 0,
"shipping_discount_amount": 0,
"base_shipping_discount_amount": 0,
"tax_amount": 0,
"base_tax_amount": 0,
"weee_tax_applied_amount": null,
"shipping_tax_amount": 0,
"base_shipping_tax_amount": 0,
"subtotal_incl_tax": 628,
"shipping_incl_tax": 0,
"base_shipping_incl_tax": 0,
"base_currency_code": "USD",
"quote_currency_code": "USD",
"items_qty": 2,
"items": [
{
"item_id": 5758,
"price": 314,
"base_price": 314,
"qty": 2,
"row_total": 628,
"base_row_total": 628,
"row_total_with_discount": 0,
"tax_amount": 0,
"base_tax_amount": 0,
"tax_percent": 0,
"discount_amount": 0,
"base_discount_amount": 0,
"discount_percent": 0,
"price_incl_tax": 314,
"base_price_incl_tax": 314,
"row_total_incl_tax": 628,
"base_row_total_incl_tax": 628,
"options": "[]",
"weee_tax_applied_amount": null,
"weee_tax_applied": null,
"name": "test product name"
}
],
"total_segments": [
{
"code": "subtotal",
"title": "Subtotal",
"value": 628
},
{
"code": "shipping",
"title": "Shipping & Handling",
"value": 0
},
{
"code": "tax",
"title": "Tax",
"value": 0,
"extension_attributes": {
"tax_grandtotal_details": []
}
},
{
"code": "grand_total",
"title": "Grand Total",
"value": 628,
"area": "footer"
}
]
}

ESTIMATE SHIPPING OF GUEST CART:
REQUEST TYPE: POST
REQUEST URL: {{baseUrl}}/{{storecode}}/V1/guest-carts/{{cartId}}/estimate-shipping-methods
REQUEST HEADERS: Content-Type : application/json
REQUEST BODY:
{
"cartId": "{{cartId}}",
"address": {
"region": "Baghdad",
"region_id": 611,
"region_code": "Baghdad",
"country_id": "IQ",
"street": [
"123 Oak Ave"
],
"postcode": "10011",
"city": "10",
"firstname": "Reena",
"lastname": "Parekh",
"customer_id": {{customerNumber}},
"email": {{customerEmail}},
"telephone": {{customerNumber}},
"same_as_billing": 1
}
}
SAMPLE RESPONSE:
[
{
"carrier_code": "freeshipping",
"method_code": "freeshipping",
"carrier_title": "Free Shipping",
"method_title": "Free Shipping",
"amount": 0,
"base_amount": 0,
"available": true,
"error_message": "",
"price_excl_tax": 0,
"price_incl_tax": 0
},
{
"carrier_code": "flatrate",
"method_code": "flatrate",
"carrier_title": "Flat Rate",
"method_title": "Fixed Shipping",
"amount": 5,
"base_amount": 5,
"available": true,
"error_message": "",
"price_excl_tax": 5,
"price_incl_tax": 5
},
{
"carrier_code": "clickandcollect",
"method_code": "clickandcollect",
"carrier_title": "Click and Collect",
"method_title": "Click and Collect",
"amount": 5,
"base_amount": 5,
"available": true,
"error_message": "",
"price_excl_tax": 5,
"price_incl_tax": 5
}
]

SET BILLING AND SHIPPING DETAILS OF GUEST CART:
REQUEST TYPE: POST
REQUEST URL: {{baseUrl}}/{{storecode}}/V1/guest-carts/{{cartId}}/shipping-information
REQUEST HEADERS: Content-Type : application/json
REQUEST BODY:
{
"addressInformation": {
"shipping_address": {
"region": "Baghdad",
"region_id": 611,
"region_code": "Baghdad",
"country_id": "IQ",
"street": [
"123 Oak Ave"
],
"postcode": "10011",
"city": "Baghdad",
"firstname": "Reena",
"lastname": "Parekh",
"email": "guest@example.com",
"telephone": {{customerNumber}}
},
"billing_address": {
"region": "Baghdad",
"region_id": 611,
"region_code": "Baghdad",
"country_id": "IQ",
"street": [
"123 Oak Ave"
],
"postcode": "10011",
"city": "Baghdad",
"firstname": "Reena",
"lastname": "Parekh",
"email": {{customerEmail}},
"telephone": {{customerNumber}}
},
"shipping_carrier_code": "freeshipping",
"shipping_method_code": "freeshipping"
}
}
SAMPLE RESPONSE:
{
"payment_methods": [
{
"code": "braintree_paypal_vault",
"title": "Stored Accounts (Braintree PayPal)"
},
{
"code": "braintree_cc_vault",
"title": "Stored Cards (Braintree)"
},
{
"code": "braintree_paypal",
"title": "PayPal (Braintree)"
},
{
"code": "braintree",
"title": "Credit Card (Braintree)"
},
{
"code": "cashondelivery",
"title": "Cash On Delivery"
}
],
"totals": {
"grand_total": 618,
"base_grand_total": 618,
"subtotal": 628,
"base_subtotal": 628,
"discount_amount": -10,
"base_discount_amount": -10,
"subtotal_with_discount": 618,
"base_subtotal_with_discount": 618,
"shipping_amount": 0,
"base_shipping_amount": 0,
"shipping_discount_amount": 0,
"base_shipping_discount_amount": 0,
"tax_amount": 0,
"base_tax_amount": 0,
"weee_tax_applied_amount": null,
"shipping_tax_amount": 0,
"base_shipping_tax_amount": 0,
"subtotal_incl_tax": 628,
"shipping_incl_tax": 0,
"base_shipping_incl_tax": 0,
"base_currency_code": "USD",
"quote_currency_code": "USD",
"items_qty": 2,
"items": [
{
"item_id": 5758,
"price": 314,
"base_price": 314,
"qty": 2,
"row_total": 628,
"base_row_total": 628,
"row_total_with_discount": 0,
"tax_amount": 0,
"base_tax_amount": 0,
"tax_percent": 0,
"discount_amount": 10,
"base_discount_amount": 10,
"discount_percent": 0,
"price_incl_tax": 314,
"base_price_incl_tax": 314,
"row_total_incl_tax": 628,
"base_row_total_incl_tax": 628,
"options": "[]",
"weee_tax_applied_amount": null,
"weee_tax_applied": null,
"name": "test product"
}
],
"total_segments": [
{
"code": "subtotal",
"title": "Subtotal",
"value": 628
},
{
"code": "discount",
"title": "Discount",
"value": -10
},
{
"code": "shipping",
"title": "Shipping & Handling (Free Shipping - Free Shipping)",
"value": 0
},
{
"code": "tax",
"title": "Tax",
"value": 0,
"extension_attributes": {
"tax_grandtotal_details": []
}
},
{
"code": "grand_total",
"title": "Grand Total",
"value": 618,
"area": "footer"
}
]
}
}

PLACE ORDER FROM GUEST CART:
REQUEST TYPE: POST
REQUEST URL: {{baseUrl}}/{{storecode}}/V1/guest-carts/{{cartId}}/payment-information
REQUEST HEADERS: Content-Type : application/json
REQUEST BODY:
{
"paymentMethod": {
"method": "cashondelivery"
},
"billing_address": {
"region": "Baghdad",
"region_id": 611,
"region_code": "Baghdad",
"country_id": "IQ",
"street": [
"123 Oak Ave"
],
"postcode": "10011",
"city": "Baghdad",
"firstname": "Reena",
"lastname": "Parekh",
"email": "guest@example.com",
"telephone": {{customerNumber}}
},
"email": "guest@example.com"
}
SAMPLE RESPONSE: "567"

Comments

Popular posts from this blog

SEO for your Press Releases [Updated 2025 list]

XDebug - PHPStorm - Mac: How to configure Xdebug with PHPStorm on Mac OS and PHP 7.3