Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Extending REST API For Multi Order Updates
 
makeitdigital
Jr. Member
 
Avatar
Total Posts:  10
Joined:  2010-10-06
 

Hi,

I have been doing some work on the REST API so that I can batch update order status for many orders at once with data from an ERP.

I found something interesting so figured I’d post it here.

It all went pretty well, extending the API was not a problem but then I hit a strange problem, my orders were being updated fine in Magento and the correct success response was being sent but an exception was being thrown by the Oauth client.

This was the message:
Invalid auth/bad request (got a 207, expected HTTP/1.1 20X or a redirect)

I was using PUT method and updating multiple items so the correct status code to return was:
Mage_Api2_Model_Server::HTTP_MULTI_STATUS

That boils down to an HTTP status code of 207

So I downloaded the Oathsource from the pecl site and found this:
} else if (http_response_code < 200 || http_response_code > 206) {
spprintf(&bufz;, 0, “Invalid auth/bad request (got a &#xld;, expected HTTP/1.1 20X or a redirect)”, http_response_code);

So we have a bit of a problem because the Oauth library expects a success status code to be in the range 200-206 and doesn’t yet recognise 207 as a valid Multi-Status response code.

So the easiest resolution was to add in an extra OAuthException handler, check for code 207, in which case handle it neatly, or else fall back to your default excpetion handling.

I hope that helps someone!

Thanks

Graham

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top