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

Gets the detail of an URL for an analysis

Created by hugo697 40 days ago Viewed 3 times
0
Submitted by hugo697 Bun
Verified 40 days ago
1
//native
2
type Botify = {
3
	token: string
4
}
5
/**
6
 * Get url detail
7
 * Gets the detail of an URL for an analysis
8
 */
9
export async function main(
10
	auth: Botify,
11
	username: string,
12
	project_slug: string,
13
	analysis_slug: string,
14
	url: string,
15
	fields: string | undefined
16
) {
17
	const endpoint = new URL(
18
		`https://api.botify.com/analyses/${username}/${project_slug}/${analysis_slug}/urls/${url}`
19
	)
20
	for (const [k, v] of [['fields', fields]]) {
21
		if (v !== undefined && v !== '' && k !== undefined) {
22
			endpoint.searchParams.append(k, v)
23
		}
24
	}
25
	const response = await fetch(endpoint, {
26
		method: 'GET',
27
		headers: {
28
			Authorization: 'Token ' + auth.token
29
		},
30
		body: undefined
31
	})
32
	if (!response.ok) {
33
		const text = await response.text()
34
		throw new Error(`${response.status} ${text}`)
35
	}
36
	return await response.text()
37
}
38