0

List of legal entities

by
Published Oct 17, 2025

Retrieve a list of legal entities in your account. **Token scopes**: `organizations:read`, `accounting:read`

Script deel Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
/**
3
 * List of legal entities
4
 * Retrieve a list of legal entities in your account.
5
 **Token scopes**: `organizations:read`, `accounting:read`
6
 */
7
export async function main(
8
	auth: RT.Deel,
9
	limit?: string | undefined,
10
	sort_order?: 'ASC' | 'DESC' | undefined,
11
	cursor?: string | undefined,
12
	include_archived?: string | undefined,
13
	legal_entity_id?: string | undefined,
14
	global_payroll?: string | undefined,
15
	_type?: string | undefined,
16
	country?: string | undefined,
17
	include_payroll_settings?: string | undefined
18
) {
19
	const url = new URL(`https://api.letsdeel.com/rest/v2/legal-entities`)
20
	for (const [k, v] of [
21
		['limit', limit],
22
		['sort_order', sort_order],
23
		['cursor', cursor],
24
		['include_archived', include_archived],
25
		['legal_entity_id', legal_entity_id],
26
		['global_payroll', global_payroll],
27
		['type', _type],
28
		['country', country],
29
		['include_payroll_settings', include_payroll_settings]
30
	]) {
31
		if (v !== undefined && v !== '') {
32
			url.searchParams.append(k, v)
33
		}
34
	}
35
	const response = await fetch(url, {
36
		method: 'GET',
37
		headers: {
38
			Authorization: 'Bearer ' + auth.apiKey
39
		},
40
		body: undefined
41
	})
42
	if (!response.ok) {
43
		const text = await response.text()
44
		throw new Error(`${response.status} ${text}`)
45
	}
46
	return await response.json()
47
}
48