3

Magento 2 API docs

  1. http://devdocs.magento.com/swagger/#/
  2. http://devdocs.magento.com/guides/v2.1/rest/list.html

I am trying to place an order using magento 2 REST API. What i have done so far is given below,

  1. Created an empty cart(quoteCartManagementV1: /V1/carts)
  2. Added item to my cart(quoteCartItemRepositoryV1: /V1/carts/mine/items)
  3. Assign billing and shipping info to my cart(checkoutShippingInformationManagementV1 /V1/carts/{cartid}/shipping-information)
  4. Checking out using the cart I created above(quoteCartManagementV1: /V1/carts/{cartid}/order)

I have performed first three of the above four steps successfully, but while performing step no. 4 I am getting the following response from magento 2 REST API,

{"message":"Please enter a customer email."}

My Request against this response was,

{"paymentMethod":{"method":"checkmo"}}

Is there anything wrong in my work flow? Please help!!

1 Answer 1

1

1. Get Customer Token

http://magento-host/index.php/rest/V1/integration/customer/token?
[email protected]&password=test@123
  • method : POST

2. Get Cart ID (Quote ID) - using customer id.

This will return quote id, which will be used for placing an order.

http://magento-host/rest/V1/carts/mine
  • method : POST
  • Authorization : Bearer <customer token>

3. Add Configurable product in cart.

http://magento-host/index.php/rest/default/V1/carts/mine/items
  • method : POST
  • Authorization : Bearer <customer token>
  • body data : json

{
  "cartItem": {
    "sku": "HKrh15hc", <product SKU>
    "qty": 5,
    "quote_id": "75", <Quote ID - Cart ID [see. step 2]>
    "product_option": {
      "extension_attributes": {
        "configurable_item_options": [
          {
            "option_id": "93",
            "option_value": 49
          },
          {
            "option_id": "141",
            "option_value": 168
          }
        ]
      }
    },
    "extension_attributes": {}
  }
}

Now, this will save your configurable product in your cart.


4. Get & put Shipping Information.

http://magento-host/index.php/rest/V1/carts/mine/shipping-information
  • method : POST
  • Authorization : Bearer <customer token>
  • body data : json

{
    "addressInformation": {
        "shippingAddress": {
            "region": "MH",
            "region_id": 0,
            "country_id": "IN",
            "street": [
                "221,Baker-street (e)"
            ],
            "company": "Lumos",
            "telephone": "12345678",
            "postcode": "400001",
            "city": "Mumbai",
            "firstname": "Aditya",
            "lastname": "Shah",
            "email": "[email protected]",
            "prefix": "address_",
            "region_code": "MH",
            "sameAsBilling": 1
        },
        "billingAddress": {
            "region": "MH",
            "region_id": 0,
            "country_id": "IN",
            "street": [
                "221,Baker-street (e)"
            ],
            "company": "Lumos",
            "telephone": "12345678",
            "postcode": "4000001",
            "city": "Mumbai",
            "firstname": "Aditya",
            "lastname": "Shah",
            "email": "[email protected]",
            "prefix": "address_",
            "region_code": "MH"
        },
        "shipping_method_code": "flatrate",
        "shipping_carrier_code": "flatrate"
    }
}

5. Get payment method.

http://magento-host/index.php/rest/V1/carts/75/payment-methods
  • method : POST
  • Authorization : Bearer <customer token>

6. Place an order.

http://magento-host/index.php/rest/V1/carts/mine/order
  • method : POST
  • Authorization : Bearer <customer token>
  • body data : json

{
    "paymentMethod": {
        "method": "checkmo"
    }
}

And finally, this will return order ID, which you just placed!

2
  • how can we use default address ?
    – Hiren
    Commented Mar 26, 2019 at 12:32
  • @aditya-shah we get the order IDs but sometimes we get blank Order IDs we have no idea why it's happening. Ever come across this kind of issue ?
    – sodhancha
    Commented Oct 12, 2020 at 18:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.