//native
export type DynSelect_view_id = string
// Resolver: the agent's active views (first 100).
export async function view_id(auth: RT.Zendesk) {
const response = await fetch(
`https://${auth.subdomain}.zendesk.com/api/v2/views?active=true&page[size]=100`,
{
headers: {
Authorization: auth.token
? `Bearer ${auth.token}`
: `Basic ${btoa(`${auth.username}:${auth.password}`)}`,
Accept: "application/json",
},
}
)
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
const { views } = await response.json()
return views.map((v: { id: number; title: string }) => ({
value: String(v.id),
label: v.title,
}))
}
/**
* List View Tickets
* List the tickets in a view, in the view's own order. Cursor-paged: pass `meta.after_cursor` as `cursor` while `meta.has_more` is true.
*/
export async function main(
auth: RT.Zendesk,
view_id: DynSelect_view_id,
page_size: number | undefined,
cursor: string | undefined
) {
const url = new URL(
`https://${auth.subdomain}.zendesk.com/api/v2/views/${view_id}/tickets`
)
url.searchParams.append("page[size]", String(page_size || 100))
if (cursor) {
url.searchParams.append("page[after]", cursor)
}
const response = await fetch(url, {
headers: {
Authorization: auth.token
? `Bearer ${auth.token}`
: `Basic ${btoa(`${auth.username}:${auth.password}`)}`,
Accept: "application/json",
},
})
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return await response.json()
}
Submitted by hugo989 2 hours ago