Manage drafts
Learn how to manage email drafts using Unipile API.
Drafts are not so different from emails messages, and you can theoretically use Emails methods on messages placed in the folder with the \Draft special-use. But we recommend using the following endpoints instead : they ensures the message is handled for the provider’s correct draft location and respects provider-specific drafting behavior.
List drafts
To list all Drafts, use the List all Drafts method.
const { data } = await emailsApi.getDraftsList({
path: {
account_id: "acc_123456789",
},
query: {
limit: 20,
},
});drafts = emails_api.get_drafts_list(
"acc_123456789",
limit=20,
)curl --request GET \
--url https://api.unipile.com/v2/account_id/drafts \
--header 'accept: application/json'Get a draft
To get a specific Draft, use Get a Draft and provide its ID.
const { data } = await emailsApi.getDraft({
path: {
account_id: "acc_123456789",
draft_id: "draft_id",
},
});draft = emails_api.get_draft("acc_123456789", "draft_id")curl --request GET \
--url https://api.unipile.com/v2/account_id/drafts/draft_id \
--header 'accept: application/json'Edit a draft
To edit the content of a Draft, use the Update a Draft method and provide updated values. Any parameters not provided will be left unchanged.
const { data } = await emailsApi.updateDraft({
path: {
account_id: "acc_123456789",
draft_id: "draft_id",
},
body: {
subject: 'New subject',
},
});draft = emails_api.update_draft(
"acc_123456789",
"draft_id",
{"subject": "New subject"},
)curl --request PATCH \
--url https://api.unipile.com/v2/account_id/drafts/draft_id \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--data '
{
"subject": "New subject"
}
'Delete a draft
To delete a Draft permanently, use Delete a Draft.
Note that drafts are automatically deleted when they are sent.
await emailsApi.deleteDraft({
path: {
account_id: "acc_123456789",
draft_id: "draft_id",
},
});emails_api.delete_draft("acc_123456789", "draft_id")curl --request DELETE \
--url https://api.unipile.com/v2/account_id/drafts/draft_idCreate and send a reply draft
Use Create a Draft to prepare a new message or a reply before sending it with Send a Draft. To reply in an existing conversation, set reply_to_message_id:
- Gmail and Outlook: use the provider message ID of the email being replied to.
- IMAP: use the original email's RFC822
Message-IDheader.
reply_to sets the email's Reply-To address header; it does not identify a message to reply to.
Outlook creates a native reply draft in the original conversation. If you omit the content, Outlook preserves the quoted body; supplying content replaces it. Each Outlook draft attachment must be smaller than 3 MB. Store the returned draft ID, review or update the draft, and send it using Send a Draft. Do not resend a draft after it has already been sent.
const { data } = await emailsApi.createDraft({
path: {
account_id: "acc_123456789",
},
body: {
to: [
{
email: "[email protected]",
},
],
reply_to_message_id: "original_message_id",
plain_text: "Thanks for your message.",
},
});data = emails_api.create_draft(
account_id='acc_123456789',
create_draft_request={
"to": [
{
"email": '[email protected]'
}
],
"reply_to_message_id": 'original_message_id',
"plain_text": 'Thanks for your message.'
},
)curl --request POST \
--url "https://api.unipile.com/v2/acc_123456789/drafts" \
--header 'X-API-KEY: YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
"to": [
{
"email": "[email protected]"
}
],
"reply_to_message_id": "original_message_id",
"plain_text": "Thanks for your message."
}'Send the reply draft
const { data } = await emailsApi.sendDraft({
path: {
account_id: "acc_123456789",
draft_id: "draft_id",
},
});data = emails_api.send_draft(
account_id='acc_123456789',
draft_id='draft_id',
)curl --request POST \
--url "https://api.unipile.com/v2/acc_123456789/drafts/draft_id/send" \
--header 'X-API-KEY: YOUR_API_KEY'Updated 12 days ago