Edits history of script submission #9178 for ' Get webhook event page (pandadoc)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Pandadoc = {
    	apiKey: string
    }
    
    export async function main(
    	auth: Pandadoc,
    	count: string | undefined,
    	page: string | undefined,
    	since: string | undefined,
    	to: string | undefined,
    	type: string | undefined,
    	http_status_code: string | undefined,
    	error: string | undefined
    ) {
    	const url = new URL(`https://api.pandadoc.com/public/v1/webhook-events`)
    
    	for (const [k, v] of [
    		['count', count],
    		['page', page],
    		['since', since],
    		['to', to],
    		['type', type],
    		['http_status_code', http_status_code],
    		['error', error]
    	]) {
    		if (v !== undefined && v !== '' && k !== undefined) {
    			url.searchParams.append(k, v)
    		}
    	}
    
    	const response = await fetch(url, {
    		method: 'GET',
    		headers: {
    			Authorization: `API-Key ${auth.apiKey}`
    		},
    		body: undefined
    	})
    
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    
    	return await response.json()
    }
    

    Submitted by hugo697 581 days ago