//native
type Intercom = {
apiVersion: string
token: string
}
/**
* List all data attributes
* You can fetch a list of all data attributes belonging to a workspace for contacts, companies or conversations.
*/
export async function main(
auth: Intercom,
model: 'contact' | 'company' | 'conversation' | undefined,
include_archived: string | undefined
) {
const url = new URL(`https://api.intercom.io/data_attributes`)
for (const [k, v] of [
['model', model],
['include_archived', include_archived]
]) {
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