//native
type Intercom = {
apiVersion: string
token: string
}
/**
* Submit a data event
*
You will need an Access Token that has write permissions to send Events.
*/
export async function main(
auth: Intercom,
body:
| ({} & {
event_name?: string
created_at?: number
user_id?: string
id?: string
email?: string
metadata?: {}
})
| ({} & {
event_name?: string
created_at?: number
user_id?: string
id?: string
email?: string
metadata?: {}
})
| ({} & {
event_name?: string
created_at?: number
user_id?: string
id?: string
email?: string
metadata?: {}
})
) {
const url = new URL(`https://api.intercom.io/events`)
const response = await fetch(url, {
method: 'POST',
headers: {
'Intercom-Version': auth.apiVersion,
'Content-Type': 'application/json',
Authorization: 'Bearer ' + auth.token
},
body: JSON.stringify(body)
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.text()
}
Submitted by hugo697 536 days ago