0

BatchRetrieveInventoryChanges

by
Published Oct 17, 2025

Returns historical physical counts and adjustments based on the provided filter criteria. Results are paginated and sorted in ascending order according their `occurred_at` timestamp (oldest first). BatchRetrieveInventoryChanges is a catch-all query endpoint for queries that cannot be handled by other, simpler endpoints.

Script square Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Square = {
3
  token: string;
4
};
5
/**
6
 * BatchRetrieveInventoryChanges
7
 * Returns historical physical counts and adjustments based on the
8
provided filter criteria.
9

10
Results are paginated and sorted in ascending order according their
11
`occurred_at` timestamp (oldest first).
12

13
BatchRetrieveInventoryChanges is a catch-all query endpoint for queries
14
that cannot be handled by other, simpler endpoints.
15
 */
16
export async function main(
17
  auth: Square,
18
  body: {
19
    catalog_object_ids?: string[];
20
    location_ids?: string[];
21
    types?: "PHYSICAL_COUNT" | "ADJUSTMENT" | "TRANSFER"[];
22
    states?:
23
      | "CUSTOM"
24
      | "IN_STOCK"
25
      | "SOLD"
26
      | "RETURNED_BY_CUSTOMER"
27
      | "RESERVED_FOR_SALE"
28
      | "SOLD_ONLINE"
29
      | "ORDERED_FROM_VENDOR"
30
      | "RECEIVED_FROM_VENDOR"
31
      | "IN_TRANSIT_TO"
32
      | "NONE"
33
      | "WASTE"
34
      | "UNLINKED_RETURN"
35
      | "COMPOSED"
36
      | "DECOMPOSED"
37
      | "SUPPORTED_BY_NEWER_VERSION"
38
      | "IN_TRANSIT"[];
39
    updated_after?: string;
40
    updated_before?: string;
41
    cursor?: string;
42
    limit?: number;
43
  },
44
) {
45
  const url = new URL(
46
    `https://connect.squareup.com/v2/inventory/changes/batch-retrieve`,
47
  );
48

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