Yesterday I received my Barcode scanner, after a little playing scanning everything in sight I got to work on programming a Raspberry PI in Python to use the barcode scanner to update orders in WooCommerce.
I’m not going to go into full details in this post on how. but I will write it up soon.
A BIG problem I hit though was updating orders using the WooCommerce API. I kept getting error code 400 ‘No order data specified to edit order’. I’d followed the example but changed it to fit my code i.e dont print the output but return it for error checking.
Searching google for that exact phrase gave just 1 result, and it’s someone commenting they are getting the error with no response (and it’s 4 months old on a 2 year old post).
After looking through the API code and trying to follow along (I’m not the best programmer but I can generally follow what it’s trying). I found it looking for ‘order’
So after looking at how the bulk update is done and with a bit of playing I found that instead of
data = {'status': 'completed'}
you need
data = {"order":{"status":"completed"}}
Hey Presto it works. My specific code is now
def WooCommerceUpdateOrder(order, data): global wcapi putstring = "orders/%s" % order result = wcapi.put(putstring, data) return result
which is called using
data = { 'order': { "status": "completed" } } updateresult = WooCommerceUpdateOrder(order, data)
Hope this helps someone. I’ll post the full python program for the barcode reader later in the week. Basically it uses a PI, PI LCD Screen with 4 buttons, Barcode Reader, Speakers. 🙂
Thanks! Just ran into this problem and found your page by searching "No order data specified to edit order". Saved me a bunch of time. It's kind of a pain sometimes how the WC api responds with and expects the data bound to an attribute on the response objects.
Request used to work without this fix just fine. Good thing I found your post, bag of cookies for you! Thanks.
Wow, thanks! Here it is 2 years later, and the WooCommerce docs still haven't been fixed. Your blog post probably saved me hours of digging.
I'm really glad it's helped someone (a few people looking at the replies), it's that long ago I can't remember writing it 🙂
Thankyou soooo much…. this error had made me soo frustrated….. Thankyou works like a charm