//native
type Codat = {
encodedKey: string
}
/**
* Create expense-transactions
* Create an expense transaction
*/
export async function main(
auth: Codat,
companyId: string,
body: {
items?: {
id: string
type:
| 'Payment'
| 'Refund'
| 'Reward'
| 'Chargeback'
| 'TransferIn'
| 'TransferOut'
| 'AdjustmentIn'
| 'AdjustmentOut'
issueDate: string
currency: string
currencyRate?: number
contactRef?: { id?: string; contactType?: 'Supplier' }
merchantName?: string
lines?: {
netAmount: number
taxAmount: number
taxRateRef?: { id?: string }
accountRef: { id?: string }
trackingRefs?: { id?: string }[]
}[]
notes?: string
}[]
}
) {
const url = new URL(
`https://api.codat.io/companies/${companyId}/sync/expenses/data/expense-transactions`
)
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