24

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?

25

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": "abc@abc.com",
            "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": "abc@abc.com",
            "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"
    }
}'                      
6

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" 
    }
}
3
  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",
        "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": "880xxxx390"
    },
    "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

  • How to pass creditcard data using payflow method using above way? – Rakesh Jesadiya Aug 24 '17 at 7:15
  • @RakeshJesadiya, there is a Magento rest api call to get all available payment method fetch the list and place the order replacing the above method. – Manish Aug 24 '17 at 8:52
  • can you look up and let me know for this, magento.stackexchange.com/questions/188939/… – Rakesh Jesadiya Aug 24 '17 at 9:58
  • @paul have you created an order using REST API with PayPal Pro and Express???? – Ketan Panchal Aug 30 '18 at 4:13
  • @KetanPanchal No – Manish Aug 31 '18 at 4:02
0

There is an official tutorial showing how to make an order through REST API:
Order processing tutorial for Magento 2.2

They included very detailed steps:

  1. Configure the store
  2. Get the admin token
  3. Create a customer
  4. Create a quote
  5. Add items to the cart
  6. Prepare for checkout
  7. Create an order
  8. Create an invoice
  9. Create a shipment
  10. Issue a partial refund

The tutorial included how to add different kinds of products, different shipping method and many other useful information with sample codes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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