//native
type Intercom = {
apiVersion: string
token: string
}
/**
* Scroll over all companies
* The `list all companies` functionality does not work well for huge datasets, and can result in errors and performance problems when paging deeply.
*/
export async function main(auth: Intercom, scroll_param: string | undefined) {
const url = new URL(`https://api.intercom.io/companies/scroll`)
for (const [k, v] of [['scroll_param', scroll_param]]) {
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 536 days ago