8

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?

awavi
  • 837
  • 3
  • 11
  • 23
  • Did you take this a step further and create a shipment for an order as well? I can't seem to figure out how to POST the right parameters to create a shipment. I can edit existing ones, but can't create new ones. Curious to see if you've figure it out. – Tim Trampedach Apr 07 '16 at 01:42
  • Sorry I did not. I only sell virtual products. – awavi Apr 09 '16 at 11:19

2 Answers2

4
  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": "manish+2@gmail.com",
    "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": "nkn@gmail.com",
        "firstname": "Manish",
        "lastname": "Kumar",
        "postcode": "335001",
        "region": "UP",
        "street": ["D-84"],
        "telephone": "9413433217"
    },
    "shippingAddress": {
        "city": "noida",
        "company": "iprag",
        "email": "nkn@gmail.com",
        "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

Manish
  • 639
  • 6
  • 17
  • Could you please answer this question ?http://stackoverflow.com/questions/41158020/not-able-to-place-the-order-using-paypal-in-magento-2-rest – Muhsin Keloth Dec 16 '16 at 11:49
  • sure, I have the same issue. – Manish Dec 16 '16 at 12:30
  • Step # 4: get shipping-methods. When performing a GET request as mentioned in magento 2 rest API docs(quoteShippingMethodManagementV1: /V1/carts/mine/shipping-methods) its giving {"message":"%fieldName is a required field.","parameters":{"fieldName":"cartId"}} as a response. There is not required parameter mentioned in documention. Please help!! – Abdul Moiz Jul 19 '17 at 19:06
  • Do i need to pass 'cartId' in place of 'mine' in the every URL?? – Abdul Moiz Jul 19 '17 at 19:33
  • And when i perform the last step, where we place order on /V1/carts/mine/order(/V1/carts/{cartId}/order, i replaced 'mine' with cartId otherwise it say cartId is a required field) it responds with '{"message":"Please enter a customer email."}' – Abdul Moiz Jul 19 '17 at 19:38
  • Please verify from the frontend site that customer cart is created before get shipping method call. – Manish Jul 20 '17 at 06:35
  • When I am adding billing addres then in response to shipping-methods it is giving error for Shipping address not set. – MOHD TAHIR Sep 29 '17 at 13:46
  • could you please share the code you used for all above operations. A BIG help – Ajith Mar 21 '18 at 05:33
  • I want to place order for Virtual products. I am getting error on Shipping Method. Can anyone assist ? – Ahsan Horani Mar 10 '20 at 07:14
2

Ok, I finally got it right.

  1. Save payment information and create order [POST] /rest/V1/carts/mine/payment-information
awavi
  • 837
  • 3
  • 11
  • 23
  • 3
    Can you provide more information about the payload here? For instance, how do you set the shipping address? – Martin Wickman Apr 18 '16 at 09:11
  • how to set shipping address to quote using api? – Sunil Patel May 06 '16 at 08:19
  • I believe there is a previous step (before 8.) but I have not tried it yet because I amy selling virtual products only. Please fix my answer when you do find it so it can help others. – awavi May 06 '16 at 10:33
  • yeah, there are two way to place order by rest api 1.[POST] /rest/V1/carts/mine/payment-information 2. [POST] /rest/V1/carts/mine/order – Manish Dec 16 '16 at 12:45
  • If I post that one, then I need to set the payment information previously? – awavi Dec 16 '16 at 14:00
  • Referring to point 7. you mentioned in your question, when i am performing a [GET] on /rest/V1/carts/mine/payment-information, so magento responds me with {"message":"%fieldName is a required field.","parameters":{"fieldName":"cartId"}}. Do i need to pass cartId in place of mine in the URL?? Please help!! – Abdul Moiz Jul 19 '17 at 19:19