0

List customers

by
Published Oct 17, 2025

The *List customers* endpoint returns a list of [customers](https://docs.codat.io/commerce-api#/schemas/Customer) for a given company's connection. [Customers](https://docs.codat.io/commerce-api#/schemas/Customer) are people or organizations that place orders, make payments and recieve goods and/or services from the SMB. Before using this endpoint, you must have [retrieved data for the company](https://docs.codat.io/sync-for-commerce-v1-api#/operations/refresh-company-data).

Script codat Verified

The script

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

9
[Customers](https://docs.codat.io/commerce-api#/schemas/Customer) are people or organizations that place orders, make payments and recieve goods and/or services from the SMB.
10

11
Before using this endpoint, you must have [retrieved data for the company](https://docs.codat.io/sync-for-commerce-v1-api#/operations/refresh-company-data).
12
    
13
 */
14
export async function main(
15
	auth: Codat,
16
	companyId: string,
17
	connectionId: string,
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}/connections/${connectionId}/data/commerce-customers`
25
	)
26
	for (const [k, v] of [
27
		['page', page],
28
		['pageSize', pageSize],
29
		['query', query],
30
		['orderBy', orderBy]
31
	]) {
32
		if (v !== undefined && v !== '' && k !== undefined) {
33
			url.searchParams.append(k, v)
34
		}
35
	}
36

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