0

Get payment method analysis

by
Published Oct 17, 2025

The *List payment methods* endpoint returns a [payment method analysis](https://docs.

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 payment method analysis
7
 * The *List payment methods* endpoint returns a [payment method analysis](https://docs.
8
 */
9
export async function main(
10
	auth: Codat,
11
	companyId: string,
12
	reportId: string,
13
	maxAge: string | undefined,
14
	page: string | undefined,
15
	pageSize: string | undefined,
16
	query: string | undefined,
17
	orderBy: string | undefined
18
) {
19
	const url = new URL(
20
		`https://api.codat.io/companies/${companyId}/reports/spendAnalysis/${reportId}/paymentMethods`
21
	)
22
	for (const [k, v] of [
23
		['maxAge', maxAge],
24
		['page', page],
25
		['pageSize', pageSize],
26
		['query', query],
27
		['orderBy', orderBy]
28
	]) {
29
		if (v !== undefined && v !== '' && k !== undefined) {
30
			url.searchParams.append(k, v)
31
		}
32
	}
33

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