Edits history of script submission #9197 for ' List Content Library Item (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,
    	q: string | undefined,
    	id: string | undefined,
    	deleted: string | undefined,
    	folder_uuid: string | undefined,
    	count: string | undefined,
    	page: string | undefined,
    	tag: string | undefined
    ) {
    	const url = new URL(`https://api.pandadoc.com/public/v1/content-library-items`)
    
    	for (const [k, v] of [
    		['q', q],
    		['id', id],
    		['deleted', deleted],
    		['folder_uuid', folder_uuid],
    		['count', count],
    		['page', page],
    		['tag', tag]
    	]) {
    		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