1 | |
2 | type Intercom = { |
3 | apiVersion: string |
4 | token: string |
5 | } |
6 | |
7 | * Update a ticket |
8 | * You can update a ticket. |
9 | */ |
10 | export async function main( |
11 | auth: Intercom, |
12 | id: string, |
13 | body: { |
14 | ticket_attributes?: {} |
15 | state?: 'in_progress' | 'waiting_on_customer' | 'resolved' |
16 | open?: false | true |
17 | is_shared?: false | true |
18 | snoozed_until?: number |
19 | assignment?: { admin_id?: string; assignee_id?: string } |
20 | } |
21 | ) { |
22 | const url = new URL(`https://api.intercom.io/tickets/${id}`) |
23 |
|
24 | const response = await fetch(url, { |
25 | method: 'PUT', |
26 | headers: { |
27 | 'Intercom-Version': auth.apiVersion, |
28 | 'Content-Type': 'application/json', |
29 | Authorization: 'Bearer ' + auth.token |
30 | }, |
31 | body: JSON.stringify(body) |
32 | }) |
33 | if (!response.ok) { |
34 | const text = await response.text() |
35 | throw new Error(`${response.status} ${text}`) |
36 | } |
37 | return await response.json() |
38 | } |
39 |
|