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_idUpdated 3 months ago