0

List shipments

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 list of all shipments created for a specific order. The results are paginated. > 🔑 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
 * List shipments
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 list of all shipments created for a specific order.
10

11
The results are paginated.
12

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