Edits history of script submission #9179 for ' Document status change (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: {
    		status: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13
    		note?: string
    		notify_recipients?: false | true
    	}
    ) {
    	const url = new URL(`https://api.pandadoc.com/public/v1/documents/${id}/status`)
    
    	const formData = new FormData()
    	for (const [k, v] of Object.entries(body)) {
    		if (v !== undefined && v !== '' && k !== undefined) {
    			formData.append(k, String(v))
    		}
    	}
    
    	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