//native
type Codat = {
encodedKey: string
}
/**
* Get enhanced profit and loss accounts
* The Enhanced Profit and Loss Accounts endpoint returns a list of categorized accounts that appear on a company’s Profit and Loss. It also includes a balance per the financial statement date.
Codat suggests a category for each account automatically, but you can change it to a more suitable one.
*/
export async function main(
auth: Codat,
companyId: string,
reportDate: string | undefined,
numberOfPeriods: string | undefined
) {
const url = new URL(
`https://api.codat.io/companies/${companyId}/reports/enhancedProfitAndLoss/accounts`
)
for (const [k, v] of [
['reportDate', reportDate],
['numberOfPeriods', numberOfPeriods]
]) {
if (v !== undefined && v !== '' && k !== undefined) {
url.searchParams.append(k, v)
}
}
const response = await fetch(url, {
method: 'GET',
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