//native
type Codat = {
encodedKey: string
}
/**
* Get lifetime value metrics
* The *Get lifetime value metrics* endpoint returns the average revenue that a specific company will generate throughout its lifespan over one or more periods of time.
*/
export async function main(
auth: Codat,
companyId: string,
connectionId: string,
reportDate: string | undefined,
periodLength: string | undefined,
numberOfPeriods: string | undefined,
periodUnit: 'Day' | 'Week' | 'Month' | 'Year' | undefined,
includeDisplayNames: string | undefined
) {
const url = new URL(
`https://api.codat.io/data/companies/${companyId}/connections/${connectionId}/assess/commerceMetrics/lifetimeValue`
)
for (const [k, v] of [
['reportDate', reportDate],
['periodLength', periodLength],
['numberOfPeriods', numberOfPeriods],
['periodUnit', periodUnit],
['includeDisplayNames', includeDisplayNames]
]) {
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