0

Get 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.** Retrieve a single shipment by its ID and the ID of its parent order. > 🔑 Access with > > API key > > Access token with **shipments.read**

Script mollie Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Mollie = {
3
  token: string;
4
};
5
/**
6
 * Get 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
Retrieve a single shipment by its ID and the ID of its parent order.
10

11
> 🔑 Access with
12
>
13
> API key
14
>
15
> Access token with **shipments.read**
16
 */
17
export async function main(
18
  auth: Mollie,
19
  orderId: string,
20
  id: string,
21
  testmode: string | undefined,
22
) {
23
  const url = new URL(
24
    `https://api.mollie.com/v2/orders/${orderId}/shipments/${id}`,
25
  );
26
  for (const [k, v] of [["testmode", testmode]]) {
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.text();
43
}
44