//native
type Pandadoc = {
apiKey: string
}
export async function main(
auth: Pandadoc,
count: string | undefined,
page: string | undefined,
status: string | undefined,
order_by: 'name' | 'responses' | 'status' | 'created_date' | 'modified_date' | undefined,
asc: string | undefined,
name: string | undefined
) {
const url = new URL(`https://api.pandadoc.com/public/v1/forms`)
for (const [k, v] of [
['count', count],
['page', page],
['status', status],
['order_by', order_by],
['asc', asc],
['name', name]
]) {
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.json()
}
Submitted by hugo697 581 days ago