0

Get company

by
Published Oct 17, 2025

The *Get company* endpoint returns a single company for a given `companyId`. A [company](https://docs.codat.io/sync-for-payables-api#/schemas/Company) represents a business sharing access to their data. Each company can have multiple [connections](https://docs.codat.io/sync-for-payables-api#/schemas/Connection) to different data sources, such as one connection to Xero for accounting data, two connections to Plaid for two bank accounts, and a connection to Zettle for POS 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
 * Get company
7
 * The *Get company* endpoint returns a single company for a given `companyId`.
8

9
A [company](https://docs.codat.io/sync-for-payables-api#/schemas/Company) represents a business sharing access to their data.
10
Each company can have multiple [connections](https://docs.codat.io/sync-for-payables-api#/schemas/Connection) to different data sources, such as one connection to Xero for accounting data, two connections to Plaid for two bank accounts, and a connection to Zettle for POS data.
11

12
 */
13
export async function main(auth: Codat, companyId: string) {
14
	const url = new URL(`https://api.codat.io/companies/${companyId}`)
15

16
	const response = await fetch(url, {
17
		method: 'GET',
18
		headers: {
19
			Authorization: `Basic ${auth.encodedKey}`
20
		},
21
		body: undefined
22
	})
23
	if (!response.ok) {
24
		const text = await response.text()
25
		throw new Error(`${response.status} ${text}`)
26
	}
27
	return await response.json()
28
}
29