> For clean Markdown content of this page, append .md to this URL. For the complete documentation index, see https://docs.postnuvia.com/llms.txt.

# Create Draft

POST https://api.postnuvia.com/v0/inboxes/{inbox_id}/drafts
Content-Type: application/json

Create a draft. Supply `in_reply_to` to create a reply draft (with
`reply_all` to address the whole thread), whose recipients, subject, and
threading are derived from the referenced message, or `forward_of` to
create a forward draft, which derives the subject, threading, and
forwarded content from the source but keeps recipients caller-supplied.

**CLI:**

```bash
postnuvia inboxes drafts create --inbox-id <inbox_id> --to recipient@example.com --subject "Draft subject" --text "Draft body"
```

Reference: https://docs.postnuvia.com/api-reference/inboxes/drafts/create

## Authentication

- `Authorization` header (bearer token, required) — Bearer authentication of the form `Bearer <token>`, where token is your auth token.

## Servers

- `https://api.postnuvia.com` (prod, default)
- `https://x402.api.postnuvia.com` (prod-x402)
- `https://mpp.api.postnuvia.com` (prod-mpp)
- `https://api.postnuvia.eu` (eu-prod)

## Request

### Path parameters

- `inbox_id` (string, required) — The ID of the inbox.

### Body (application/json)

This endpoint expects a CreateDraftRequest.

- `labels` (list of string, optional) — Labels of draft.
- `reply_to` (list of string, optional) — Reply-to addresses. In format `username@domain.com` or `Display Name <username@domain.com>`.
- `to` (list of string, optional) — Addresses of recipients. In format `username@domain.com` or `Display Name <username@domain.com>`.
- `cc` (list of string, optional) — Addresses of CC recipients. In format `username@domain.com` or `Display Name <username@domain.com>`.
- `bcc` (list of string, optional) — Addresses of BCC recipients. In format `username@domain.com` or `Display Name <username@domain.com>`.
- `subject` (string, optional) — Subject of draft.
- `text` (string, optional) — Plain text body of draft.
- `html` (string, optional) — HTML body of draft.
- `attachments` (list of SendAttachment, optional) — Attachments to include in draft.
- `in_reply_to` (string, optional) — ID of message being replied to.
- `forward_of` (string, optional) — ID of message being forwarded.
- `reply_all` (boolean, optional) — Reply to all recipients of the original message.
- `send_at` (datetime, optional) — Time at which to schedule send draft.
- `client_id` (string, optional) — Client ID of draft.

## Response

### 200

- `inbox_id` (string, required) — The ID of the inbox.
- `draft_id` (string, required) — ID of draft.
- `labels` (list of string, required) — Labels of draft.
- `updated_at` (datetime, required) — Time at which draft was last updated.
- `created_at` (datetime, required) — Time at which draft was created.
- `client_id` (string, optional) — Client ID of draft.
- `reply_to` (list of string, optional) — Reply-to addresses. In format `username@domain.com` or `Display Name <username@domain.com>`.
- `to` (list of string, optional) — Addresses of recipients. In format `username@domain.com` or `Display Name <username@domain.com>`.
- `cc` (list of string, optional) — Addresses of CC recipients. In format `username@domain.com` or `Display Name <username@domain.com>`.
- `bcc` (list of string, optional) — Addresses of BCC recipients. In format `username@domain.com` or `Display Name <username@domain.com>`.
- `subject` (string, optional) — Subject of draft.
- `preview` (string, optional) — Text preview of draft.
- `text` (string, optional) — Plain text body of draft.
- `html` (string, optional) — HTML body of draft.
- `attachments` (list of Attachment, optional) — Attachments in draft.
- `in_reply_to` (string, optional) — ID of message being replied to.
- `forward_of` (string, optional) — ID of message being forwarded.
- `references` (list of string, optional) — IDs of previous messages in thread.
- `send_status` (enum, optional) — Schedule send status of draft.
  - Allowed values: `scheduled`, `sending`, `failed`
- `send_at` (datetime, optional) — Time at which to schedule send draft.

## Errors

### 400 Validation Error

