0
Get urls
One script reply has been approved by the moderators Verified

Executes a query and returns a paginated response

Created by hugo697 2 days ago Viewed 0 times
0
Submitted by hugo697 Bun
Verified 2 days ago
1
//native
2
type Botify = {
3
	token: string
4
}
5
/**
6
 * Get urls
7
 * Executes a query and returns a paginated response
8
 */
9
export async function main(
10
	auth: Botify,
11
	username: string,
12
	project_slug: string,
13
	analysis_slug: string,
14
	area: string | undefined,
15
	page: string | undefined,
16
	size: string | undefined,
17
	previous_crawl: string | undefined
18
) {
19
	const url = new URL(
20
		`https://api.botify.com/analyses/${username}/${project_slug}/${analysis_slug}/urls`
21
	)
22
	for (const [k, v] of [
23
		['area', area],
24
		['page', page],
25
		['size', size],
26
		['previous_crawl', previous_crawl]
27
	]) {
28
		if (v !== undefined && v !== '' && k !== undefined) {
29
			url.searchParams.append(k, v)
30
		}
31
	}
32
	const response = await fetch(url, {
33
		method: 'POST',
34
		headers: {
35
			Authorization: 'Token ' + auth.token
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.text()
44
}
45