> For the complete documentation index, see [llms.txt](https://developers.docstudio.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.docstudio.com/api-reference/fill-envelope.md).

# Fill Envelope

This document contains details for the /api/v1/envelope/fill endpoint, including headers, request body, response, and status codes.

### Endpoint

| Method | Endpoint                |
| ------ | ----------------------- |
| `PUT`  | `/api/v1/envelope/fill` |

### Headers

<table><thead><tr><th width="165">Header</th><th width="253">Required</th><th>Description</th></tr></thead><tbody><tr><td><code>Authorization</code></td><td>Yes</td><td>Bearer authorization token</td></tr><tr><td><code>Content-Type</code></td><td>Yes</td><td><code>application/json</code></td></tr><tr><td><code>Mailbox</code></td><td>Yes</td><td>UUID of the mailbox filling the envelope</td></tr></tbody></table>

### Request body

<table><thead><tr><th width="81">Field</th><th width="82">Type</th><th width="198">Required</th><th>Description</th></tr></thead><tbody><tr><td><code>uuid</code></td><td>UUID</td><td>Yes</td><td>UUID of the envelope to fill</td></tr><tr><td><code>data</code></td><td>string</td><td>Yes</td><td>Envelope XML containing the field values</td></tr></tbody></table>

#### Envelope XML

```xml
<envelope
  templateUuid="500afafd-711e-471a-a18f-24a89cd4ede3"
  templateVersion="143a2a4b-325e-4c05-a4c1-52f44e21b745"
>
  <documents>
    <document id="ef247568-559a-4ec1-9ecc-6b44c9fb8215">
      <field name="Customer name">ACME Ltd</field>
      <field name="Contract amount">1000.00</field>
    </document>
  </documents>
</envelope>
```

{% hint style="warning" %}
Use document IDs and field names from the envelope template version.
{% endhint %}

### Request example

{% tabs %}
{% tab title="Node.js" %}

```javascript
const response = await fetch(
  "https://{baseUrl}/api/v1/envelope/fill",
  {
    method: "PUT",
    headers: {
      Authorization: "Bearer {token}",
      "Content-Type": "application/json",
      Mailbox: "42c95245-30c1-46ef-bd5b-a9a111deec10"
    },
    body: JSON.stringify({
      uuid: "89499ba2-287d-404c-87b0-342dc5b01b6a",
      data: "{envelopeXml}"
    })
  }
);
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

$client = curl_init("https://{baseUrl}/api/v1/envelope/fill");

curl_setopt_array($client, [
    CURLOPT_CUSTOMREQUEST => "PUT",
    CURLOPT_POSTFIELDS => json_encode([
        "uuid" => "89499ba2-287d-404c-87b0-342dc5b01b6a",
        "data" => "{envelopeXml}"
    ]),
    CURLOPT_HTTPHEADER => [
        "Authorization: Bearer {token}",
        "Content-Type: application/json",
        "Mailbox: 42c95245-30c1-46ef-bd5b-a9a111deec10"
    ],
    CURLOPT_RETURNTRANSFER => true
]);

$response = curl_exec($client);
curl_close($client);
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

response = requests.put(
    "https://{baseUrl}/api/v1/envelope/fill",
    headers={
        "Authorization": "Bearer {token}",
        "Mailbox": "42c95245-30c1-46ef-bd5b-a9a111deec10"
    },
    json={
        "uuid": "89499ba2-287d-404c-87b0-342dc5b01b6a",
        "data": "{envelopeXml}"
    }
)
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
require "json"
require "net/http"

uri = URI("https://{baseUrl}/api/v1/envelope/fill")
request = Net::HTTP::Put.new(
  uri,
  {
    "Authorization" => "Bearer {token}",
    "Content-Type" => "application/json",
    "Mailbox" => "42c95245-30c1-46ef-bd5b-a9a111deec10"
  }
)
request.body = {
  uuid: "89499ba2-287d-404c-87b0-342dc5b01b6a",
  data: "{envelopeXml}"
}.to_json

response = Net::HTTP.start(
  uri.hostname,
  uri.port,
  use_ssl: uri.scheme == "https"
) { |http| http.request(request) }
```

{% endtab %}

{% tab title="Go" %}

```go
package main

import (
    "bytes"
    "log"
    "net/http"
)

func main() {
    body := bytes.NewBufferString(`
{
  "uuid": "89499ba2-287d-404c-87b0-342dc5b01b6a",
  "data": "{envelopeXml}"
}`)

    request, err := http.NewRequest(
        http.MethodPut,
        "https://{baseUrl}/api/v1/envelope/fill",
        body,
    )
    if err != nil {
        log.Fatal(err)
    }

    request.Header.Set("Authorization", "Bearer {token}")
    request.Header.Set("Content-Type", "application/json")
    request.Header.Set("Mailbox", "42c95245-30c1-46ef-bd5b-a9a111deec10")

    response, err := http.DefaultClient.Do(request)
    if err != nil {
        log.Fatal(err)
    }
    defer response.Body.Close()
}
```

{% endtab %}

{% tab title="Java" %}

```java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class FillEnvelope {
    public static void main(String[] args) throws Exception {
        String body = """
            {
              "uuid": "89499ba2-287d-404c-87b0-342dc5b01b6a",
              "data": "{envelopeXml}"
            }
            """;

        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://{baseUrl}/api/v1/envelope/fill"))
            .header("Authorization", "Bearer {token}")
            .header("Content-Type", "application/json")
            .header("Mailbox", "42c95245-30c1-46ef-bd5b-a9a111deec10")
            .PUT(HttpRequest.BodyPublishers.ofString(body))
            .build();

        HttpResponse<String> response = HttpClient.newHttpClient().send(
            request,
            HttpResponse.BodyHandlers.ofString()
        );
    }
}
```

{% endtab %}

{% tab title=".NET" %}

```csharp
using System.Net.Http.Headers;
using System.Net.Http.Json;

using var client = new HttpClient();
using var request = new HttpRequestMessage(
    HttpMethod.Put,
    "https://{baseUrl}/api/v1/envelope/fill"
)
{
    Content = JsonContent.Create(new
    {
        uuid = "89499ba2-287d-404c-87b0-342dc5b01b6a",
        data = "{envelopeXml}"
    })
};

request.Headers.Authorization = new AuthenticationHeaderValue(
    "Bearer",
    "{token}"
);
request.Headers.Add("Mailbox", "42c95245-30c1-46ef-bd5b-a9a111deec10");

using var response = await client.SendAsync(request);
```

{% endtab %}

{% tab title="cURL" %}

```bash
curl --request PUT \
  "https://{baseUrl}/api/v1/envelope/fill" \
  --header "Authorization: Bearer {token}" \
  --header "Content-Type: application/json" \
  --header "Mailbox: 42c95245-30c1-46ef-bd5b-a9a111deec10" \
  --data '{
    "uuid": "89499ba2-287d-404c-87b0-342dc5b01b6a",
    "data": "{envelopeXml}"
  }'
```

{% endtab %}
{% endtabs %}

### Response

The endpoint returns `200 OK` after updating the field values.

### Status codes

| Code  | Description                 |
| ----- | --------------------------- |
| `200` | Fields updated successfully |

### Related topics

* [Working with XML payloads](/guides/xml-payloads.md)
* [Envelope fields](/guides/envelope-fields.md)
* [Error handling and API error codes](/error-codes/error-handling-and-api-error-codes.md)
