Skip to content

Resources

Working with resources

How the SignatureAPI CLI resource commands choose a mode and a credential, read request bodies, ask for confirmation, page through lists, and report results.

The resource commands work with envelopes, recipients, events, deliverables, uploads, and sent emails from your terminal or a CI job. Every one except the emails commands sends the same request as the REST API, so a body that works with the API works here.

This page covers what all resource commands share. Each resource has its own page with common tasks and the full command reference.

Commands by resource

ResourceCommandsUse them to
Envelopeslist, get, create, cancel, deleteSend an envelope from a JSON file and follow its status.
Recipientsresend, replace, ceremonyRemind, replace, or get a signing URL for a recipient.
EventslistSee what happened to an envelope or a recipient.
Deliverableslist, getDownload the signed PDF of a completed envelope.
Uploadscreate, inspectUpload a local document and check its placeholders.
Emailslist, getRead the emails SignatureAPI sent for your account.

<command> --help lists every option with an example, for example npx signatureapi envelopes create --help.

Test and live mode

Commands act in test mode unless you pass --mode live or run them with a live API key. Test mode sends no email to recipients.

A resource belongs to one mode. Reaching a resource of the other mode fails with mode-error, and the message says which mode to use. Uploads belong to the account, not to a mode, so the uploads commands take no --mode.

Request bodies

envelopes create and recipients ceremony take the API’s request body: Create an envelope and Create a ceremony. --body <path> reads a JSON file, and --body - reads stdin. The CLI sends the body as written.

envelope.json
{
  "title": "Service Agreement",
  "message": "Please review the agreement and provide your signature.",
  "routing": "parallel",
  "documents": [
    {
      "key": "service_agreement",
      "title": "Service Agreement",
      "url": "https://pub-9cb75390636c4a8a83a6f76da33d7f45.r2.dev/docs-samples/acme-service-agreement.pdf",
      "format": "pdf",
      "places": [
        { "key": "client_signs_here", "type": "signature", "recipient_key": "client" },
        { "key": "provider_signs_here", "type": "signature", "recipient_key": "provider" }
      ]
    }
  ],
  "recipients": [
    { "type": "signer", "key": "client", "name": "Jane Doe", "email": "jane.doe@example.com" },
    { "type": "signer", "key": "provider", "name": "John Smith", "email": "john.smith@example.com" }
  ]
}

The examples on the resource pages use this file as envelope.json. Its document has the [[client_signs_here]] and [[provider_signs_here]] placeholders the places refer to.

A body can be at most 1,536,000 bytes. A body that can’t be read, isn’t a JSON object, or is over the limit fails with invalid-options before any request.

Confirmation

Some commands ask before they act:

  • envelopes cancel and envelopes delete ask in both modes, because neither can be undone.
  • In live mode, envelopes create, recipients resend, recipients replace, and recipients ceremony ask too, because they reach real people.

In a non-interactive shell, pass --yes. Without it, the command fails with confirmation-required (exit code 2) before it signs in or sends anything. --json does not skip the prompt. A command that reads its body from stdin (--body -) can’t prompt, so it needs --yes whenever it needs confirmation. Declining the prompt changes nothing and reports confirmation-declined.

Pagination

List commands return up to 20 items per page (--limit 1 to 20). When there are more, the result carries next_cursor, and its next step is the exact command for the next page: the same filters plus --cursor <next_cursor>. The last page has no next_cursor.

No option fetches every page. Loop on next_cursor instead:

Terminal
cursor=""
while :; do
  result=$(npx --yes signatureapi envelopes list --status completed ${cursor:+--cursor "$cursor"} --json \
    | jq -c 'select(.type == "result")')
  echo "$result" | jq -e '.status == "success"' > /dev/null || exit 1
  echo "$result" | jq -r '.data[].id'
  cursor=$(echo "$result" | jq -r '.next_cursor // empty')
  [ -n "$cursor" ] || break
done

Space out requests in loops: the API applies rate limits. A read (list, get, inspect) is retried a few times on 429; a change is never resent. A 429 that remains fails with too-many-requests.

Results

