//native
type Intercom = {
apiVersion: string
token: string
}
/**
* List subscriptions for a contact
* You can fetch a list of subscription types that are attached to a contact. These can be subscriptions that a user has 'opted-in' to or has 'opted-out' from, depending on the subscription type.
This will return a list of Subscription Type objects that the contact is associated with.
The data property will show a combined list of:
1.Opt-out subscription types that the user has opted-out from.
2.Opt-in subscription types that the user has opted-in to receiving.
*/
export async function main(auth: Intercom, contact_id: string) {
const url = new URL(`https://api.intercom.io/contacts/${contact_id}/subscriptions`)
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