0

RetrieveCatalogObject

by
Published Oct 17, 2025

Returns a single [CatalogItem]($m/CatalogItem) as a [CatalogObject]($m/CatalogObject) based on the provided ID. The returned object includes all of the relevant [CatalogItem]($m/CatalogItem) information including: [CatalogItemVariation]($m/CatalogItemVariation) children, references to its [CatalogModifierList]($m/CatalogModifierList) objects, and the ids of any [CatalogTax]($m/CatalogTax) objects that apply to it.

Script square Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Square = {
3
  token: string;
4
};
5
/**
6
 * RetrieveCatalogObject
7
 * Returns a single [CatalogItem]($m/CatalogItem) as a
8
[CatalogObject]($m/CatalogObject) based on the provided ID. The returned
9
object includes all of the relevant [CatalogItem]($m/CatalogItem)
10
information including: [CatalogItemVariation]($m/CatalogItemVariation)
11
children, references to its
12
[CatalogModifierList]($m/CatalogModifierList) objects, and the ids of
13
any [CatalogTax]($m/CatalogTax) objects that apply to it.
14
 */
15
export async function main(
16
  auth: Square,
17
  object_id: string,
18
  include_related_objects: string | undefined,
19
  catalog_version: string | undefined,
20
  include_category_path_to_root: string | undefined,
21
) {
22
  const url = new URL(
23
    `https://connect.squareup.com/v2/catalog/object/${object_id}`,
24
  );
25
  for (const [k, v] of [
26
    ["include_related_objects", include_related_objects],
27
    ["catalog_version", catalog_version],
28
    ["include_category_path_to_root", include_category_path_to_root],
29
  ]) {
30
    if (v !== undefined && v !== "" && k !== undefined) {
31
      url.searchParams.append(k, v);
32
    }
33
  }
34
  const response = await fetch(url, {
35
    method: "GET",
36
    headers: {
37
      Authorization: "Bearer " + auth.token,
38
    },
39
    body: undefined,
40
  });
41
  if (!response.ok) {
42
    const text = await response.text();
43
    throw new Error(`${response.status} ${text}`);
44
  }
45
  return await response.json();
46
}
47