Edits history of script submission #15204 for ' Update all sync settings (codat)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Codat = {
    	encodedKey: string
    }
    /**
     * Update all sync settings
     * Update sync settings for all data types.
     */
    export async function main(
    	auth: Codat,
    	body: {
    		clientId: string
    		settings: {
    			dataType:
    				| 'accountTransactions'
    				| 'balanceSheet'
    				| 'bankAccounts'
    				| 'bankTransactions'
    				| 'billCreditNotes'
    				| 'billPayments'
    				| 'bills'
    				| 'cashFlowStatement'
    				| 'chartOfAccounts'
    				| 'company'
    				| 'creditNotes'
    				| 'customers'
    				| 'directCosts'
    				| 'directIncomes'
    				| 'invoices'
    				| 'itemReceipts'
    				| 'items'
    				| 'journalEntries'
    				| 'journals'
    				| 'paymentMethods'
    				| 'payments'
    				| 'profitAndLoss'
    				| 'purchaseOrders'
    				| 'salesOrders'
    				| 'suppliers'
    				| 'taxRates'
    				| 'trackingCategories'
    				| 'transfers'
    				| 'banking-accountBalances'
    				| 'banking-accounts'
    				| 'banking-transactionCategories'
    				| 'banking-transactions'
    				| 'commerce-companyInfo'
    				| 'commerce-customers'
    				| 'commerce-disputes'
    				| 'commerce-locations'
    				| 'commerce-orders'
    				| 'commerce-paymentMethods'
    				| 'commerce-payments'
    				| 'commerce-productCategories'
    				| 'commerce-products'
    				| 'commerce-taxComponents'
    				| 'commerce-transactions'
    			fetchOnFirstLink: false | true
    			syncSchedule: number
    			syncOrder: number
    			syncFromUtc?: string
    			syncFromWindow?: number
    			monthsToSync?: number
    			isLocked?: false | true
    		}[]
    		overridesDefaults: false | true
    	}
    ) {
    	const url = new URL(`https://api.codat.io/profile/syncSettings`)
    
    	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.text()
    }
    

    Submitted by hugo697 235 days ago