- `name` (string, required) — Name of error.
- `errors` (any, required) — Validation errors. Each entry has a path and a message identifying the invalid field.
- `code` (string, optional) — Stable, machine-readable error code in snake_case (for example, not_found or missing_permission). Branch on this rather than the message text.
- `message` (string, optional) — Error message.
- `fix` (string, optional) — The concrete next action that resolves the error.
- `docs` (string, optional) — Link to the error reference entry for this code.

### 404 Not Found Error

- `name` (string, required) — Name of error.
- `message` (string, required) — Error message.
- `code` (string, optional) — Stable, machine-readable error code in snake_case (for example, not_found or missing_permission). Branch on this rather than the message text.
- `fix` (string, optional) — The concrete next action that resolves the error.
- `docs` (string, optional) — Link to the error reference entry for this code.

## Types

### SendAttachment

Provide either `content` or `url` for each attachment.

- `filename` (string, optional) — Filename of attachment.
- `content_type` (string, optional) — Content type of attachment.
- `content_disposition` (enum, optional) — Content disposition of attachment.
  - Allowed values: `inline`, `attachment`
- `content_id` (string, optional) — Content ID of attachment.
- `content` (string, optional) — Base64 encoded content of the attachment. The entire request, including the message body and all attachments, is limited to 6 MB.
- `url` (string, optional) — URL that PostNuvia can download without custom authentication headers or cookies. Redirects and pre-signed URLs are supported, and the final response must be a successful 2xx response. Keep URL-backed attachments around 30 MB total per message.

### Attachment

- `attachment_id` (string, required) — ID of attachment.
- `size` (integer, required) — Size of attachment in bytes.
- `filename` (string, optional) — Filename of attachment.
- `content_type` (string, optional) — Content type of attachment.
- `content_disposition` (enum, optional) — Content disposition of attachment.
  - Allowed values: `inline`, `attachment`
- `content_id` (string, optional) — Content ID of attachment.

## Examples

**Request**

```json
{}
```

**Response**

```json
{
  "inbox_id": "inbox_id",
  "draft_id": "draft_id",
  "labels": [
    "labels",
    "labels"
  ],
  "updated_at": "2024-01-15T09:30:00Z",
  "created_at": "2024-01-15T09:30:00Z",
  "client_id": "client_id",
  "reply_to": [
    "reply_to",
    "reply_to"
  ],
  "to": [
    "to",
    "to"
  ],
  "cc": [
    "cc",
    "cc"
  ],
  "bcc": [
    "bcc",
    "bcc"
  ],
  "subject": "subject",
  "preview": "preview",
  "text": "text",
  "html": "html",
  "attachments": [
    {
      "attachment_id": "attachment_id",
      "size": 1,
      "filename": "filename",
      "content_type": "content_type",
      "content_disposition": "inline",
      "content_id": "content_id"
    },
    {
      "attachment_id": "attachment_id",
      "size": 1,
      "filename": "filename",
      "content_type": "content_type",
      "content_disposition": "inline",
      "content_id": "content_id"
    }
  ],
  "in_reply_to": "in_reply_to",
  "forward_of": "forward_of",
  "references": [
    "references",
    "references"
  ],
  "send_status": "scheduled",
  "send_at": "2024-01-15T09:30:00Z"
}
```

**SDK Code**

```python
import requests

url = "https://api.postnuvia.com/v0/inboxes/inbox_id/drafts"

payload = {}
headers = {
    "Authorization": "Bearer <api_key>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api.postnuvia.com/v0/inboxes/inbox_id/drafts';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <api_key>', 'Content-Type': 'application/json'},
  body: '{}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.postnuvia.com/v0/inboxes/inbox_id/drafts"

	payload := strings.NewReader("{}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <api_key>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.postnuvia.com/v0/inboxes/inbox_id/drafts")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <api_key>'
request["Content-Type"] = 'application/json'
request.body = "{}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.postnuvia.com/v0/inboxes/inbox_id/drafts")
  .header("Authorization", "Bearer <api_key>")
  .header("Content-Type", "application/json")
  .body("{}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.postnuvia.com/v0/inboxes/inbox_id/drafts', [
  'body' => '{}',
  'headers' => [
    'Authorization' => 'Bearer <api_key>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.postnuvia.com/v0/inboxes/inbox_id/drafts");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <api_key>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <api_key>",
  "Content-Type": "application/json"
]
let parameters = [] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.postnuvia.com/v0/inboxes/inbox_id/drafts")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```