0

Delete connection

by
Published Oct 17, 2025

Revoke and remove a connection from a company. This operation is not reversible. The end user would need to reauthorize a new data connection if you wish to view new data for this company.

Script codat Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Codat = {
3
	encodedKey: string
4
}
5
/**
6
 * Delete connection
7
 * Revoke and remove a connection from a company.
8
This operation is not reversible. The end user would need to reauthorize a new data connection if you wish to view new data for this company.
9
 */
10
export async function main(auth: Codat, companyId: string, connectionId: string) {
11
	const url = new URL(`https://api.codat.io/companies/${companyId}/connections/${connectionId}`)
12

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