I am using Google’s Apps Script to design a small internal app to track customer activity.
Part of what I’m needing to do is track customer orders with specific line items in a given time frame. In the API Explorer, I am able to do this easily with the given curl
curl https://connect.squareup.com/v2/orders/search \
-X POST \
-H 'Square-Version: 2023-08-16' \
-H 'Authorization: Bearer XXXXX' \
-H 'Content-Type: application/json' \
-d '{
"query": {
"filter": {
"date_time_filter": {
"closed_at": {
"end_at": "2023-09-20",
"start_at": "2023-08-01"
}
},
"state_filter": {
"states": [
"COMPLETED"
]
}
},
"sort": {
"sort_field": "CLOSED_AT",
"sort_order": "DESC"
}
},
"location_ids": [
"XXXXX"
]
}'
I set up my headers in Apps Script as follows:
{ method: 'post',
headers:
{ 'Square-Version': '2022-08-23',
Authorization: 'Bearer XXXXX',
Accept: 'application/json' },
muteHttpExceptions: true,
payload: '{"query":{"filter":{"date_time_filter":{"closed_at":{"end_at":"2023-09-20T16:39:31.415Z","start_at":1692463171416}},"state_filter":{"states":["COMPLETED"]}},"sort":{"sort_field":"CLOSED_AT","sort_order":"DESC"}},"location_ids":["XXXXX"]}' }
Using that request and payload, I get the following error:
Response content: {“errors”: [{“code”: “BAD_REQUEST”,“detail”: “Must provide at least 1 location_id.”,“field”: “location_ids”,“category”: “INVALID_REQUEST_ERROR”}]}
I have tried re-ordering the arguments in the payload, removing all arguments except “location_ids”, and everything I can think of to confirm spelling, capitalization, etc. without any success.
Is there another way to search orders or something I am missing in how I have structured my request?
As an additional note, I have confirmed that other API endpoints can be hit and respond correctly. So far, orders/search is the only one that doesn’t appear to work.