0

ListOrderCustomAttributes

by
Published Oct 17, 2025

Lists the [custom attributes]($m/CustomAttribute) associated with an order. You can use the `with_definitions` query parameter to also retrieve custom attribute definitions in the same call. When all response pages are retrieved, the results include all custom attributes that are visible to the requesting application, including those that are owned by other applications and set to `VISIBILITY_READ_ONLY` or `VISIBILITY_READ_WRITE_VALUES`.

Script square Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Square = {
3
  token: string;
4
};
5
/**
6
 * ListOrderCustomAttributes
7
 * Lists the [custom attributes]($m/CustomAttribute) associated with an order.
8

9
You can use the `with_definitions` query parameter to also retrieve custom attribute definitions
10
in the same call.
11

12
When all response pages are retrieved, the results include all custom attributes that are
13
visible to the requesting application, including those that are owned by other applications
14
and set to `VISIBILITY_READ_ONLY` or `VISIBILITY_READ_WRITE_VALUES`.
15
 */
16
export async function main(
17
  auth: Square,
18
  order_id: string,
19
  visibility_filter: "ALL" | "READ" | "READ_WRITE" | undefined,
20
  cursor: string | undefined,
21
  limit: string | undefined,
22
  with_definitions: string | undefined,
23
) {
24
  const url = new URL(
25
    `https://connect.squareup.com/v2/orders/${order_id}/custom-attributes`,
26
  );
27
  for (const [k, v] of [
28
    ["visibility_filter", visibility_filter],
29
    ["cursor", cursor],
30
    ["limit", limit],
31
    ["with_definitions", with_definitions],
32
  ]) {
33
    if (v !== undefined && v !== "" && k !== undefined) {
34
      url.searchParams.append(k, v);
35
    }
36
  }
37
  const response = await fetch(url, {
38
    method: "GET",
39
    headers: {
40
      Authorization: "Bearer " + auth.token,
41
    },
42
    body: undefined,
43
  });
44
  if (!response.ok) {
45
    const text = await response.text();
46
    throw new Error(`${response.status} ${text}`);
47
  }
48
  return await response.json();
49
}
50