Get posts to be added to bio
One script reply has been approved by the moderators Verified
Created by hugo697 369 days ago
Submitted by hugo697 Bun
Verified 369 days ago
1
//native
2
type Adhook = {
3
	token: string
4
}
5

6
export async function main(
7
	auth: Adhook,
8
	subtenantId: string | undefined,
9
	groupId: string | undefined,
10
	Origin: string
11
) {
12
	const url = new URL(`https://app.adhook.io/v1/posts/addToBio`)
13

14
	for (const [k, v] of [
15
		['subtenantId', subtenantId],
16
		['groupId', groupId]
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
			Authorization: `Bearer ${auth.token}`,
27
			Origin: Origin
28
		},
29
		body: undefined
30
	})
31

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

37
	return await response.json()
38
}
39