0

Get order

by
Published Apr 8, 2025

**⚠️ We no longer recommend implementing the Orders API. Please refer to the Payments API instead. We are actively working on adding support for Klarna, Billie, in3 and Vouchers to the Payments API later this year.** Retrieve a single order object by its ID. > 🔑 Access with > > API key > > Access token with **orders.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 order
7
 * **⚠️ We no longer recommend implementing the Orders API. Please refer to the Payments API instead. We are actively working on adding support for Klarna, Billie, in3 and Vouchers to the Payments API later this year.**
8

9
Retrieve a single order object by its ID.
10

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