Edits history of script submission #11133 for ' List all contacts (intercom)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Intercom = {
    	apiVersion: string
    	token: string
    }
    /**
     * List all contacts
     * You can fetch a list of all contacts (ie. users or leads) in your workspace.
    {% admonition type="warning" name="Pagination" %}
      You can use pagination to limit the number of results returned. The default is `50` results per page.
      See the [pagination section](https://developers.intercom.com/docs/build-an-integration/learn-more/rest-apis/pagination/#pagination-for-list-apis) for more details on how to use the `starting_after` param.
    {% /admonition %}
    
     */
    export async function main(auth: Intercom) {
    	const url = new URL(`https://api.intercom.io/contacts`)
    
    	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