Edits history of script submission #15187 for ' Refresh data type (codat)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Codat = {
    	encodedKey: string
    }
    /**
     * Refresh data type
     * Refreshes a given data type for a given company.
    
    This is an asynchronous operation, and will bring updated data into Codat from the linked integration for you to view.
     */
    export async function main(
    	auth: Codat,
    	companyId: string,
    	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',
    	connectionId: string | undefined
    ) {
    	const url = new URL(`https://api.codat.io/companies/${companyId}/data/queue/${dataType}`)
    	for (const [k, v] of [['connectionId', connectionId]]) {
    		if (v !== undefined && v !== '' && k !== undefined) {
    			url.searchParams.append(k, v)
    		}
    	}
    
    	const response = await fetch(url, {
    		method: 'POST',
    		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