0

ListLocationCustomAttributeDefinitions

by
Published Oct 17, 2025

Lists the location-related [custom attribute definitions]($m/CustomAttributeDefinition) that belong to a Square seller account. When all response pages are retrieved, the results include all custom attribute definitions that are visible to the requesting application, including those that are created 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
 * ListLocationCustomAttributeDefinitions
7
 * Lists the location-related [custom attribute definitions]($m/CustomAttributeDefinition) that belong to a Square seller account.
8
When all response pages are retrieved, the results include all custom attribute definitions
9
that are visible to the requesting application, including those that are created by other
10
applications and set to `VISIBILITY_READ_ONLY` or `VISIBILITY_READ_WRITE_VALUES`.
11
 */
12
export async function main(
13
  auth: Square,
14
  visibility_filter: "ALL" | "READ" | "READ_WRITE" | undefined,
15
  limit: string | undefined,
16
  cursor: string | undefined,
17
) {
18
  const url = new URL(
19
    `https://connect.squareup.com/v2/locations/custom-attribute-definitions`,
20
  );
21
  for (const [k, v] of [
22
    ["visibility_filter", visibility_filter],
23
    ["limit", limit],
24
    ["cursor", cursor],
25
  ]) {
26
    if (v !== undefined && v !== "" && k !== undefined) {
27
      url.searchParams.append(k, v);
28
    }
29
  }
30
  const response = await fetch(url, {
31
    method: "GET",
32
    headers: {
33
      Authorization: "Bearer " + auth.token,
34
    },
35
    body: undefined,
36
  });
37
  if (!response.ok) {
38
    const text = await response.text();
39
    throw new Error(`${response.status} ${text}`);
40
  }
41
  return await response.json();
42
}
43