Edits history of script submission #15002 for ' Get Excel report status (codat)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Codat = {
    	encodedKey: string
    }
    /**
     * Get Excel report status
     * The *Get Excel report status* returns the status of the report mostly recently requested for Excel generation. It does not return the status of any historical report requests. 
    
    Poll this endpoint to check the progress of the report once you have requested its generation. This will not affect the generation of the report. 
    
    When the report generation completes successfully, the `inProgress` property will be marked as `false` and the `success` field will be marked as `true`.
     */
    export async function main(
    	auth: Codat,
    	companyId: string,
    	reportType: 'audit' | 'enhancedFinancials' | 'enhancedInvoices' | 'enhancedCashFlow' | undefined
    ) {
    	const url = new URL(`https://api.codat.io/data/companies/${companyId}/assess/excel`)
    	for (const [k, v] of [['reportType', reportType]]) {
    		if (v !== undefined && v !== '' && k !== undefined) {
    			url.searchParams.append(k, v)
    		}
    	}
    
    	const response = await fetch(url, {
    		method: 'GET',
    		headers: {
    			Authorization: `Basic ${auth.encodedKey}`
    		},
    		body: undefined
    	})
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    	return await response.json()
    }
    

    Submitted by hugo697 235 days ago