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

Creates a new UrlExport object and starts a task that will export the results into a csv. Returns the model id that manages the task

Created by hugo697 16 days ago Viewed 0 times
0
Submitted by hugo697 Bun
Verified 16 days ago
1
//native
2
type Botify = {
3
	token: string
4
}
5
/**
6
 * Create urls export
7
 * Creates a new UrlExport object and starts a task that will export the results into a csv. Returns the model id that manages the task
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
	export_size: string | undefined,
17
	size: string | undefined,
18
	compression: string | undefined
19
) {
20
	const url = new URL(
21
		`https://api.botify.com/analyses/${username}/${project_slug}/${analysis_slug}/urls/export`
22
	)
23
	for (const [k, v] of [
24
		['area', area],
25
		['previous_crawl', previous_crawl],
26
		['export_size', export_size],
27
		['size', size],
28
		['compression', compression]
29
	]) {
30
		if (v !== undefined && v !== '' && k !== undefined) {
31
			url.searchParams.append(k, v)
32
		}
33
	}
34
	const response = await fetch(url, {
35
		method: 'POST',
36
		headers: {
37
			Authorization: 'Token ' + auth.token
38
		},
39
		body: undefined
40
	})
41
	if (!response.ok) {
42
		const text = await response.text()
43
		throw new Error(`${response.status} ${text}`)
44
	}
45
	return await response.text()
46
}
47