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

Gets Analysis Datasets

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 datasets
7
 * Gets Analysis Datasets
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
	previous_crawl: string | undefined,
16
	deprecated_fields: string | undefined,
17
	sequenced: string | undefined
18
) {
19
	const url = new URL(
20
		`https://api.botify.com/analyses/${username}/${project_slug}/${analysis_slug}/urls/datasets`
21
	)
22
	for (const [k, v] of [
23
		['area', area],
24
		['previous_crawl', previous_crawl],
25
		['deprecated_fields', deprecated_fields],
26
		['sequenced', sequenced]
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: '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