0

V1UpdateOrder

by
Published Oct 17, 2025

Updates the details of an online store order. Every update you perform on an order corresponds to one of three actions:

Script square Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Square = {
3
  token: string;
4
};
5
/**
6
 * V1UpdateOrder
7
 * Updates the details of an online store order. Every update you perform on an order corresponds to one of three actions:
8
 */
9
export async function main(
10
  auth: Square,
11
  location_id: string,
12
  order_id: string,
13
  body: {
14
    action: "COMPLETE" | "CANCEL" | "REFUND";
15
    shipped_tracking_number?: string;
16
    completed_note?: string;
17
    refunded_note?: string;
18
    canceled_note?: string;
19
  },
20
) {
21
  const url = new URL(
22
    `https://connect.squareup.com/v1/${location_id}/orders/${order_id}`,
23
  );
24

25
  const response = await fetch(url, {
26
    method: "PUT",
27
    headers: {
28
      "Content-Type": "application/json",
29
      Authorization: "Bearer " + auth.token,
30
    },
31
    body: JSON.stringify(body),
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