Edits history of script submission #19735 for ' Send a composite request (sage_intacct)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type SageIntacct = {
    	token: string
    }
    /**
     * Send a composite request
     * Sends multiple requests within a single POST request.
     */
    export async function main(
    	auth: SageIntacct,
    	body: {
    		method: 'GET' | 'POST' | 'PATCH' | 'DELETE'
    		path: string
    		headers?: {}
    		body?: {}
    		resultReference?: string
    	}[]
    ) {
    	const url = new URL(`https://api.intacct.com/ia/api/v1/services/core/composite`)
    
    	const response = await fetch(url, {
    		method: 'POST',
    		headers: {
    			'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 235 days ago