Edits history of script submission #11150 for ' List subscriptions for a contact (intercom)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //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