//native
/**
* List Envelopes
* Search envelopes in the account by date range, status, folder, recipient email, or full-text.
*/
export async function main(
auth: RT.Docusign,
from_date: string,
to_date: string | undefined,
status: string | undefined,
folder_ids: string | undefined,
email: string | undefined,
search_text: string | undefined,
) {
const url = new URL(
`${auth.base_uri}/restapi/v2.1/accounts/${auth.account_id}/envelopes`,
)
url.searchParams.append("from_date", from_date)
for (const [k, v] of [
["to_date", to_date],
["status", status],
["folder_ids", folder_ids],
["email", email],
["search_text", search_text],
] as const) {
if (v !== undefined && v !== "") {
url.searchParams.append(k, v)
}
}
const response = await fetch(url, {
method: "GET",
headers: {
Authorization: `Bearer ${auth.token}`,
Accept: "application/json",
},
})
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return await response.json()
}
Submitted by hugo989 22 days ago