//native
type Intercom = {
apiVersion: string
token: string
}
/**
* List all data events
*
> 🚧
>
> Please note that you can only 'list' events that are less than 90 days old.
*/
export async function main(
auth: Intercom,
filter: string | undefined,
type: string | undefined,
summary: string | undefined
) {
const url = new URL(`https://api.intercom.io/events`)
for (const [k, v] of [
['filter', filter],
['type', type],
['summary', summary]
]) {
if (v !== undefined && v !== '' && k !== undefined) {
url.searchParams.append(k, v)
}
}
const response = await fetch(url, {
method: 'GET',
headers: {
'Intercom-Version': auth.apiVersion,
Authorization: 'Bearer ' + auth.token
},
body: undefined
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.json()
}
Submitted by hugo697 537 days ago