0

Update shipment

by
Published Apr 8, 2025

**⚠️ We no longer recommend implementing the Shipments API. Please refer to the Captures API instead. We are actively working on adding support for line-specific captures to the Captures API.** Update the tracking information on a shipment. For an in-depth explanation of each parameter, refer to the [Create shipment](create-shipment) endpoint. > 🔑 Access with > > API key > > Access token with **shipments.write**

Script mollie Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Mollie = {
3
  token: string;
4
};
5
/**
6
 * Update shipment
7
 * **⚠️ We no longer recommend implementing the Shipments API. Please refer to the Captures API instead. We are actively working on adding support for line-specific captures to the Captures API.**
8

9
Update the tracking information on a shipment.
10

11
For an in-depth explanation of each parameter, refer to the [Create shipment](create-shipment) endpoint.
12

13
> 🔑 Access with
14
>
15
> API key
16
>
17
> Access token with **shipments.write**
18
 */
19
export async function main(
20
  auth: Mollie,
21
  orderId: string,
22
  id: string,
23
  testmode: string | undefined,
24
  body: { tracking?: { carrier?: string; code?: string; url?: string } },
25
) {
26
  const url = new URL(
27
    `https://api.mollie.com/v2/orders/${orderId}/shipments/${id}`,
28
  );
29
  for (const [k, v] of [["testmode", testmode]]) {
30
    if (v !== undefined && v !== "" && k !== undefined) {
31
      url.searchParams.append(k, v);
32
    }
33
  }
34
  const response = await fetch(url, {
35
    method: "PATCH",
36
    headers: {
37
      "Content-Type": "application/json",
38
      Authorization: "Bearer " + auth.token,
39
    },
40
    body: JSON.stringify(body),
41
  });
42
  if (!response.ok) {
43
    const text = await response.text();
44
    throw new Error(`${response.status} ${text}`);
45
  }
46
  return await response.text();
47
}
48