I need to use the Magento REST API to create an order from a mobile client. In my case, the 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 a money order and performing a guest checkout. Which API(s) should I use to achieve this?
5 Answers 5
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"
}
}'
-
1I created a sample php script based on your answer here, if someone wants to try this via php: github.com/acolono/php-magento-api-sandboxNebel54– Nebel542017年02月28日 12:34:26 +00:00Commented Feb 28, 2017 at 12:34
-
1@zzpaul, How to pass creditcard data using payflow method using above way?Rakesh Jesadiya– Rakesh Jesadiya2017年08月24日 07:16:13 +00:00Commented Aug 24, 2017 at 7:16
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"
}
}
create empty cart url : http://www.[yoursite].com/rest/V1/carts/mine call: post response: cartID eg: 4290
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"}] } } } }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 }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}
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
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
-
How to pass creditcard data using payflow method using above way?Rakesh Jesadiya– Rakesh Jesadiya2017年08月24日 07:15:49 +00:00Commented Aug 24, 2017 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– Manish2017年08月24日 08:52:19 +00:00Commented Aug 24, 2017 at 8:52
-
can you look up and let me know for this, magento.stackexchange.com/questions/188939/…Rakesh Jesadiya– Rakesh Jesadiya2017年08月24日 09:58:19 +00:00Commented Aug 24, 2017 at 9:58
-
@paul have you created an order using REST API with PayPal Pro and Express????Ketan Panchal– Ketan Panchal2018年08月30日 04:13:20 +00:00Commented Aug 30, 2018 at 4:13
-
Complete Order Flow for Guest and LoggedIn Customer Using REST API
Guest
1. Create Empty Cart
End Point = http://magento.local/en-uae/rest/V1/guest-carts
Method = POST
Output = token(hFJ9dQO4nkyTwWJFoiAdk9Bp4SF9aJo7)
2. Get Cart ID By Token
End Point = http://magento.local/en-uae/rest/V1/guest-carts/(token)
Method = GET
Output = Cart Details
3.Add Item to Cart
End Point = http://magento.local/en-uae/rest/V1/guest-carts/(token)/items
Method = POST
Body = `{ "cartItem": {
"sku": "ABC1088",
"qty": 1,
"quote_id": "6261"
}
}`
Output = Added Product Details
4.Fetch Shipping Method Details
End Point = http://magento.local/en-uae/rest/V1/guest-carts/(token)/estimate-shipping-methods
Method = POST
Body = `{
"address": {
"region": "Dubai",
"country_id": "AE",
"street": [
"L-142, 5th Main Rd"
],
"postcode": "123456",
"city": "Goa",
"firstname": "First Name",
"lastname": "Last",
"customer_id": null,
"email": "[email protected]",
"telephone": "12345678",
"same_as_billing": 1
}
}`
OutPut = Added Shipping Methods
5. Fetch Available Payment Methods
End Point = http://magento.local/en-uae/rest/V1/guest-carts/(token)/shipping-information
Method = POST
Body = `{
"addressInformation": {
"shipping_address": {
"region": "Dubai",
"country_id": "AE",
"street": [
"L-142, 5th Main Rd"
],
"postcode": "12345",
"city": "Hsr Layout",
"firstname": "First Name",
"lastname": "Last",
"customer_id": null,
"email": "[email protected]",
"telephone": "12345678"
},
"billing_address": {
"region": "Dubai",
"country_id": "AE",
"street": [
"L-142, 5th Main Rd"
],
"postcode": "12345",
"city": "Goa",
"firstname": "First Name",
"lastname": "Last",
"customer_id": null,
"email": "[email protected]",
"telephone": "12345"
},
"shipping_carrier_code": "instore",
"shipping_method_code": "pickup"
}}`
Output = Available Payment Methods
6. Place Order
End Point = http://magento.local/en-uae/rest/V1/guest-carts/(token)/payment-information
Method = GET
Body = `{
"email": "[email protected]",
"paymentMethod": {
"method": "cashondelivery"
},
"billing_address": {
"email": "[email protected]",
"region": "Dubai",
"region_id": 612,
"region_code": "",
"country_id": "AE",
"street": [
"123 Dublin street"
],
"postcode": "1234",
"city": "Goa",
"telephone": "1234",
"firstname": "First Name",
"lastname": "Last"
}
}`
LoggedIn
1. Get Customer Token
End Point = http://magento.local/en-uae/rest/V1/integration/customer/token
Method = POST
Body = `{
"username":"[email protected]",
"password":"Test123@@"
}`
Output = Bearer Token
2. Get Cart Details
End Point = http://magento.local/en-uae/rest/V1/carts/mine
Method = GET
Output = cart details
3. Add Product to Cart
End Point = http://magento.local/en-uae/rest/V1/carts/mine/items
Method = POST
Header = Bearer Token = ( Pass token from step -1(logged-in))
Body = `{
"cartItem": {
"sku": "ABC1088",
"qty": 1,
"quote_id": "6255"
}
}`
Output = Added Product Details
4. Add Billing Address
End Point = http://magento.local/en-uae/rest/V1/carts/mine/billing-address
Method = POST
Header = Bearer Token = ( Pass token from step -1(logged-in)
Body = `{
"address": {
"city": "Hsr Layout",
"company": "Codilar",
"countryId": "AE",
"email": "[email protected]",
"firstname": "First",
"lastname": "Last",
"postcode": "1234",
"region": "Dubai",
"saveInAddressBook": 1,
"street": ["L-142, 5th Main Rd"],
"telephone": "12345"
},
"useForShipping": true
}`
Output = You will get added details
5. Get Shipping methods
End point = http://magento.local/en-uae/rest/V1/carts/mine/shipping-methods
Method = GET
Header = Bearer Token = ( Pass token from step -1(logged-in)
6. Get Shipping Information
End point = http://magento.local/en-uae/rest/V1/carts/mine/shipping-information
Method = POST
Header = Bearer Token = ( Pass token from step -1(logged-in))
Body = `{
"addressInformation": {
"shipping_address": {
"region": "Dubai",
"country_id": "AE",
"street": [
"L-142, 5th Main Rd"
],
"postcode": "560102",
"city": "Hsr Layout",
"firstname": "First Name",
"lastname": "Last",
"customer_id": null,
"email": "[email protected]",
"telephone": "1234567"
},
"billing_address": {
"region": "Dubai",
"country_id": "AE",
"street": [
"L-142, 5th Main Rd"
],
"postcode": "1234",
"city": "Goa",
"firstname": "First Name",
"lastname": "Das",
"customer_id": null,
"email": "[email protected]",
"telephone": "1234"
},
"shipping_carrier_code": "instore",
"shipping_method_code": "pickup"
}}`
7. Plae Order
End Point = http://magento.local/en-uae/rest/V1/carts/mine/order
Method = PUT
Header = Bearer Token = ( Pass token from step -1(logged-in)
Body = `{
"paymentMethod":{"method":"checkmo"},
"shippingMethod":
{
"method_code":"freeshipping",
"carrier_code":"freeshipping",
"additionalProperties":{},
"region_id":""
}}`
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:
- Configure the store
- Get the admin token
- Create a customer
- Create a quote
- Add items to the cart
- Prepare for checkout
- Create an order
- Create an invoice
- Create a shipment
- 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.
Explore related questions
See similar questions with these tags.