0

Update Thread

by
Published today

Open or close a conversation thread.

Script hubspot Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 4 hours ago
1
//native
2

3
/**
4
 * Update Thread
5
 * Open or close a conversation thread. Requires conversations.write.
6
 */
7
export async function main(
8
  auth: RT.Hubspot,
9
  thread_id: string,
10
  status: "OPEN" | "CLOSED"
11
) {
12
  const url = new URL(
13
    `https://api.hubapi.com/conversations/v3/conversations/threads/${thread_id}`
14
  )
15

16
  const body: { [key: string]: any } = {}
17
  body.status = status
18

19
  const response = await fetch(url, {
20
    method: "PATCH",
21
    headers: {
22
      Authorization: `Bearer ${auth.token}`,
23
      "Content-Type": "application/json",
24
      Accept: "application/json",
25
    },
26
    body: JSON.stringify(body),
27
  })
28

29
  if (!response.ok) {
30
    throw new Error(`${response.status} ${await response.text()}`)
31
  }
32

33
  return await response.json()
34
}
35