0

Get List Companies

by
Published Oct 17, 2025
Script their_stack Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type TheirStack = {
3
	apiKey: string
4
}
5
/**
6
 * Get List Companies
7
 *
8
 */
9
export async function main(
10
	auth: TheirStack,
11
	list_id: string,
12
	order_by: 'revealed_at' | 'name' | undefined,
13
	order_direction: 'asc' | 'desc' | undefined,
14
	company_name_partial: string | undefined,
15
	limit: string | undefined,
16
	page: string | undefined,
17
	offset: string | undefined
18
) {
19
	const url = new URL(`https://api.theirstack.com/v0/company_lists/${list_id}/companies`)
20
	for (const [k, v] of [
21
		['order_by', order_by],
22
		['order_direction', order_direction],
23
		['company_name_partial', company_name_partial],
24
		['limit', limit],
25
		['page', page],
26
		['offset', offset]
27
	]) {
28
		if (v !== undefined && v !== '' && k !== undefined) {
29
			url.searchParams.append(k, v)
30
		}
31
	}
32
	const response = await fetch(url, {
33
		method: 'GET',
34
		headers: {
35
			Authorization: 'Bearer ' + auth.apiKey
36
		},
37
		body: undefined
38
	})
39
	if (!response.ok) {
40
		const text = await response.text()
41
		throw new Error(`${response.status} ${text}`)
42
	}
43
	return await response.json()
44
}
45