//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