Edits history of script submission #15197 for ' Set company configuration (codat)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Codat = {
    	encodedKey: string
    }
    /**
     * Set company configuration
     * Sets a companies expense sync configuration
     */
    export async function main(
    	auth: Codat,
    	companyId: string,
    	body: {
    		bankAccount: { id?: string }
    		supplier: { id?: string }
    		customer: { id?: string }
    	}
    ) {
    	const url = new URL(`https://api.codat.io/companies/${companyId}/sync/expenses/config`)
    
    	const response = await fetch(url, {
    		method: 'POST',
    		headers: {
    			'Content-Type': 'application/json',
    			Authorization: `Basic ${auth.encodedKey}`
    		},
    		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