I'm sending a request to the Square API via Node using the ordersApi.searchOrders
method, like so:
const customerOrders = await ordersApi.searchOrders({location_ids: ["MY_LOCATION_ID"]});
--Additional arguments/filters follow, but it isn't reaching those because of the location_id issue
According to the documentation, the method/endpoint is looking for the body to be an object, with a key of "location_ids" which corresponds to an array of strings of location Ids, of which I only have one.
I have tried at least a dozen times with different ways of retrieving and passing the location Id, but keep getting a 400 error of "Must provide at least 1 location_id".
I've tried passing ONLY the location Id in the body object, only the Id in an array, the location_ids key with just the Id as a string (no array), hard-coding in the Id, retrieving and passing the Id programatically, and still nothing.
Everything is required and ordered properly, or I wouldn't even be making it to this point. Any ideas? This project is set to save the small business I work for hundreds of dollars a week in employee time spent manually adding loyalty points for transactions through a third party that don't trigger the loyalty API for whatever reason (calling you out, Squarespace/Acuity)
UPDATE: I found the correct formatting in the API docs, I just had to select the correct SDK I was using at the top right of the example POST content--which would be Node.js versus the default cURL: https://developer.squareup.com/reference/square/orders-api/search-orders
I played around with the format of the object, turning it into a JSON-like string: {"'location_ids': ['MY_LOCATION_ID']"}
and received a different error that I had passed in a string (no surprise) and then there was a property of "Expected type: 'Object<{locationIds,cursor,query,limit,returnEntries}>'" that clued me in to the fact that the key should be "locationIds" without the underscore.
This is not recorded anywhere in the comments within the Square NPM package "ordersApi.js" file, instead it tells you to "See the corresponding object definition for field details" and I took that to mean the documentation page for the API endpoint, but apparently that definition is somewhere else. No idea where though.