//native
type Codat = {
encodedKey: string
}
/**
* Get report status
* > **Available as beta release**
>
> This endpoint is part of a beta release. Please contact your account manager if you want to enable it.
Use the *Get report status* endpoint to return the metadata about report generation, such as its current status, date of request, and date of generation.
You can either provide the ID of a report or use `latest` as the ID value to get the most recent generated *reportName* report for the company.
*/
export async function main(
auth: Codat,
companyId: string,
reportType: 'spendAnalysis',
reportId: string,
maxAge: string | undefined
) {
const url = new URL(
`https://api.codat.io/companies/${companyId}/reports/${reportType}/${reportId}/status`
)
for (const [k, v] of [['maxAge', maxAge]]) {
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