0

UpdateOrderCustomAttributeDefinition

by
Published Oct 17, 2025

Updates an order-related custom attribute definition for a Square seller account. Only the definition owner can update a custom attribute definition. Note that sellers can view all custom attributes in exported customer data, including those set to `VISIBILITY_HIDDEN`.

Script square Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Square = {
3
  token: string;
4
};
5
/**
6
 * UpdateOrderCustomAttributeDefinition
7
 * Updates an order-related custom attribute definition for a Square seller account.
8

9
Only the definition owner can update a custom attribute definition. Note that sellers can view all custom attributes in exported customer data, including those set to `VISIBILITY_HIDDEN`.
10
 */
11
export async function main(
12
  auth: Square,
13
  key: string,
14
  body: {
15
    custom_attribute_definition: {
16
      key?: string;
17
      schema?: {};
18
      name?: string;
19
      description?: string;
20
      visibility?:
21
        | "VISIBILITY_HIDDEN"
22
        | "VISIBILITY_READ_ONLY"
23
        | "VISIBILITY_READ_WRITE_VALUES";
24
      version?: number;
25
      updated_at?: string;
26
      created_at?: string;
27
    };
28
    idempotency_key?: string;
29
  },
30
) {
31
  const url = new URL(
32
    `https://connect.squareup.com/v2/orders/custom-attribute-definitions/${key}`,
33
  );
34

35
  const response = await fetch(url, {
36
    method: "PUT",
37
    headers: {
38
      "Content-Type": "application/json",
39
      Authorization: "Bearer " + auth.token,
40
    },
41
    body: JSON.stringify(body),
42
  });
43
  if (!response.ok) {
44
    const text = await response.text();
45
    throw new Error(`${response.status} ${text}`);
46
  }
47
  return await response.json();
48
}
49