0

BatchRetrieveInventoryCounts

by
Published Oct 17, 2025

Returns current counts for the provided [CatalogObject]($m/CatalogObject)s at the requested [Location]($m/Location)s. Results are paginated and sorted in descending order according to their `calculated_at` timestamp (newest first). When `updated_after` is specified, only counts that have changed since that time (based on the server timestamp for the most recent change) are returned. This allows clients to perform a "sync" operation, for example in response to receiving a Webhook notification.

Script square Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Square = {
3
  token: string;
4
};
5
/**
6
 * BatchRetrieveInventoryCounts
7
 * Returns current counts for the provided
8
[CatalogObject]($m/CatalogObject)s at the requested
9
[Location]($m/Location)s.
10

11
Results are paginated and sorted in descending order according to their
12
`calculated_at` timestamp (newest first).
13

14
When `updated_after` is specified, only counts that have changed since that
15
time (based on the server timestamp for the most recent change) are
16
returned. This allows clients to perform a "sync" operation, for example
17
in response to receiving a Webhook notification.
18
 */
19
export async function main(
20
  auth: Square,
21
  body: {
22
    catalog_object_ids?: string[];
23
    location_ids?: string[];
24
    updated_after?: string;
25
    cursor?: string;
26
    states?:
27
      | "CUSTOM"
28
      | "IN_STOCK"
29
      | "SOLD"
30
      | "RETURNED_BY_CUSTOMER"
31
      | "RESERVED_FOR_SALE"
32
      | "SOLD_ONLINE"
33
      | "ORDERED_FROM_VENDOR"
34
      | "RECEIVED_FROM_VENDOR"
35
      | "IN_TRANSIT_TO"
36
      | "NONE"
37
      | "WASTE"
38
      | "UNLINKED_RETURN"
39
      | "COMPOSED"
40
      | "DECOMPOSED"
41
      | "SUPPORTED_BY_NEWER_VERSION"
42
      | "IN_TRANSIT"[];
43
    limit?: number;
44
  },
45
) {
46
  const url = new URL(
47
    `https://connect.squareup.com/v2/inventory/counts/batch-retrieve`,
48
  );
49

50
  const response = await fetch(url, {
51
    method: "POST",
52
    headers: {
53
      "Content-Type": "application/json",
54
      Authorization: "Bearer " + auth.token,
55
    },
56
    body: JSON.stringify(body),
57
  });
58
  if (!response.ok) {
59
    const text = await response.text();
60
    throw new Error(`${response.status} ${text}`);
61
  }
62
  return await response.json();
63
}
64