//native
type Pandadoc = {
apiKey: string
}
export async function main(
auth: Pandadoc,
id: string,
watermark_color: string | undefined,
watermark_font_size: string | undefined,
watermark_opacity: string | undefined,
watermark_text: string | undefined,
separate_files: string | undefined
) {
const url = new URL(`https://api.pandadoc.com/public/v1/documents/${id}/download`)
for (const [k, v] of [
['watermark_color', watermark_color],
['watermark_font_size', watermark_font_size],
['watermark_opacity', watermark_opacity],
['watermark_text', watermark_text],
['separate_files', separate_files]
]) {
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.text()
}
Submitted by hugo697 581 days ago