0

Get payment link

by
Published Apr 8, 2025

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

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