Edits history of script submission #9158 for ' Create document (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,
    	editor_ver: string | undefined,
    	body: {
    		name?: string
    		detect_title_variables?: false | true
    		template_uuid?: string
    		folder_uuid?: string
    		owner?: {}
    		recipients?: {
    			email: string
    			first_name?: string
    			last_name?: string
    			role?: string
    			signing_order?: number
    		}[]
    		tokens?: { name: string; value: string }[]
    		fields?: {}
    		metadata?: {}
    		tags?: string[]
    		images?: { urls: string[]; name: string }[]
    		pricing_tables?: {
    			name: string
    			data_merge?: false | true
    			options?: {}
    			sections?: {
    				title: string
    				default?: false | true
    				multichoice_enabled?: false | true
    				rows?: {
    					options?: {
    						qty_editable?: false | true
    						optional_selected?: false | true
    						optional?: false | true
    					}
    					data?: {}
    					custom_fields?: {}
    				}[]
    			}[]
    		}[]
    		content_placeholders?: {
    			block_id?: string
    			content_library_items?: {
    				id: string
    				pricing_tables?: {
    					name: string
    					data_merge?: false | true
    					options?: {}
    					sections?: {
    						title: string
    						default?: false | true
    						multichoice_enabled?: false | true
    						rows?: {
    							options?: {
    								qty_editable?: false | true
    								optional_selected?: false | true
    								optional?: false | true
    							}
    							data?: {}
    							custom_fields?: {}
    						}[]
    					}[]
    				}[]
    				fields?: {}
    				recipients?: {
    					email: string
    					first_name?: string
    					last_name?: string
    					role?: string
    					signing_order?: number
    				}[]
    			}[]
    		}[]
    		url?: string
    		parse_form_fields?: false | true
    	}
    ) {
    	const url = new URL(`https://api.pandadoc.com/public/v1/documents`)
    
    	for (const [k, v] of [['editor_ver', editor_ver]]) {
    		if (v !== undefined && v !== '' && k !== undefined) {
    			url.searchParams.append(k, v)
    		}
    	}
    
    	const formData = new FormData()
    
    	for (const [k, v] of Object.entries(body)) {
    		if (v !== undefined && v !== '') {
    			formData.append(k, String(v))
    		}
    	}
    
    	const response = await fetch(url, {
    		method: 'POST',
    		headers: {
    			'Content-Type': 'application/json',
    			Authorization: `API-Key ${auth.apiKey}`
    		},
    		body: JSON.stringify(body)
    	})
    
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    
    	return await response.json()
    }
    

    Submitted by hugo697 581 days ago