Create secure email to send card number
One script reply has been approved by the moderators Verified

Creates a secure email to send card number, CVV, and expiration date of a card by ID to the specified email.

This endpoint is currently gated. If you would like to request access, please reach out to [email protected]

Created by hugo697 170 days ago
Submitted by hugo697 Bun
Verified 170 days ago
1
//native
2
type Brex = {
3
  token: string;
4
};
5
/**
6
 * 
7
Create secure email to send card number 
8

9
 * 
10
Creates a secure email to send card number, CVV, and expiration date of a card by ID to the specified email.
11

12
This endpoint is currently gated. If you would like to request access, please reach out to
13
developer-support@brex.com
14

15
 */
16
export async function main(
17
  auth: Brex,
18
  id: string,
19
  Idempotency_Key: string,
20
  body: {
21
    recipient_email?: string;
22
    sender_name?: string;
23
    message?: string;
24
    expiry_days?: number;
25
  },
26
) {
27
  const url = new URL(
28
    `https://platform.brexapis.com/v2/cards/${id}/secure_email`,
29
  );
30

31
  const response = await fetch(url, {
32
    method: "POST",
33
    headers: {
34
      "Idempotency-Key": Idempotency_Key,
35
      "Content-Type": "application/json",
36
      Authorization: "Bearer " + auth.token,
37
    },
38
    body: JSON.stringify(body),
39
  });
40
  if (!response.ok) {
41
    const text = await response.text();
42
    throw new Error(`${response.status} ${text}`);
43
  }
44
  return await response.text();
45
}
46