0

RetrieveInventoryChanges

by
Published Oct 17, 2025

Returns a set of physical counts and inventory adjustments for the provided [CatalogObject](entity:CatalogObject) at the requested [Location](entity:Location)s.

Script square Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Square = {
3
  token: string;
4
};
5
/**
6
 * RetrieveInventoryChanges
7
 * Returns a set of physical counts and inventory adjustments for the
8
provided [CatalogObject](entity:CatalogObject) at the requested
9
[Location](entity:Location)s.
10
 */
11
export async function main(
12
  auth: Square,
13
  catalog_object_id: string,
14
  location_ids: string | undefined,
15
  cursor: string | undefined,
16
) {
17
  const url = new URL(
18
    `https://connect.squareup.com/v2/inventory/${catalog_object_id}/changes`,
19
  );
20
  for (const [k, v] of [
21
    ["location_ids", location_ids],
22
    ["cursor", cursor],
23
  ]) {
24
    if (v !== undefined && v !== "" && k !== undefined) {
25
      url.searchParams.append(k, v);
26
    }
27
  }
28
  const response = await fetch(url, {
29
    method: "GET",
30
    headers: {
31
      Authorization: "Bearer " + auth.token,
32
    },
33
    body: undefined,
34
  });
35
  if (!response.ok) {
36
    const text = await response.text();
37
    throw new Error(`${response.status} ${text}`);
38
  }
39
  return await response.json();
40
}
41