0

Get supplier analysis

by
Published Oct 17, 2025

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).

Script codat Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Codat = {
3
	encodedKey: string
4
}
5
/**
6
 * Get supplier analysis
7
 * The *List suppliers* endpoint returns a list of [suppliers](https://docs.codat.io/spend-insights#/schemas/SupplierAnalysis) for a given company's connection.
8

9
[Suppliers](https://docs.codat.io/spend-insights#/schemas/SupplierAnalysis) are people or organizations that provide something, such as a product or service.
10

11
Before using this endpoint, you must have an existing [spend analysis report generated](https://docs.codat.io/spend-insights-api#/operations/generate-report).
12
 */
13
export async function main(
14
	auth: Codat,
15
	companyId: string,
16
	reportId: string,
17
	maxAge: string | undefined,
18
	page: string | undefined,
19
	pageSize: string | undefined,
20
	query: string | undefined,
21
	orderBy: string | undefined
22
) {
23
	const url = new URL(
24
		`https://api.codat.io/companies/${companyId}/reports/spendAnalysis/${reportId}/suppliers`
25
	)
26
	for (const [k, v] of [
27
		['maxAge', maxAge],
28
		['page', page],
29
		['pageSize', pageSize],
30
		['query', query],
31
		['orderBy', orderBy]
32
	]) {
33
		if (v !== undefined && v !== '' && k !== undefined) {
34
			url.searchParams.append(k, v)
35
		}
36
	}
37

38
	const response = await fetch(url, {
39
		method: 'GET',
40
		headers: {
41
			Authorization: `Basic ${auth.encodedKey}`
42
		},
43
		body: undefined
44
	})
45
	if (!response.ok) {
46
		const text = await response.text()
47
		throw new Error(`${response.status} ${text}`)
48
	}
49
	return await response.json()
50
}
51