Edits history of script submission #10441 for ' Retrieves the content of a specific file (xero)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Xero = {
    	token: string
    }
    /**
     * Retrieves the content of a specific file
     * By passing in the appropriate options, retrieve data for specific file
     */
    export async function main(auth: Xero, FileId: string, xero_tenant_id: string) {
    	const url = new URL(`https://api.xero.com/files.xro/1.0//Files/${FileId}/Content`)
    
    	const response = await fetch(url, {
    		method: 'GET',
    		headers: {
    			Accept: 'application/json',
    			'xero-tenant-id': xero_tenant_id,
    			Authorization: 'Bearer ' + auth.token
    		},
    		body: undefined
    	})
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    	return await response.text()
    }
    

    Submitted by hugo697 515 days ago