0

RetrieveCustomerCustomAttributeDefinition

by
Published Oct 17, 2025

Retrieves a customer-related [custom attribute definition]($m/CustomAttributeDefinition) from a Square seller account. To retrieve a custom attribute definition created by another application, the `visibility` setting must be `VISIBILITY_READ_ONLY` or `VISIBILITY_READ_WRITE_VALUES`. Note that seller-defined custom attributes (also known as custom fields) are always set to `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
 * RetrieveCustomerCustomAttributeDefinition
7
 * Retrieves a customer-related [custom attribute definition]($m/CustomAttributeDefinition) from a Square seller account.
8

9
To retrieve a custom attribute definition created by another application, the `visibility`
10
setting must be `VISIBILITY_READ_ONLY` or `VISIBILITY_READ_WRITE_VALUES`. Note that seller-defined custom attributes
11
(also known as custom fields) are always set to `VISIBILITY_READ_WRITE_VALUES`.
12
 */
13
export async function main(
14
  auth: Square,
15
  key: string,
16
  version: string | undefined,
17
) {
18
  const url = new URL(
19
    `https://connect.squareup.com/v2/customers/custom-attribute-definitions/${key}`,
20
  );
21
  for (const [k, v] of [["version", version]]) {
22
    if (v !== undefined && v !== "" && k !== undefined) {
23
      url.searchParams.append(k, v);
24
    }
25
  }
26
  const response = await fetch(url, {
27
    method: "GET",
28
    headers: {
29
      Authorization: "Bearer " + auth.token,
30
    },
31
    body: undefined,
32
  });
33
  if (!response.ok) {
34
    const text = await response.text();
35
    throw new Error(`${response.status} ${text}`);
36
  }
37
  return await response.json();
38
}
39