Text output names the credential and the mode in its headline, for example “Envelopes (test mode, signed in)”, and shows the fields a person checks first. Add --json for the full resource.

With --json, the final result event carries the resource. Scripts read it with jq 'select(.type == "result")':

FieldDescription
credentialsign_in or api_key: which credential ran.
modetest or live: the mode the request acted in. Absent for uploads.
dataThe API resource, a list’s data array, or { id, url } for uploads create, plus key once the upload is stored. Absent for envelopes delete.
next_cursorLists only, when there is a next page.
problemFailures from an API error, and upload_not_stored: status, type, title, and detail and errors when the API sent them.

A request the API refuses fails with exit code 1. A few API errors, such as validation-error and not-found, keep their code; any other becomes api-error. Either way, problem carries the API’s type, title, and details, and the text output shows them. See Output and exit codes for the event stream and the result codes.

A change whose outcome is unknown after the request was sent, for example after a network error, is a partial result (exit code 1), such as envelope_creation_unconfirmed. The CLI never resends a change. Its next step says how to check whether the change happened before you try again.

API keys in CI

Resource commands can run with an API key instead of a sign-in, so a CI job needs no browser. The emails commands are the exception: they need the sign-in.

Which credential runs, in this order:

  1. --api-key-var <name>: the key in the env variable with that name. The option takes a variable name, never a key: a key on the command line would end up in shell history, process lists, and CI logs.
  2. SIGNATUREAPI_KEY, when it is set and not empty.
  3. The sign-in.

init writes SIGNATUREAPI_KEY by default, so a CI secret with that name works as is. The CLI reads the key from the process environment only, never from an env file. To use the sign-in while SIGNATUREAPI_KEY is exported, empty it for one command:

Terminal
SIGNATUREAPI_KEY= npx signatureapi envelopes list

--credential-store applies only to the sign-in. With a key, it fails with invalid-options.

The key decides the mode. A test key acts in test mode and a live key in live mode, so --mode is optional. A --mode that differs from the key’s mode fails with api-key-mode-mismatch before any request.

You see which key runs. Before its first request, the command prints “Using the API key in SIGNATUREAPI_KEY, test mode” (with the variable and mode it used). With --json, this is a progress event with the code api_key_selected and the fields variable and mode. The key itself never appears in output, errors, or next steps.

Confirmation still applies. envelopes cancel and envelopes delete always need --yes in CI, in test mode too. With a live key, so do envelopes create, recipients resend, recipients replace, and recipients ceremony.

A CI job with the test key from a secret:

Terminal
# SIGNATUREAPI_KEY comes from the CI secret store.
id=$(npx --yes signatureapi envelopes create --body envelope.json --json | jq -r 'select(.type == "result") | .data.id')
npx --yes signatureapi envelopes get "$id" --json
npx --yes signatureapi envelopes cancel "$id" --reason "Test run finished" --yes --json
npx --yes signatureapi envelopes delete "$id" --yes --json

Keep URLs out of shared logs. Text output prints the ceremony URL (recipients ceremony), the deliverable URL (deliverables get), the upload URL (uploads create), and the email’s HTML link (emails get). Text output goes to stderr, which CI logs capture. Anyone with a ceremony URL can sign as the recipient, and anyone with an email’s link can read it until the link expires. With --json, the URL is in the result on stdout, where your script decides what to do with it.

The key failure codes are listed in Troubleshooting.

Global options

Resource commands take these options, with two exceptions: the uploads commands take no --mode, and the emails commands take no --api-key-var.

Each command lists the global options it takes. They go after the command words.

OptionDescription
-V, --versionShow the CLI version.
-h, --helpShow help for a command.
--credential-store <store>Where the sign-in is kept; defaults to the OS keychain when one is usable, else a private file. One of keychain, file.
--jsonPrint newline-delimited JSON events instead of text.
--mode <mode>Mode to act in; with an API key, the key's mode. One of test, live. Default test.
--api-key-var <name>Env variable that holds the API key to use instead of the sign-in (default: SIGNATUREAPI_KEY when set).

Resource commands act in test mode unless --mode live is given or the API key is a live key.