Magento 2 - Create order using REST API

I need to use the Magento REST API to create an order from a mobile client. In my case, mobile side will implement the payment directly using PayPal SDK. What I need to do is to create an order by setting the payment method to money order and perform a guest checkout. Which API(s) should I use to achieve this?

Solutions

I think there is a little mistake: For placing order, on the body, it has to be paymentMethod the first key, like this:

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

I finally figured it out. Here is what I'm doing.

Get a single product

curl -g -X GET "$base_url/index.php/rest/V1/products/24-MB05/" \
-H "Authorization: Bearer $token" 

Create cart

curl -g -X POST "$base_url/index.php/rest/V1/guest-carts/" \
-H "Authorization: Bearer $token" 

Get Cart

curl -g -X GET "$base_url/index.php/rest/V1/guest-carts/56241bf6bc084cd7589426c8754fc9c5" \
-H "Authorization: Bearer $token" 

Add Product To Cart

curl -g -X POST "$base_url/index.php/rest/V1/guest-carts/56241bf6bc084cd7589426c8754fc9c5/items" \
-H "Authorization: Bearer $token" \
-H "Content-Type:application/json" \
 -d '{ "cartItem": { "quote_id": "56241bf6bc084cd7589426c8754fc9c5", "sku": "24-MB05", "qty": 1 } }'

Add shipping information

curl -g -X POST "$base_url/index.php/rest/V1/guest-carts/56241bf6bc084cd7589426c8754fc9c5/shipping-information" \
    -H "Authorization: Bearer $token" \
    -H "Content-Type:application/json" \
     -d '
{
    "addressInformation": {
        "shippingAddress": {
            "region": "MH",
            "region_id": 0,
            "country_id": "IN",
            "street": [
                "Chakala,Kalyan (e)"
            ],
            "company": "abc",
            "telephone": "1111111",
            "postcode": "12223",
            "city": "Mumbai",
            "firstname": "Sameer",
            "lastname": "Sawant",
            "email": "[email protected]",
            "prefix": "address_",
            "region_code": "MH",
            "sameAsBilling": 1
        },
        "billingAddress": {
            "region": "MH",
            "region_id": 0,
            "country_id": "IN",
            "street": [
                "Chakala,Kalyan (e)"
            ],
            "company": "abc",
            "telephone": "1111111",
            "postcode": "12223",
            "city": "Mumbai",
            "firstname": "Sameer",
            "lastname": "Sawant",
            "email": "[email protected]",
            "prefix": "address_",
            "region_code": "MH"
        },
        "shipping_method_code": "flatrate",
        "shipping_carrier_code": "flatrate"
    }
}
 '

Get Payment Method

curl -g -X GET "$base_url/index.php/rest/V1/guest-carts/56241bf6bc084cd7589426c8754fc9c5/payment-information" \
    -H "Authorization: Bearer $token" 

Place Order

curl -g -X PUT "$base_url/index.php/rest/V1/guest-carts/56241bf6bc084cd7589426c8754fc9c5/order" \
    -H "Authorization: Bearer $token" \
    -H "Content-Type:application/json" \
     -d '
{
    "paymentMethod": {
        "method": "checkmo"
    }
}'                      
  1. create empty cart url : http://www.[yoursite].com/rest/V1/carts/mine call: post response: cartID eg: 4290

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

    {"cartItem":{
        "sku":"JFCO00017",
        "qty":1,
        "name":"Devil May Cry III 3 Dante",
        "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.[yoursite].com/rest/V1/carts/mine/billing-address body:

    {
    "address": {
    "city": "Springfield",
    "company": "iprag",
    "countryId": "IN",
    "email": "[email protected]",
    "firstname": "Jane",
    "lastname": "Doe",
    "postcode": "90210",
    "region": "UP",
    "saveInAddressBook": 1,
    "street": ["Street"],
    "telephone": "5551234"
    },
    "useForShipping": true
    }
    
  4. get shipping-methods url : http://www.[yoursite].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.[yoursite].com/rest/V1/carts/mine/shipping-information body:

    {
     "addressInformation": {
     "billingAddress": {
        "city": "Springfield",
        "company": "iprag",
        "email": "[email protected]",
        "firstname": "Jane",
        "lastname": "Doe",
        "postcode": "335001",
        "region": "UP",
        "street": ["Street"],
        "telephone": "5551234"
    },
    "shippingAddress": {
        "city": "Springfield",
        "company": "iprag",
        "email": "[email protected]",
        "firstname": "Jane",
        "lastname": "Doe",
        "postcode": "335001",
        "region": "UP",
        "street": ["Street"],
        "telephone": "5551234"
      },
      "shippingCarrierCode": "flatrate",
      "shippingMethodCode": "flatrate"
    }
    }
    

response: payment method and cart detail

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

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

response: orderid

Similar questions

Added product via REST API OAuth not retrieved and not able to update via REST API
After adding product to Magento run http://mymagentohost/api/rest/products/40 it will return Resource not found but if just open product from Magento and click on save (without changing anything) than (run http://mymagentohost/api/rest/products/40) it will return product in xml view. some code for saving product using REST OAuth as below Response I...
Rest Api - call custom rest api function
i am beginner in creating Rest api, i dont know from where to start. till now am able to pull products list using http://my_host.com/api/rest/products. but am confused what will my url for calling custom function
How to extend rest API request or check request from web or rest API?
I have created a module for checkout payment methods event. But I need to check request is getting from web or rest API. I mean something like: Please Help me
what is entity when create an order using REST api
I am trying to create order using REST API I have got an error message ordered: {"message":"%fieldName is a required field.","parameters":{"fieldName":"entity"}}" What is entity field in order of magento2?. Api.php place-order.php Can any one help me on this problem ? Any references or suggestions are highly appreciated. Thanks in advance.
How to change Order-Status with custom-order-status(Ready To Dispatch) using rest API in magento 2.1?
I have one custom order status(Ready To Dispatch).I want to change order-status of order using rest api.Please help me i don't know what api is used?
Magento 2 REST API: Create an API to fetch recently viewed products
I need to create an API for fetching all the recently viewed products. Any suggestions on how to do it?

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.