0

RetrieveMerchantCustomAttribute

by
Published Oct 17, 2025

Retrieves a [custom attribute]($m/CustomAttribute) associated with a merchant. You can use the `with_definition` query parameter to also retrieve the custom attribute definition in the same call. To retrieve a custom attribute owned by another application, the `visibility` setting must be `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
 * RetrieveMerchantCustomAttribute
7
 * Retrieves a [custom attribute]($m/CustomAttribute) associated with a merchant.
8
You can use the `with_definition` query parameter to also retrieve the custom attribute definition
9
in the same call.
10
To retrieve a custom attribute owned by another application, the `visibility` setting must be
11
`VISIBILITY_READ_ONLY` or `VISIBILITY_READ_WRITE_VALUES`.
12
 */
13
export async function main(
14
  auth: Square,
15
  merchant_id: string,
16
  key: string,
17
  with_definition: string | undefined,
18
  version: string | undefined,
19
) {
20
  const url = new URL(
21
    `https://connect.squareup.com/v2/merchants/${merchant_id}/custom-attributes/${key}`,
22
  );
23
  for (const [k, v] of [
24
    ["with_definition", with_definition],
25
    ["version", version],
26
  ]) {
27
    if (v !== undefined && v !== "" && k !== undefined) {
28
      url.searchParams.append(k, v);
29
    }
30
  }
31
  const response = await fetch(url, {
32
    method: "GET",
33
    headers: {
34
      Authorization: "Bearer " + auth.token,
35
    },
36
    body: undefined,
37
  });
38
  if (!response.ok) {
39
    const text = await response.text();
40
    throw new Error(`${response.status} ${text}`);
41
  }
42
  return await response.json();
43
}
44