0

Get terminal

by
Published Apr 8, 2025

Retrieve a single terminal by its ID. > 🔑 Access with > > API key > > Access token with **terminals.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 terminal
7
 * Retrieve a single terminal by its ID.
8

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