//native
type Square = {
token: string;
};
/**
* RetrieveInventoryCount
* Retrieves the current calculated stock count for a given
[CatalogObject]($m/CatalogObject) at a given set of
[Location]($m/Location)s. Responses are paginated and unsorted.
For more sophisticated queries, use a batch endpoint.
*/
export async function main(
auth: Square,
catalog_object_id: string,
location_ids: string | undefined,
cursor: string | undefined,
) {
const url = new URL(
`https://connect.squareup.com/v2/inventory/${catalog_object_id}`,
);
for (const [k, v] of [
["location_ids", location_ids],
["cursor", cursor],
]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
Authorization: "Bearer " + auth.token,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 235 days ago