4

I have built a php application which prints shipping labels for orders placed in a magento store - I use the REST API to query for order and customer data.

What is the correct technique to query the Magento store for the set of newest orders only?

So far I have simply been querying for order ids that are greater than the maximum order id that I already have but I think there must be a better way.

3

You should be able to sort the order results by adding a query string to the request URL containing the order field and the order direction. The field would be "created_at" and the direction "DESC" to get the newest orders first.

The URL would then be: http://magentohost/api/rest/orders?order=created_at&dir=DESC

You should be able to set the amount of results with the query param limit (default 10, maximum 100). Then you could try to find new orders until you reach one you already have processed.

  • 1
    Ok this is a couple of years old but I don't get how this is an accepted answer, the OPs method results in less data coming back and a less complicated script.... Am I missing something? – Charleh Nov 4 '17 at 13:37
  • Yes, it is a few years later, maybe I missed that point. I don't think you can ever do this without recording orders that you have processed by ID. You need some starting point/ending point. Actually both methods are evenly complex. The OP probably already has the best solution, with the difference to my solution that he is querying a field that is indexed in the db (row ID, created_at probably isn't). – 7ochem Nov 6 '17 at 10:14
  • Fair enough! I was thinking that storing the last order ID was the most straightforward thing - I actually found this because I'm about to query a Magneto API myself and I wondered if there was any way of "marking" the seen orders. I was wondering if it's possible to add a custom field to the sales order entity and update it - but I'm not sure if that requires bespoke to the instance. Worst case I'll just take the latest order no. – Charleh Nov 6 '17 at 13:06

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.