Create a draft
curl --request POST \
--url https://{dsn}/api/v1/drafts \
--header 'Content-Type: application/json' \
--header 'X-API-KEY: <api-key>' \
--data '
{
"account_id": "acc_ba1fa6938d8548298e8ce62e4b4b4e99",
"to": [
{
"identifier": "ana@example.com"
}
],
"subject": "Draft proposal",
"body": "<p>First version</p>"
}
'import requests
url = "https://{dsn}/api/v1/drafts"
payload = {
"account_id": "acc_ba1fa6938d8548298e8ce62e4b4b4e99",
"to": [{ "identifier": "ana@example.com" }],
"subject": "Draft proposal",
"body": "<p>First version</p>"
}
headers = {
"X-API-KEY": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-API-KEY': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
account_id: 'acc_ba1fa6938d8548298e8ce62e4b4b4e99',
to: [{identifier: 'ana@example.com'}],
subject: 'Draft proposal',
body: JSON.stringify('<p>First version</p>')
})
};
fetch('https://{dsn}/api/v1/drafts', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{dsn}/api/v1/drafts",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'account_id' => 'acc_ba1fa6938d8548298e8ce62e4b4b4e99',
'to' => [
[
'identifier' => 'ana@example.com'
]
],
'subject' => 'Draft proposal',
'body' => '<p>First version</p>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-API-KEY: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://{dsn}/api/v1/drafts"
payload := strings.NewReader("{\n \"account_id\": \"acc_ba1fa6938d8548298e8ce62e4b4b4e99\",\n \"to\": [\n {\n \"identifier\": \"ana@example.com\"\n }\n ],\n \"subject\": \"Draft proposal\",\n \"body\": \"<p>First version</p>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-API-KEY", "<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(string(body))
}HttpResponse<String> response = Unirest.post("https://{dsn}/api/v1/drafts")
.header("X-API-KEY", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"account_id\": \"acc_ba1fa6938d8548298e8ce62e4b4b4e99\",\n \"to\": [\n {\n \"identifier\": \"ana@example.com\"\n }\n ],\n \"subject\": \"Draft proposal\",\n \"body\": \"<p>First version</p>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{dsn}/api/v1/drafts")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-API-KEY"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"account_id\": \"acc_ba1fa6938d8548298e8ce62e4b4b4e99\",\n \"to\": [\n {\n \"identifier\": \"ana@example.com\"\n }\n ],\n \"subject\": \"Draft proposal\",\n \"body\": \"<p>First version</p>\"\n}"
response = http.request(request)
puts response.read_body{
"object": "DraftCreated",
"account_id": "acc_ba1fa6938d8548298e8ce62e4b4b4e99",
"draft_id": "drf_AAMkAGI2THVSAAA=",
"message_id": "5b1c2d3e4f6a47b8@mail-api.example.com",
"tracking_id": null
}{
"status": 400,
"type": "errors/invalid_parameters",
"title": "Invalid parameters",
"detail": "limit must be between 1 and 250"
}{
"status": 401,
"type": "errors/invalid_credentials",
"title": "Invalid credentials",
"detail": "the mail provider rejected the credentials: invalid_grant"
}{
"status": 502,
"type": "errors/provider_error",
"title": "Mail provider error",
"detail": "timed out talking to imap.example.com"
}Drafts
Create a draft
Saves a draft in the user’s Drafts folder. Same fields as Send an email; recipients are optional. An email.draft.new event follows when it syncs.
POST
/
drafts
Create a draft
curl --request POST \
--url https://{dsn}/api/v1/drafts \
--header 'Content-Type: application/json' \
--header 'X-API-KEY: <api-key>' \
--data '
{
"account_id": "acc_ba1fa6938d8548298e8ce62e4b4b4e99",
"to": [
{
"identifier": "ana@example.com"
}
],
"subject": "Draft proposal",
"body": "<p>First version</p>"
}
'import requests
url = "https://{dsn}/api/v1/drafts"
payload = {
"account_id": "acc_ba1fa6938d8548298e8ce62e4b4b4e99",
"to": [{ "identifier": "ana@example.com" }],
"subject": "Draft proposal",
"body": "<p>First version</p>"
}
headers = {
"X-API-KEY": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-API-KEY': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
account_id: 'acc_ba1fa6938d8548298e8ce62e4b4b4e99',
to: [{identifier: 'ana@example.com'}],
subject: 'Draft proposal',
body: JSON.stringify('<p>First version</p>')
})
};
fetch('https://{dsn}/api/v1/drafts', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{dsn}/api/v1/drafts",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'account_id' => 'acc_ba1fa6938d8548298e8ce62e4b4b4e99',
'to' => [
[
'identifier' => 'ana@example.com'
]
],
'subject' => 'Draft proposal',
'body' => '<p>First version</p>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-API-KEY: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://{dsn}/api/v1/drafts"
payload := strings.NewReader("{\n \"account_id\": \"acc_ba1fa6938d8548298e8ce62e4b4b4e99\",\n \"to\": [\n {\n \"identifier\": \"ana@example.com\"\n }\n ],\n \"subject\": \"Draft proposal\",\n \"body\": \"<p>First version</p>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-API-KEY", "<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(string(body))
}HttpResponse<String> response = Unirest.post("https://{dsn}/api/v1/drafts")
.header("X-API-KEY", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"account_id\": \"acc_ba1fa6938d8548298e8ce62e4b4b4e99\",\n \"to\": [\n {\n \"identifier\": \"ana@example.com\"\n }\n ],\n \"subject\": \"Draft proposal\",\n \"body\": \"<p>First version</p>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{dsn}/api/v1/drafts")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-API-KEY"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"account_id\": \"acc_ba1fa6938d8548298e8ce62e4b4b4e99\",\n \"to\": [\n {\n \"identifier\": \"ana@example.com\"\n }\n ],\n \"subject\": \"Draft proposal\",\n \"body\": \"<p>First version</p>\"\n}"
response = http.request(request)
puts response.read_body{
"object": "DraftCreated",
"account_id": "acc_ba1fa6938d8548298e8ce62e4b4b4e99",
"draft_id": "drf_AAMkAGI2THVSAAA=",
"message_id": "5b1c2d3e4f6a47b8@mail-api.example.com",
"tracking_id": null
}{
"status": 400,
"type": "errors/invalid_parameters",
"title": "Invalid parameters",
"detail": "limit must be between 1 and 250"
}{
"status": 401,
"type": "errors/invalid_credentials",
"title": "Invalid credentials",
"detail": "the mail provider rejected the credentials: invalid_grant"
}{
"status": 502,
"type": "errors/provider_error",
"title": "Mail provider error",
"detail": "timed out talking to imap.example.com"
}Authorizations
Your access token, from your dashboard under API keys.
Body
application/json
The account to send from (acc_…).
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Sender name; identifier can set a send-as alias.
Show child attributes
Show child attributes
Show child attributes
Show child attributes
HTML body.
The email_… id you answer.
X-…, List-Unsubscribe, List-Unsubscribe-Post or Reply-To.
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes