Edits history of script submission #9159 for ' Update Document only in the draft status (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,
    	id: string,
    	body: {
    		name?: string
    		recipients?: {
    			id?: string
    			email?: string
    			first_name?: string
    			last_name?: string
    		}[]
    		fields?: {}
    		tokens?: { name: string; value: string }[]
    		metadata?: {}
    		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?: {}
    				}[]
    			}[]
    		}[]
    	}
    ) {
    	const url = new URL(`https://api.pandadoc.com/public/v1/documents/${id}`)
    
    	const response = await fetch(url, {
    		method: 'PATCH',
    		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.text()
    }
    

    Submitted by hugo697 581 days ago