How to place an order using Magento2 API?

awavi picture awavi · Nov 18, 2015 · Viewed 12.3k times · Source

I am looking for the complete "happy path" to place an order using Magento2's REST API. So far these are all the steps I have followed. What else am I missing?

  1. Create a user: [POST] /rest/V1/customers

  2. Log In (create a token): [POST] /rest/V1/integration/customer/token

  3. Get Product Categories for navigation: [GET] /rest/V1/categories

  4. Get Products:

    4.1 Get Category Products: [GET] /rest/V1/categories/{category_id}/products

    4.2 Or search for a product: [GET] /rest/V1/products

  5. Create a cart: [POST] /rest/V1/carts/mine

  6. Add items to cart: [POST] /rest/V1/carts/mine/items

  7. Get cart payment information [GET] /rest/V1/carts/mine/payment-information

  8. ...

What other things do I have to do to place the order?

Answer

Manish picture Manish · Dec 2, 2016
  1. create empty cart url : http://www.xxxxxx.com/rest/V1/carts/mine call: post response: cartID eg: 4290

  2. Add item to the cart url : http://www.xxxxxx.com/rest/V1/carts/mine/items body:

    {"cartItem":{
      "sku":"JFCO00017","qty":1,"name":"Devil May Cry III 3 Dante           Cosplay           Costume","price":81.55,"product_type":"simple","quote_id":"4290","product_option":{"extension_attributes":{"custom_options":[{"option_id":"thumbnail","option_value":"\/d\/e\/devilmaycryiii3dantecosplay_1_.jpg"},{"option_id":"color_2","option_value":"Red"},{"option_id":"google_size","option_value":"xxs"}]}}}
    }
    
  3. Add billling info url : http://www.xxxxxx.com/rest/V1/carts/mine/billing-address body:

    {
    "address": {
    "city": "noida",
    "company": "iprag",
    "countryId": "IN",
    "email": "[email protected]",
    "firstname": "Manish",
    "lastname": "Kumar",
    "postcode": "201301",
    "region": "UP",
    "saveInAddressBook": 1,
    "street": ["D-84"],
    "telephone": "8802xxxx90"
    },
    "useForShipping": true
    }
    
  4. get shipping-methods url : http://www.xxxxxx.com/rest/V1/carts/mine/shipping-methods

    {
    "carrier_code": "flatrate",
    "method_code": "flatrate",
    "carrier_title": "Flat Rate",
    "method_title": "Fixed",
    "amount": 10,
    "base_amount": 10,
    "available": true,
    "error_message": "",
    "price_excl_tax": 10,
    "price_incl_tax": 10
    

    }

  5. add shipping info url : http://www.xxxxxx.com/rest/V1/carts/mine/shipping-information body:

    {
     "addressInformation": {
     "billingAddress": {
        "city": "noida",
        "company": "iprag",
        "email": "[email protected]",
        "firstname": "Manish",
        "lastname": "Kumar",
        "postcode": "335001",
        "region": "UP",
        "street": ["D-84"],
        "telephone": "9413433217"
    },
    "shippingAddress": {
        "city": "noida",
        "company": "iprag",
        "email": "[email protected]",
        "firstname": "Manish",
        "lastname": "Kumar",
        "postcode": "335001",
        "region": "UP",
        "street": ["D-84"],
        "telephone": "9413433217"
      },
       "shippingCarrierCode": "flatrate",
      "shippingMethodCode": "flatrate"
    }
    }
    

response: payment method and cart detail

  1. Order place URL : http://www.xxxxxx.com/rest/V1/carts/mine/order body :

    {
     "paymentMethod":{"method":"checkmo"},
     "shippingMethod":
        {
          "method_code":"flatrate",
    
          "carrier_code":"flatrate",
          "additionalProperties":{}
    
        }
    
    }
    

response: orderid