Edits history of script submission #11110 for ' Create content data export (intercom)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Intercom = {
    	apiVersion: string
    	token: string
    }
    /**
     * Create content data export
     * To create your export job, you need to send a `POST` request to the export endpoint `https://api.
     */
    export async function main(
    	auth: Intercom,
    	body: { created_at_after: number; created_at_before: number }
    ) {
    	const url = new URL(`https://api.intercom.io/export/content/data`)
    
    	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.json()
    }
    

    Submitted by hugo697 536 days ago