---
title: "Store Envelope Data on Completion"
description: "When an envelope completes, receive the webhook, fetch the envelope with the values signers entered, and save them to your database with your own IDs."
canonical: "https://signatureapi.com/docs/api/guides/use-cases/store-data-webhook"
source: "https://signatureapi.com/docs/api/guides/use-cases/store-data-webhook.md"
last_verified_api_version: "1.18.1"
last_modified: "2026-11-18T11:49:54Z"
---

# Store Envelope Data on Completion

When an envelope completes, receive the webhook, fetch the envelope with the values signers entered, and save them to your database with your own IDs.

_Last verified against API version 1.18.1._

After an envelope completes, you may want to store the signing data in your own database or system of record. This guide shows how to detect when an envelope completes using a webhook, retrieve the envelope details (including any captured input from the signer), and persist the data.

## Overview

The flow has five steps:

1. Register a webhook endpoint for the `envelope.completed` event.
2. Create the envelope with `capture_as` on the places whose values you want, and your own IDs in `metadata`.
3. Receive the `envelope.completed` event when every recipient has finished.
4. Retrieve the full envelope, including `captures`, with the API.
5. Store the data in your database.

Steps 3 to 5 happen in your webhook endpoint:

**Storing envelope data when the envelope completes**

Participants: SignatureAPI, Your webhook endpoint, Your database.

1. **SignatureAPI** to **Your webhook endpoint**: Webhook `envelope.completed`
   The event carries the envelope ID and your `envelope_metadata`, but not the captured values.
2. **Your webhook endpoint** to **SignatureAPI**: Get the envelope `GET /v1/envelopes/{envelope_id}`
3. **SignatureAPI** to **Your webhook endpoint**: Envelope with `captures` and `metadata`
4. **Your webhook endpoint** to **Your database**: Save the record
   Upsert by envelope ID, so a redelivered event writes the same row again instead of a duplicate.
5. **Your webhook endpoint** to **SignatureAPI**: Respond `200 OK`

## Step 1: Set Up a Webhook Endpoint

