//native
function authHeader(auth: RT.Servicenow) {
return auth.token
? `Bearer ${auth.token}`
: `Basic ${btoa(`${auth.username}:${auth.password}`)}`
}
/**
* List Attachments
* List attachment metadata (sys_id, file_name, content_type, size, download_link). Filter with an encoded query, e.g. table_name=incident^table_sys_id=<record sys_id>.
*/
export async function main(
auth: RT.Servicenow,
query: string | undefined,
limit: number | undefined
) {
const url = new URL(`${auth.instance_url}/api/now/attachment`)
if (query !== undefined && query !== "") {
url.searchParams.append("sysparm_query", query)
}
url.searchParams.append("sysparm_limit", String(limit ?? 100))
const response = await fetch(url, {
method: "GET",
headers: {
Authorization: authHeader(auth),
Accept: "application/json",
},
})
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return await response.json()
}
Submitted by hugo989 5 days ago