> 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/send-envelope.md). Agents can also search and read this documentation through its [MCP server](https://developers.docstudio.com/~gitbook/mcp).

# Send Envelope

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

### Endpoint

| Method | Endpoint                |
| ------ | ----------------------- |
| `POST` | `/api/v1/envelope/send` |

### Headers

| Header          | Required | Description                |
| --------------- | -------- | -------------------------- |
| `Authorization` | Yes      | Bearer authorization token |
| `Content-Type`  | Yes      | `application/json`         |
| `Mailbox`       | Yes      | UUID of the sender mailbox |

Use a token with access to the sender mailbox.

### Request body

<table><thead><tr><th width="181">Field</th><th width="128">Type</th><th width="100">Required</th><th>Description</th></tr></thead><tbody><tr><td><code>uuid</code></td><td>UUID</td><td>No</td><td>Predefined envelope UUID</td></tr><tr><td><code>data</code></td><td>string</td><td>Yes</td><td>Envelope XML serialized as a JSON string</td></tr><tr><td><code>metadata</code></td><td>object</td><td>No</td><td>Custom envelope metadata</td></tr></tbody></table>

#### Envelope XML

Use identifiers from the same template version.

<table><thead><tr><th width="313.4444580078125">Envelope value</th><th>Source</th></tr></thead><tbody><tr><td><code>envelope/@templateUuid</code></td><td>Template UUID</td></tr><tr><td><code>envelope/@templateVersion</code></td><td>Template version UUID</td></tr><tr><td><code>role/@id</code></td><td>Role ID from the template flow</td></tr><tr><td><code>role/@mailboxUuid</code></td><td>Recipient mailbox UUID</td></tr><tr><td><code>document/@id</code></td><td>Document ID from the selected template version</td></tr><tr><td><code>field/@name</code></td><td>Exact field name from the selected template version</td></tr></tbody></table>

Example envelope XML:

```xml
<envelope
  templateUuid="{templateUuid}"
  templateVersion="{templateVersion}"
>
  <info>
    <subject>Sales agreement</subject>
    <message>Please review and complete the agreement.</message>
  </info>

  <flow>
    <roles>
      <role
        id="{roleId}"
        mailboxUuid="{recipientMailboxUuid}"
      />
    </roles>
  </flow>

  <documents>
    <document id="{documentId}">
      <field name="Customer name">ACME Ltd</field>
      <field name="Contract amount">1250.50</field>
    </document>
  </documents>
</envelope>
```

### Optional request fields

#### uuid

Set `uuid` when the integration assigns the envelope UUID.

```json
{
  "uuid": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
  "data": "{envelopeXml}"
}
```

#### metadata

Set `metadata` to store custom envelope data.

```json
{
  "data": "{envelopeXml}",
  "metadata": {
    "customerId": "C-1024",
    "crmRecordId": "CRM-77551",
    "priority": true
  }
}
```

### Request example

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

```javascript
const payload = {
  data: "{envelopeXml}"
};

const response = await fetch(
  "https://api.docstudio.com/api/v1/envelope/send",
  {
    method: "POST",
    headers: {
      Authorization: "Bearer {token}",
      Mailbox: "{senderMailboxUuid}",
      "Content-Type": "application/json"
    },
    body: JSON.stringify(payload)
  }
);

const body = await response.text();

if (!response.ok) {
  throw new Error(
    `Request failed: ${response.status}\n${body}`
  );
}

console.log(body);
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

$payload = [
    "data" => "{envelopeXml}"
];

$curl = curl_init(
    "https://api.docstudio.com/api/v1/envelope/send"
);

curl_setopt_array($curl, [
    CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => [
        "Authorization: Bearer {token}",
        "Mailbox: {senderMailboxUuid}",
        "Content-Type: application/json"
    ],
    CURLOPT_POSTFIELDS => json_encode($payload),
    CURLOPT_RETURNTRANSFER => true
]);

$body = curl_exec($curl);

if ($body === false) {
    throw new RuntimeException(curl_error($curl));
}

$status = curl_getinfo(
    $curl,
    CURLINFO_RESPONSE_CODE
);

curl_close($curl);

if ($status < 200 || $status >= 300) {
    throw new RuntimeException(
        "Request failed: {$status}\n{$body}"
    );
}

echo $body;
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

response = requests.post(
    "https://api.docstudio.com/api/v1/envelope/send",
    headers={
        "Authorization": "Bearer {token}",
        "Mailbox": "{senderMailboxUuid}",
    },
    json={
        "data": "{envelopeXml}",
    },
    timeout=30,
)

response.raise_for_status()
print(response.json())
```

{% endtab %}

{% tab title="Ruby" %}

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

uri = URI(
  "https://api.docstudio.com/api/v1/envelope/send"
)

payload = {
  data: "{envelopeXml}"
}

request = Net::HTTP::Post.new(uri)
request["Authorization"] = "Bearer {token}"
request["Mailbox"] = "{senderMailboxUuid}"
request["Content-Type"] = "application/json"
request.body = JSON.generate(payload)

response = Net::HTTP.start(
  uri.hostname,
  uri.port,
  use_ssl: true
) do |http|
  http.request(request)
end

unless response.is_a?(Net::HTTPSuccess)
  raise "Request failed: #{response.code}\n#{response.body}"
end

puts response.body
```

{% endtab %}

{% tab title="Go" %}

```go
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"net/http"
)

