# ATDSign agent API

Anyone with a verified ATDSign account can invite Codex, Grok Bot, or another HTTP client from **Settings → Agent integrations**, just below Profile. Choose the permissions and expiration, copy the setup message into the agent, and save the separately displayed credential in the agent’s secret store. The credential appears once. Revoke it from the same panel. Personal envelope and template permissions apply to records the account owns. Choose **Read and download Team Documents** to also let an agent access envelopes shared with the team. Reconnect an existing agent using a new credential to grant this permission. Removing an administrator role or resetting an account’s two-step sign-in under People revokes that account’s existing agent credentials.

Use `Authorization: Bearer <credential>` on HTTPS requests to the ATDSign origin. JSON requests use `Content-Type: application/json`. `GET /api/v1/agent/connection` checks the connection and returns the credential ID and granted scopes. Keep credential values and signer links in private destinations.

| Permission     | Operations                                                                                      |
| -------------- | ----------------------------------------------------------------------------------------------- |
| `read`         | List and inspect envelopes and templates, read envelope audit entries, download a completed PDF |
| `draft`        | Authorize uploads, create drafts, set signers, map fields and place fields from document tags   |
| `send`         | Send a prepared draft and email the first signer                                                |
| `signing_link` | Retrieve the current signer’s private URL for an envelope sent through this API                 |
| `team_read`    | Find team-shared envelopes and download their PDFs                                              |

## Upload a PDF and map coordinates

1. `POST /api/v1/uploads` returns the upload method. In `direct` mode, PUT the PDF bytes to the returned `url` with the returned `headers` and `Content-Type: application/pdf`. Omit the ATDSign authorization header on the storage PUT. After a successful upload, call `POST /api/v1/envelopes` with `{"title":"Agreement","filename":"agreement.pdf","uploadKey":"<uploadKey>"}`. In `multipart` mode, send the `title` and PDF `file` form parts straight to `POST /api/v1/envelopes`. The source PDF limit is 20 MiB. A direct upload belongs to the credential that requested it.
2. `PUT /api/v1/envelopes/{id}/signers` replaces the draft’s signer list. Send `{"signers":[{"name":"Jane Smith","email":"jane@example.com","signOrder":1}]}`. Use the returned signer IDs for field mapping. Signing order starts at 1.
3. `PUT /api/v1/envelopes/{id}/fields` replaces the draft’s field list. The coordinates and dimensions are fractions of the page, measured from the top-left, and the page number starts at 1. Use `GET /api/v1/envelopes/{id}` for page dimensions and the current field layout.

```json
{
  "fields": [
    {
      "signerId": "<id returned by the signers route>",
      "type": "signature",
      "page": 1,
      "x": 0.12,
      "y": 0.72,
      "width": 0.32,
      "height": 0.08,
      "required": true
    }
  ]
}
```

## Upload a Word or Markdown file and place fields from its tags

An envelope can start from a Word (`.docx`, `.doc`) or Markdown (`.md`) file as well as a PDF. ATDSign converts it to the PDF that everyone signs. For a direct upload, send `{"filename":"agreement.docx"}` to `POST /api/v1/uploads` and PUT the file with the `Content-Type` header it returns. For multipart, send the file as `file`. The create response's `convertedFrom` names the original file and lists any conversion warnings. Word files need the install's document converter.

Type tags where fields belong: `{{signature:1}}`, `{{date:2}}`, `{{initials:1}}`, `{{text:1:Company name}}`, `{{checkbox:2}}`. The number is the signer's place in the signing order. Put each signature tag on its own line with space above it, as a signature field is taller than a line of text. Add `?` after the type for an optional field, as in `{{text?:2:Phone number}}`. Tags in a `.docx` or `.md` file do not show in the PDF. In a PDF, print them in white.