Register a webhook endpoint in the [Dashboard](https://dashboard.signatureapi.com/settings/webhooks) and subscribe to the `envelope.completed` event. See [Set Up Webhooks](https://signatureapi.com/docs/api/guides/how-to/set-up-webhooks) for detailed instructions.

## Step 2: Create an Envelope with Captures

When creating the envelope, use `capture_as` on interactive places to store values entered by the signer. Also use `metadata` to attach your own identifiers for matching the envelope back to your records.

```http
POST /v1/envelopes HTTP/1.1
Host: api.signatureapi.com
X-API-Key: YOUR_API_KEY
Content-Type: application/json

{
  "title": "Order Confirmation",
  "metadata": {
    "order_id": "ORD-2026-1234",
    "customer_id": "cust_5678"
  },
  "documents": [
    {
      "url": "https://pub-9cb75390636c4a8a83a6f76da33d7f45.r2.dev/privacy-placeholder.pdf",
      "format": "pdf",
      "fixed_positions": [
        {
          "place_key": "reference_number",
          "page": 2,
          "top": 600,
          "left": 72
        }
      ],
      "places": [
        {
          "key": "signer_signs_here",
          "type": "signature",
          "recipient_key": "customer"
        },
        {
          "key": "reference_number",
          "type": "text_input",
          "recipient_key": "customer",
          "hint": "Your 8-digit reference code",
          "capture_as": "reference",
          "width": 200
        }
      ]
    }
  ],
  "recipients": [
    {
      "type": "signer",
      "key": "customer",
      "name": "Jane Doe",
      "email": "jane.doe@example.com"
    }
  ]
}
```

The signature sits on the document's `[[signer_signs_here]]` placeholder. The text input has no placeholder, so it gets a fixed position below the signature on page 2.

## Step 3: Handle the Webhook Event

When the envelope completes, SignatureAPI sends an `envelope.completed` event to your endpoint:

```json
{
  "id": "evt_4GpGD1cNnrkemsTLAvPW9G",
  "type": "envelope.completed",
  "timestamp": "2026-11-02T15:21:40.000Z",
  "data": {
    "object_id": "eb4cf433-a8af-4161-b37b-7ef57d423e56",
    "object_type": "envelope",
    "envelope_id": "eb4cf433-a8af-4161-b37b-7ef57d423e56",
    "envelope_metadata": {
      "order_id": "ORD-2026-1234",
      "customer_id": "cust_5678"
    }
  }
}
```

The `envelope_metadata` property reflects the metadata you attached when creating the envelope. You can use these values to match the event to your internal records without making an additional API call.

## Step 4: Retrieve the Envelope

If you need data beyond what the webhook event provides (such as captured input from the signer), use the `envelope_id` from the event to fetch the full envelope.

```http
GET /v1/envelopes/eb4cf433-a8af-4161-b37b-7ef57d423e56 HTTP/1.1
Host: api.signatureapi.com
X-API-Key: YOUR_API_KEY
```

The response is the full [envelope](https://signatureapi.com/docs/api/resources/envelopes/object). Trimmed to the fields this guide uses, it looks like this:

```json 200 OK
{
  "id": "eb4cf433-a8af-4161-b37b-7ef57d423e56",
  "title": "Order Confirmation",
  "status": "completed",
  "metadata": {
    "order_id": "ORD-2026-1234",
    "customer_id": "cust_5678"
  },
  "captures": {
    "reference": "11223344"
  },
  "completed_at": "2026-11-02T15:21:40.000Z"
}
```

The `captures` object contains any values the signer entered in interactive places that had `capture_as` defined.

## Step 5: Store the Data

With the envelope details and captures in hand, persist the data to your database. Verify the webhook first, against the raw body and the `webhook-*` headers (see [Verify the Signature](https://signatureapi.com/docs/api/guides/how-to/set-up-webhooks#verify-the-signature)). This example uses Express and the Standard Webhooks library:

```javascript
import express from "express";
import { Webhook } from "standardwebhooks";

const app = express();
const wh = new Webhook(process.env.SIGNATUREAPI_WEBHOOK_SECRET);

app.post("/webhooks/signatureapi", express.raw({ type: "application/json" }), async (req, res) => {
  let event;
  try {
    event = wh.verify(req.body.toString("utf8"), {
      "webhook-id": req.header("webhook-id"),
      "webhook-timestamp": req.header("webhook-timestamp"),
      "webhook-signature": req.header("webhook-signature"),
    });
  } catch {
    return res.status(400).send("Invalid signature");
  }

  if (event.type === "envelope.completed") {
    // Fetch the full envelope to get captures
    const response = await fetch(
      `https://api.signatureapi.com/v1/envelopes/${event.data.envelope_id}`,
      { headers: { "X-API-Key": process.env.SIGNATUREAPI_KEY } }
    );
    if (!response.ok) return res.status(500).send("Retry later"); // SignatureAPI retries the event
    const envelope = await response.json();

    // Upsert by envelope ID: a redelivered event writes the same row again
    await db.signingRecords.upsert({
      envelope_id: envelope.id,
      order_id: envelope.metadata.order_id,
      customer_id: envelope.metadata.customer_id,
      reference: envelope.captures.reference,
      completed_at: envelope.completed_at
    });
  }

  res.status(200).send("OK");
});
```

`db.signingRecords.upsert` stands for your own database client.

## Try It

Send the request with your [test API key](https://signatureapi.com/docs/api/test-mode) to create a free, non-binding test envelope, for example from the [API Playground](https://signatureapi.com/docs/api/playground). Sign it from the email preview in the Dashboard, then read `captures` with `GET /v1/envelopes/{envelope_id}`.

## Keep Learning

- Learn more about [captures](https://signatureapi.com/docs/api/resources/envelopes/captures) and which place types support them.
- Set up [webhooks](https://signatureapi.com/docs/api/guides/how-to/set-up-webhooks) with signature verification and retry handling.
- Use [topics](https://signatureapi.com/docs/api/resources/envelopes/topics) to route events from specific envelopes to different webhook endpoints.
- [Download signed documents](https://signatureapi.com/docs/api/guides/use-cases/save-signed-documents) after the envelope completes.
