Edits history of script submission #9181 for ' List documents (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,
    	completed_from: string | undefined,
    	completed_to: string | undefined,
    	contact_id: string | undefined,
    	count: string | undefined,
    	created_from: string | undefined,
    	created_to: string | undefined,
    	deleted: string | undefined,
    	id: string | undefined,
    	folder_uuid: string | undefined,
    	form_id: string | undefined,
    	membership_id: string | undefined,
    	metadata: string | undefined,
    	modified_from: string | undefined,
    	modified_to: string | undefined,
    	order_by:
    		| 'name'
    		| 'date_created'
    		| 'date_status_changed'
    		| 'date_of_last_action'
    		| 'date_modified'
    		| 'date_sent'
    		| 'date_completed'
    		| 'date_expiration'
    		| 'date_declined'
    		| 'status'
    		| '-name'
    		| '-date_created'
    		| '-date_status_changed'
    		| '-date_of_last_action'
    		| '-date_modified'
    		| '-date_sent'
    		| '-date_completed'
    		| '-date_expiration'
    		| '-date_declined'
    		| '-status'
    		| undefined,
    	page: string | undefined,
    	q: string | undefined,
    	status:
    		| '0'
    		| '1'
    		| '2'
    		| '3'
    		| '4'
    		| '5'
    		| '6'
    		| '7'
    		| '8'
    		| '9'
    		| '10'
    		| '11'
    		| '12'
    		| '13'
    		| undefined,
    	status__ne:
    		| '0'
    		| '1'
    		| '2'
    		| '3'
    		| '4'
    		| '5'
    		| '6'
    		| '7'
    		| '8'
    		| '9'
    		| '10'
    		| '11'
    		| '12'
    		| '13'
    		| undefined,
    	tag: string | undefined,
    	template_id: string | undefined
    ) {
    	const url = new URL(`https://api.pandadoc.com/public/v1/documents`)
    
    	for (const [k, v] of [
    		['completed_from', completed_from],
    		['completed_to', completed_to],
    		['contact_id', contact_id],
    		['count', count],
    		['created_from', created_from],
    		['created_to', created_to],
    		['deleted', deleted],
    		['id', id],
    		['folder_uuid', folder_uuid],
    		['form_id', form_id],
    		['membership_id', membership_id],
    		['metadata', metadata],
    		['modified_from', modified_from],
    		['modified_to', modified_to],
    		['order_by', order_by],
    		['page', page],
    		['q', q],
    		['status', status],
    		['status__ne', status__ne],
    		['tag', tag],
    		['template_id', template_id]
    	]) {
    		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