0

Get company access token

by
Published Oct 17, 2025

Use the _Get company access token_ endpoint to return an access token for the specified company ID. The token is valid for one day. The token is required by Codat's embeddable UIs (such as [Connections SDK](https://docs.codat.io/auth-flow/optimize/connection-management) and [Link SDK](https://docs.codat.io/auth-flow/authorize-embedded-link)) to verify the identity of the user and improve the reliability of data provided by them.

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 access token
7
 * Use the _Get company access token_ endpoint to return an access token for the specified company ID. The token is valid for one day. 
8

9
The token is required by Codat's embeddable UIs (such as [Connections SDK](https://docs.codat.io/auth-flow/optimize/connection-management) and [Link SDK](https://docs.codat.io/auth-flow/authorize-embedded-link)) to verify the identity of the user and improve the reliability of data provided by them.
10
 */
11
export async function main(auth: Codat, companyId: string) {
12
	const url = new URL(`https://api.codat.io/companies/${companyId}/accessToken`)
13

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