0

Update draft forward

by
Published Oct 17, 2025

Updates a draft forward.

Script kustomer Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Kustomer = {
3
  apiKey: string;
4
};
5
/**
6
 * Update draft forward
7
 * Updates a draft forward.
8
 */
9
export async function main(
10
  auth: Kustomer,
11
  id: string,
12
  body: {
13
    status?: "draft" | "sent" | "failed";
14
    sendAt?: string;
15
    lang?: string;
16
    to?: { email: string; name?: string }[];
17
    from?: { email: string; name?: string };
18
    body?: string;
19
    subject?: string;
20
    replyTo?: string;
21
    template?: string;
22
    payload?: {};
23
    attachments?: {
24
      id: string;
25
      name: string;
26
      contentType: string;
27
      contentLength: number;
28
    }[];
29
  },
30
) {
31
  const url = new URL(`https://api.kustomerapp.com/v1/forwards/${id}`);
32

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