# Track and download envelopes

> List envelopes, see who has signed, send a reminder, void one, and download the signed PDF and its certificate.

An envelope is one document sent for signature. You need a key with the `read` scope to look, and `send` to remind or void.

## List envelopes

**curl**

```bash
curl "https://appliflo.com/api/v1/envelopes?status=awaiting&limit=20" \
  -H "Authorization: Bearer $APPLIFLO_API_KEY"
```

**Node**

```js
const res = await fetch("https://appliflo.com/api/v1/envelopes?status=awaiting&limit=20", {
  headers: { Authorization: `Bearer ${process.env.APPLIFLO_API_KEY}` },
});
const { data, meta } = await res.json();
for (const env of data) console.log(env.id, env.subject, `${env.recipients.signed}/${env.recipients.total} signed`);
```

**Python**

```python
import os, requests

headers = {"Authorization": f"Bearer {os.environ['APPLIFLO_API_KEY']}"}
page = requests.get(
    "https://appliflo.com/api/v1/envelopes?status=awaiting&limit=20",
    headers=headers,
).json()
for env in page["data"]:
    print(env["id"], env["subject"], env["recipients"]["signed"], "of", env["recipients"]["total"])
```

`limit` is 20 by default and at most 100. Use `offset` for the next page; `meta.total` says how many there are.

| `status` | Meaning |
| --- | --- |
| `draft` | Not sent yet. |
| `awaiting` | Waiting for recipients. |
| `completing` | Everyone has signed and the signed PDF is being sealed. |
| `completed` | Signed and sealed. Ready to download. |
| `declined` | A recipient declined to sign. |
| `expired` | Passed its expiry date. |
| `voided` | Cancelled by the sender. |

## See one envelope

`GET /api/v1/envelopes/{id}` returns each recipient with their `status`, when they `viewedAt`, `consentedAt`, `identityVerifiedAt` and `signedAt`, and a `timeline` of what happened. `hasSealedDocument` is `true` once the signed PDF can be downloaded.

To hear when an envelope changes without polling, add a [webhook](https://dev.appliflo.com/webhooks). Otherwise, poll an envelope every minute or so while you wait for it.

## Send a reminder

`POST /api/v1/envelopes/{id}/remind` emails everyone who still has to act. Each person gets at most one reminder a day; the reply says how many were `reminded` and how many were held back by that limit (`rateLimited`). Reminders also go out by themselves every 24 hours unless the sender changed that.

## Void an envelope

```bash
curl -X POST https://appliflo.com/api/v1/envelopes/$ENVELOPE_ID/void \
  -H "Authorization: Bearer $APPLIFLO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"reason":"Sent to the wrong address"}'
```

Recipients can no longer sign it. An envelope that is already completed, or already voided, can't be voided (`409`).

## Download the signed PDF

When the envelope is `completed`, ask for a download link. `artifact=sealed` is the signed PDF. `artifact=certificate` is the completion certificate: who signed, when, how they were identified, and the document's fingerprint.

**curl**

```bash
curl "https://appliflo.com/api/v1/envelopes/$ENVELOPE_ID/download?artifact=sealed" \
  -H "Authorization: Bearer $APPLIFLO_API_KEY"
```

**Node**

```js
import { writeFile } from "node:fs/promises";

const link = await fetch(`https://appliflo.com/api/v1/envelopes/${envelopeId}/download?artifact=sealed`, {
  headers: { Authorization: `Bearer ${process.env.APPLIFLO_API_KEY}` },
});
const { data } = await link.json();
await writeFile("signed.pdf", Buffer.from(await (await fetch(data.url)).arrayBuffer()));
```

**Python**

```python
url = requests.get(
    f"https://appliflo.com/api/v1/envelopes/{envelope_id}/download?artifact=sealed",
    headers=headers,
).json()["data"]["url"]
open("signed.pdf", "wb").write(requests.get(url).content)
```

The link is short-lived. Fetch the file straight away and keep your own copy. Ask for a new link each time you need one.
