0

UpdateMerchantCustomAttributeDefinition

by
Published Oct 17, 2025

Updates a merchant-related [custom attribute definition]($m/CustomAttributeDefinition) for a Square seller account. Use this endpoint to update the following fields: `name`, `description`, `visibility`, or the `schema` for a `Selection` data type. Only the definition owner can update a custom attribute definition.

Script square Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Square = {
3
  token: string;
4
};
5
/**
6
 * UpdateMerchantCustomAttributeDefinition
7
 * Updates a merchant-related [custom attribute definition]($m/CustomAttributeDefinition) for a Square seller account.
8
Use this endpoint to update the following fields: `name`, `description`, `visibility`, or the
9
`schema` for a `Selection` data type.
10
Only the definition owner can update a custom attribute definition.
11
 */
12
export async function main(
13
  auth: Square,
14
  key: string,
15
  body: {
16
    custom_attribute_definition: {
17
      key?: string;
18
      schema?: {};
19
      name?: string;
20
      description?: string;
21
      visibility?:
22
        | "VISIBILITY_HIDDEN"
23
        | "VISIBILITY_READ_ONLY"
24
        | "VISIBILITY_READ_WRITE_VALUES";
25
      version?: number;
26
      updated_at?: string;
27
      created_at?: string;
28
    };
29
    idempotency_key?: string;
30
  },
31
) {
32
  const url = new URL(
33
    `https://connect.squareup.com/v2/merchants/custom-attribute-definitions/${key}`,
34
  );
35

36
  const response = await fetch(url, {
37
    method: "PUT",
38
    headers: {
39
      "Content-Type": "application/json",
40
      Authorization: "Bearer " + auth.token,
41
    },
42
    body: JSON.stringify(body),
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