Gets a list of Company Names that have been queried.
One script reply has been approved by the moderators Verified
Created by hugo697 414 days ago
Submitted by hugo697 Bun
Verified 414 days ago
1
//native
2
type Aero_workflow = {
3
	apiKey: string
4
}
5

6
export async function main(
7
	auth: Aero_workflow,
8
	accountid: string,
9
	name: string | undefined,
10
	active: string | undefined
11
) {
12
	const url = new URL(`https://api.aeroworkflow.com/api/${accountid}/v1/Companies/Query`)
13

14
	for (const [k, v] of [
15
		['name', name],
16
		['active', active]
17
	]) {
18
		if (v !== undefined && v !== '' && k !== undefined) {
19
			url.searchParams.append(k, v)
20
		}
21
	}
22

23
	const response = await fetch(url, {
24
		method: 'GET',
25
		headers: {
26
			apikey: auth.apiKey
27
		},
28
		body: undefined
29
	})
30

31
	if (!response.ok) {
32
		const text = await response.text()
33
		throw new Error(`${response.status} ${text}`)
34
	}
35

36
	return await response.json()
37
}
38