I’m new to the Magento 2 REST API (this is also my first post in this forum, hi all), but during the past day have been able to retrieve information using it to my backend system. GET -requests are easy enough, but I’m struggling with getting a correct PUT request together.
What I need to do next is to update the order status from pending to processing, but just cannot figure out how to create a proper array to encode. I’ve endlessly Googled this up to the point where I’ve all but given up. There are a million examples on how to retrieve information from Magento, but pretty much NOTHING on how to make updates.
Here’s my code:
(authentication part omitted – that works great)
$ icrement_id = "000000003"; $ requestUrl='http://www.example.com/rest/V1/orders?searchCriteria[filter_groups][filters][field]=increment_id&searchCriteria[filter_groups][filters][value]='.$ increment_id; $ ch = curl_init($ requestUrl); // Set status to processing $ data_json = [ "items"=> [ "state"=> "processing" ] ]; $ data_json = json_encode($ data); print '<br>JSON data: '.$ data_json; curl_setopt($ ch, CURLOPT_URL, $ url); curl_setopt($ ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', $ headers, 'Content-Length: ' . strlen($ data_json))); curl_setopt($ ch, CURLOPT_CUSTOMREQUEST, 'PUT'); curl_setopt($ ch, CURLOPT_POSTFIELDS,$ data_json); curl_setopt($ ch, CURLOPT_RETURNTRANSFER, true); $ response = curl_exec($ ch); curl_close($ ch); // Execute the query $ result = curl_exec($ ch); // Decode the result $ result= json_decode($ result); print_r($ result);
1. How to formulate $ data, so that it would be correct (items -> status from pending to processing)
2. Is my PUT request correct otherwise? (f.ex. can I use a search as the requestURL)
So just to be crystal clear, I’m not trying to create a new order, but change an existing order. Examples that would give a ‘for dummies’ example of a REST API PUT -request would be appreciated also. Thanks.
✓ Extra quality
ExtraProxies brings the best proxy quality for you with our private and reliable proxies
✓ Extra anonymity
Top level of anonymity and 100% safe proxies – this is what you get with every proxy package
✓ Extra speed
1,ooo mb/s proxy servers speed – we are way better than others – just enjoy our proxies!
USA proxy location
We offer premium quality USA private proxies – the most essential proxies you can ever want from USA
Our proxies have TOP level of anonymity + Elite quality, so you are always safe and secure with your proxies
Use your proxies as much as you want – we have no limits for data transfer and bandwidth, unlimited usage!
Superb fast proxy servers with 1,000 mb/s speed – sit back and enjoy your lightning fast private proxies!
99,9% servers uptime
Alive and working proxies all the time – we are taking care of our servers so you can use them without any problems
No usage restrictions
You have freedom to use your proxies with every software, browser or website you want without restrictions
Perfect for SEO
We are 100% friendly with all SEO tasks as well as internet marketing – feel the power with our proxies
Buy more proxies and get better price – we offer various proxy packages with great deals and discounts
We are working 24/7 to bring the best proxy experience for you – we are glad to help and assist you!