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

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Codat = {
    	encodedKey: string
    }
    /**
     * Set configuration
     * Use *Set configuration* endpoint to configure a given company ID.
     */
    export async function main(
    	auth: Codat,
    	companyId: string,
    	body: {
    		companyId?: string
    		accountingSoftwareCompanyName?: string
    		enabled?: false | true
    		configured?: false | true
    		schedule?: {
    			selectedFrequency?: string
    			frequencyOptions?: string[]
    			startDate?: string
    			syncHourUtc?: number
    			timeZoneIanaId?: string
    		}
    		configuration?: {
    			syncAsBankFeeds?: {
    				enableSync?: false | true
    				selectedBankAccountId?: string
    				bankAccountOptions?: {
    					id?: string
    					name?: string
    					accountType?: string
    				}[]
    			}
    			syncAsExpenses?: {
    				enableSync?: false | true
    				supplier?: {
    					selectedSupplierId?: string
    					supplierOptions?: { id?: string; name?: string }[]
    				}
    				customer?: {
    					selectedCustomerId?: string
    					customerOptions?: { id?: string; name?: string }[]
    				}
    				selectedBankAccountId?: string
    				bankAccountOptions?: {
    					id?: string
    					name?: string
    					accountType?: string
    				}[]
    			}
    		}
    	}
    ) {
    	const url = new URL(`https://api.codat.io/companies/${companyId}/sync/banking/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