0

Create forward by conversation

by
Published Oct 17, 2025

Creates a forward to send through email. Forwards will send all messages in a conversation. ### NOTE > To schedule the forward for delivery, create a forward with a `sendAt` property. Any one of the following roles is required for this endpoint: |Legacy Role|Equivalent Permission Set Role| |-----|--------| |org.user.conversation_forward.write|org.permission.conversation_forward.create|

Script kustomer Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Kustomer = {
3
  apiKey: string;
4
};
5
/**
6
 * Create forward by conversation
7
 * Creates a forward to send through email. Forwards will send all messages in a conversation.
8

9
### NOTE
10
> To schedule the forward for delivery, create a forward with a `sendAt` property.
11

12
Any one of the following roles is required for this endpoint:
13

14
|Legacy Role|Equivalent Permission Set Role|
15
|-----|--------|
16
|org.user.conversation_forward.write|org.permission.conversation_forward.create|
17

18
 */
19
export async function main(
20
  auth: Kustomer,
21
  id: string,
22
  body: {
23
    channel: "email";
24
    app?: "gmail" | "postmark";
25
    customer?: string;
26
    status?: "draft" | "sent" | "failed";
27
    sendAt?: string;
28
    to?: { email: string; name?: string }[];
29
    from?: { email: string; name?: string };
30
    body?: string;
31
    subject?: string;
32
    replyTo?: string;
33
    template?: string;
34
    payload?: {};
35
    attachments?: {
36
      id: string;
37
      name: string;
38
      contentType: string;
39
      contentLength: number;
40
    }[];
41
  },
42
) {
43
  const url = new URL(
44
    `https://api.kustomerapp.com/v1/conversations/${id}/forwards`,
45
  );
46

47
  const response = await fetch(url, {
48
    method: "POST",
49
    headers: {
50
      "Content-Type": "application/json",
51
      Authorization: "Bearer " + auth.apiKey,
52
    },
53
    body: JSON.stringify(body),
54
  });
55
  if (!response.ok) {
56
    const text = await response.text();
57
    throw new Error(`${response.status} ${text}`);
58
  }
59
  return await response.json();
60
}
61