Edits history of script submission #9387 for ' Get jobs (botify)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Botify = {
    	token: string
    }
    /**
     * Get jobs
     * List All jobs
     */
    export async function main(
    	auth: Botify,
    	page: string | undefined,
    	size: string | undefined,
    	job_type: string | undefined,
    	project: string | undefined,
    	analysis: string | undefined
    ) {
    	const url = new URL(`https://api.botify.com/jobs`)
    	for (const [k, v] of [
    		['page', page],
    		['size', size],
    		['job_type', job_type],
    		['project', project],
    		['analysis', analysis]
    	]) {
    		if (v !== undefined && v !== '' && k !== undefined) {
    			url.searchParams.append(k, v)
    		}
    	}
    	const response = await fetch(url, {
    		method: 'GET',
    		headers: {
    			Authorization: 'Token ' + auth.token
    		},
    		body: undefined
    	})
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    	return await response.text()
    }
    

    Submitted by hugo697 566 days ago