//native
/**
* Set Custom Ticket Fields
* Set one or more custom field values on a ticket, e.g. `[{ "id": 360001234, "value": "gold" }]`. Field ids come from List Ticket Fields; dropdown fields take the option's `value` tag, multi-select fields an array of tags, date fields `YYYY-MM-DD`.
*/
export async function main(
auth: RT.Zendesk,
ticket_id: number,
custom_fields: { id: number; value: any }[]
) {
const response = await fetch(
`https://${auth.subdomain}.zendesk.com/api/v2/tickets/${ticket_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({ ticket: { custom_fields } }),
}
)
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return await response.json()
}
Submitted by hugo989 2 hours ago