//native
type Codat = {
encodedKey: string
}
/**
* Update source account
* The _Update source account_ endpoint updates a single source account for a single data connection connected to a single company.
### Tips and pitfalls
* This endpoint only updates the `accountName` field.
* Updates made here apply exclusively to source accounts and will not affect target accounts in the accounting software.
*/
export async function main(
auth: Codat,
companyId: string,
connectionId: string,
accountId: string,
body: {
id: string
accountName: string
accountType: 'checking' | 'savings' | 'loan' | 'creditCard' | 'prepaidCard'
accountNumber: string
sortCode?: string
routingInfo?: {
bankCode?: string
type?:
| 'rtn'
| 'aba'
| 'swift'
| 'bsb'
| 'iban'
| 'nz2'
| 'trno'
| 'sortcode'
| 'blz'
| 'ifsc'
| 'bankcode'
| 'apca'
| 'clabe'
}
currency: string
balance: number
accountInfo?: {
description?: string
nickname?: string
accountOpenDate?: string
availableBalance?: number
}
status?: 'pending' | 'connected' | 'connecting' | 'disconnected' | 'unknown'
feedStartDate?: string
}
) {
const url = new URL(
`https://api.codat.io/companies/${companyId}/connections/${connectionId}/connectionInfo/bankFeedAccounts/${accountId}`
)
const response = await fetch(url, {
method: 'PATCH',
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