//native
type Codat = {
encodedKey: string
}
/**
* Get supplier analysis
* The *List suppliers* endpoint returns a list of [suppliers](https://docs.codat.io/spend-insights#/schemas/SupplierAnalysis) for a given company's connection.
[Suppliers](https://docs.codat.io/spend-insights#/schemas/SupplierAnalysis) are people or organizations that provide something, such as a product or service.
Before using this endpoint, you must have an existing [spend analysis report generated](https://docs.codat.io/spend-insights-api#/operations/generate-report).
*/
export async function main(
auth: Codat,
companyId: string,
reportId: string,
maxAge: string | undefined,
page: string | undefined,
pageSize: string | undefined,
query: string | undefined,
orderBy: string | undefined
) {
const url = new URL(
`https://api.codat.io/companies/${companyId}/reports/spendAnalysis/${reportId}/suppliers`
)
for (const [k, v] of [
['maxAge', maxAge],
['page', page],
['pageSize', pageSize],
['query', query],
['orderBy', orderBy]
]) {
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