func main() {
	payload := map[string]string{
		"data": "{envelopeXml}",
	}

	requestBody, err := json.Marshal(payload)
	if err != nil {
		panic(err)
	}

	request, err := http.NewRequest(
		http.MethodPost,
		"https://api.docstudio.com/api/v1/envelope/send",
		bytes.NewReader(requestBody),
	)
	if err != nil {
		panic(err)
	}

	request.Header.Set(
		"Authorization",
		"Bearer {token}",
	)
	request.Header.Set(
		"Mailbox",
		"{senderMailboxUuid}",
	)
	request.Header.Set(
		"Content-Type",
		"application/json",
	)

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

	body, err := io.ReadAll(response.Body)
	if err != nil {
		panic(err)
	}

	if response.StatusCode < 200 ||
		response.StatusCode >= 300 {
		panic(fmt.Sprintf(
			"Request failed: %s\n%s",
			response.Status,
			body,
		))
	}

	fmt.Println(string(body))
}
```

{% 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 Main {
  public static void main(String[] args) throws Exception {
    String payload = """
        {
          "data": "{envelopeXml}"
        }
        """;

    HttpRequest request = HttpRequest.newBuilder()
        .uri(URI.create(
            "https://api.docstudio.com/api/v1/envelope/send"
        ))
        .header(
            "Authorization",
            "Bearer {token}"
        )
        .header(
            "Mailbox",
            "{senderMailboxUuid}"
        )
        .header(
            "Content-Type",
            "application/json"
        )
        .POST(
            HttpRequest.BodyPublishers.ofString(payload)
        )
        .build();

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

    if (response.statusCode() < 200 ||
        response.statusCode() >= 300) {
      throw new RuntimeException(
          "Request failed: " +
          response.statusCode() +
          "\n" +
          response.body()
      );
    }

    System.out.println(response.body());
  }
}
```

{% endtab %}

{% tab title=".NET" %}

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

using var client = new HttpClient();

var payload = new
{
    data = "{envelopeXml}"
};

using var request = new HttpRequestMessage(
    HttpMethod.Post,
    "https://api.docstudio.com/api/v1/envelope/send"
);

request.Headers.Authorization =
    new AuthenticationHeaderValue(
        "Bearer",
        "{token}"
    );

request.Headers.Add(
    "Mailbox",
    "{senderMailboxUuid}"
);

request.Content = new StringContent(
    JsonSerializer.Serialize(payload),
    Encoding.UTF8,
    "application/json"
);

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

var body =
    await response.Content.ReadAsStringAsync();

if (!response.IsSuccessStatusCode)
{
    throw new HttpRequestException(
        $"Request failed: " +
        $"{(int)response.StatusCode}\n{body}"
    );
}

Console.WriteLine(body);
```

{% endtab %}

{% tab title="cURL" %}

```bash
curl --request POST \
  --url 'https://api.docstudio.com/api/v1/envelope/send' \
  --header 'Authorization: Bearer {token}' \
  --header 'Mailbox: {senderMailboxUuid}' \
  --header 'Content-Type: application/json' \
  --data '{
    "data": "{envelopeXml}"
  }'
```

{% endtab %}
{% endtabs %}

### Response

The endpoint returns `201 Created` and the UUID of the created envelope.

| Field  | Type | Description                  |
| ------ | ---- | ---------------------------- |
| `uuid` | UUID | UUID of the created envelope |

```json
{
  "uuid": "89499ba2-287d-404c-87b0-342dc5b01b6a"
}
```

### Status codes

<table><thead><tr><th width="159">Code</th><th>Description</th></tr></thead><tbody><tr><td><code>201</code></td><td>Envelope created and sent successfully</td></tr><tr><td><code>400</code></td><td>Invalid request headers, JSON body, envelope XML, or reusable identifiers</td></tr><tr><td><code>401</code></td><td>Missing, invalid, or expired authorization token</td></tr><tr><td><code>403</code></td><td>No permission to send envelopes from the specified mailbox</td></tr></tbody></table>

### Related topics

{% columns %}
{% column %}

* [Send your first envelope](https://developers.docstudio.com/introduction/send-your-first-envelope.md)
* [XML payloads](https://developers.docstudio.com/guides/xml-payloads.md)
* [Templates and reusable IDs](https://developers.docstudio.com/guides/templates-and-reusable-ids.md)
* [Envelope fields](https://developers.docstudio.com/guides/envelope-fields.md)
* [Envelope metadata](https://developers.docstudio.com/guides/envelope-metadata.md)
  {% endcolumn %}

{% column %}

* [Upload Attachments](https://developers.docstudio.com/api-reference/upload-attachments.md)
* [Fill Envelope](https://developers.docstudio.com/api-reference/fill-envelope.md)
* [Check Envelope Status](https://developers.docstudio.com/api-reference/check-envelope-status.md)
* [Error handling and API error codes](https://developers.docstudio.com/error-codes/error-handling-and-api-error-codes.md)
  {% endcolumn %}
  {% endcolumns %}
