Order API call to match frontend search

So in the orders UI, when I select Active orders, I see a screen like this:

I’m writing up a little script that grabs these orders and processes them into an excel sheet. I’m trying to replicate the frontend function in the Order API by using the Search Orders call, however, it doesn’t appear there is an easy way to do that with the parameters available.

The closest call I can make is:
curl https://connect.squareup.com/v2/orders/search
-X POST
-H ‘Square-Version: 2020-12-16’
-H ‘Authorization: Bearer REDACTED’
-H ‘Content-Type: application/json’
-d ‘{
“location_ids”: [
“ALocationIDHere”
],
“query”: {
“filter”: {
“state_filter”: {
“states”: [
“OPEN”
]
},
“fulfillment_filter”: {}
}
}
}’

This of course, returns a lot more than the six entries seen here, as apparently the Open state covers a lot more than just these.

I did notice in the URL on the frontend that for “Active” passing in an orderGroup of 1 returns the expected results, but there doesn’t seem to be a way to do this in the API.

How is the status being filtered on, (not the state) and is there an API call that matches the frontend? I’ve gone through the Order documentation, but it’s a little unclear to me.

Hi @ajyong, welcome to the forums!

You would want to use the fulfillment_filter instead; currently you’re searching for all open orders, not open fulfillments. If an order is open without fulfillments, it won’t show up in your dashboard.

The fulfillment_filter has fulfillment_states array of strings, that you can pass in several values. I think for “Active” you would want to search for “PROPOSED”, “RESERVED”, and “PREPARED”.

1 Like

Hey there, sorry for the slow reply. So I updated the call to be this:

curl https://connect.squareup.com/v2/orders/search
-X POST
-H ‘Square-Version: 2020-12-16’
-H ‘Authorization: Bearer REDACTED’
-H ‘Content-Type: application/json’
-d ‘{
“location_ids”: [
“LocationID”
],
“query”: {
“filter”: {
“state_filter”: {
“states”: [
“OPEN”
]
},
“fulfillment_filter”: {
“fulfillment_states”: [
“PROPOSED”,
“RESERVED”,
“PREPARED”
]
}
}
}
}’

At the time of writing, I have only two open orders. I get those orders back in the call, along with 19 other orders as well.

What am I doing wrong?

Can you share your Square application id and the location_id in question?

sq0idp-bO3-yHLhAiR8QFLYeCAU-g application_id
R91B6AW863ZKJ location_id

Ah, shoot sorry, I missed an important piece here. In order for the order to show up on your dashboard, it must also be paid for, which this query doesn’t search for. There’s no way to query for paid orders explicitly, unfortunately, so after doing the above query, you would need to also narrow it down further by checking to see if there’s any tenders associated, and if so, is it equal to the full amount of the order (completely paid for). If there’s no tenders, then you can rule it out, as those won’t show up on the dashboard.