1. Set the signers with `PUT /api/v1/envelopes/{id}/signers`.
2. `POST /api/v1/envelopes/{id}/fields/from-document` replaces the draft's fields with the ones the document places: its tags and a PDF's own form fields. `{"signatureBlock":"auto"}` (the default) also adds a signature, printed name and date for every signer when the document places no fields. Use `"always"` to add one anyway, or `"never"`. Blank lines that only look like signature lines are not used. The response lists the fields and the draft's `review`.
3. `GET /api/v1/envelopes/{id}` includes `review` while the envelope is a draft:
   - `checks`: the same "Before you send" list the editor shows. Each has a `kind` (`covers_text`, `overlaps_field`, `off_page`, `no_label` or `no_date`), a `message`, the `page`, the `fieldIds` and the `signerId`.
   - `unplacedFields`: tags that name no signer (`no_signer`) and suggested lines that were left alone (`guess`).
   - `readyToSend` and `problem`: what would stop a send, such as a signer with no signature field.
   - `convertedFrom`: the original file, and whether its PDF has been confirmed.
4. To fix a check, edit the document and start a new draft, or adjust the fields with `PUT /api/v1/envelopes/{id}/fields`. None of the checks stops a send.
5. `GET /api/v1/envelopes/{id}/document` returns the PDF the signers will see. Show it to the sender before sending.
6. A converted draft is sent with `"convertedPdfConfirmed": true` beside `"permittedUseConfirmed": true`, once the sender has approved the PDF. Without it, the send is refused with `409`.

## Use a saved template

`GET /api/v1/templates` lists your templates. `GET /api/v1/templates/{id}` shows the signing roles in order. `POST /api/v1/templates/{id}/envelopes` creates a draft with the template’s mapped fields. Supply a title and one `{name,email}` signer for each role in signing order.

```json
{
  "title": "Agreement",
  "signers": [{ "name": "Jane Smith", "email": "jane@example.com" }]
}
```

The draft uses the saved PDF by default. To supply the same PDF yourself, add `"upload":{"filename":"agreement.pdf","uploadKey":"<uploadKey>"}` to the JSON or send multipart `title`, `file`, and a `signers` field containing the JSON array. The uploaded file must match the template PDF byte for byte. Use coordinates for a different PDF.

## Send and retrieve the signer link

1. Verify the prepared document, signer details, and field mapping with the sender. `POST /api/v1/envelopes/{id}/send` accepts `{"permittedUseConfirmed":true}` and optional `expiresInDays`, `reminderIntervalDays`, `signatureLevel`, and `convertedPdfConfirmed` (required for a Word or Markdown original). Confirm that the sender has approved the permitted use and sending. The usual signing and identity requirements still apply.
2. `POST /api/v1/envelopes/{id}/signing-link` with no body returns `envelopeId`, `signerId`, `expiresAt` (Unix seconds), and `signingUrl` for the active signer. In a sequential signing flow, the next link becomes available when the next signer’s turn begins. Retrieval preserves the emailed link. Older envelopes and envelopes sent from the dashboard use their existing invitation email.
3. Treat the signer URL as a private credential. Deliver it to the authorized recipient through the agreed channel. Use the envelope ID when recording the workflow in shared logs.

## Browse Team Documents

- `GET /api/v1/team/envelopes?page=1&search=Agreement` lists envelopes currently shared with the team. Each entry contains the title, status, owner’s name, date shared in Unix seconds, and a `documentPath`. Search matches titles and owners. Follow `hasNext` to request the next page.
- Send an authenticated `GET` to the `documentPath` returned in the list, such as `/api/v1/team/envelopes/{id}/pdf`. It returns the signed PDF when the envelope is completed and the source PDF otherwise.
- The owner controls sharing and envelope management. When the owner stops sharing, the envelope disappears from the team list and its team PDF path returns `404`. Team access follows the site’s Team Documents settings.

## Track envelopes

- `GET /api/v1/envelopes?page=1&limit=25` lists owned envelopes with optional `status` and `search` filters.
- `GET /api/v1/envelopes/{id}` reads status, pages, signers, and field placements, plus a draft's `review`.
- `GET /api/v1/envelopes/{id}/audit` returns audit events. `GET /api/v1/envelopes/{id}/pdf` downloads the signed PDF after completion.
- Treat `401` as an inactive or invalid credential, `403` as a missing scope, and `429` as a rate limit. Honor `Retry-After`. After an ambiguous send or draft creation result, check the envelope list or detail before retrying. Uploads are temporary.

Account settings, user administration, and cross-account envelopes are outside these permissions. The site audit records credential changes, authenticated API access decisions, and successful signer-link retrievals. The envelope audit records the underlying document workflow.
