//native
/**
* Update Side Conversation
* Close or reopen a ticket's side conversation, and/or change its subject. Only the fields you fill are changed.
*/
export async function main(
auth: RT.Zendesk,
ticket_id: number,
side_conversation_id: string,
state: "open" | "closed" | undefined,
subject: string | undefined
) {
if (!state && !subject) {
throw new Error("Provide a state, a subject, or both")
}
const response = await fetch(
`https://${auth.subdomain}.zendesk.com/api/v2/tickets/${ticket_id}/side_conversations/${side_conversation_id}`,
{
method: "PUT",
headers: {
Authorization: auth.token
? `Bearer ${auth.token}`
: `Basic ${btoa(`${auth.username}:${auth.password}`)}`,
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify({
side_conversation: {
state: state || undefined,
subject: subject || undefined,
},
}),
}
)
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return await response.json()
}
Submitted by hugo989 2 hours ago