daimon.email
Api referenceMessages

Delete Message

Soft delete a message from an inbox

Authentication

Requires the inbox's API key in the Authorization header.

Path Parameters

idstringpathrequired

Inbox ID (e.g., inb_abc123)

msgIdstringpathrequired

Message ID to delete (e.g., msg_xyz789)

Request

curl -X DELETE "https://api.daimon.email/v1/inboxes/inb_abc123/messages/msg_xyz789" \
  -H "Authorization: Bearer dm_free_7d8a9b0c1d2e3f4g5h6i7j8k9l0m1n2o"
const client = new DaimonClient({ apiKey: 'dm_free_...' });

const deleted = await client.inboxes.messages.delete('inb_abc123', 'msg_xyz789');

console.log(`Deleted message: ${deleted.id}`);
console.log(`Deleted at: ${deleted.deleted_at}`);
client = DaimonClient(api_key='dm_free_...')

deleted = client.inboxes.messages.delete('inb_abc123', 'msg_xyz789')

print(f"Deleted message: {deleted.id}")
print(f"Deleted at: {deleted.deleted_at}")

Response

Response

{
  "result": {
    "id": "msg_xyz789",
    "deleted_at": "2024-03-11T14:35:20Z"
  },
  "next_steps": [
    "Message soft deleted and hidden from list endpoints",
    "Message can be recovered from database backups if needed",
    "Attachments remain in storage for 30 days"
  ]
}
{
  "error": "MESSAGE_NOT_FOUND",
  "message": "Message msg_xyz789 not found in inbox inb_abc123",
  "next_steps": [
    "Verify the message ID is correct",
    "Check that the message belongs to this inbox"
  ]
}

Response Fields

result.idstring

ID of the deleted message

result.deleted_atstring

ISO 8601 timestamp of when the message was deleted

next_stepsarray

Agent guidance for next actions

Soft Delete Behavior

When you delete a message:

Message is marked as deleted

The message is soft deleted - a deleted_at timestamp is set in the database

Hidden from list endpoints

The message will no longer appear in GET /v1/inboxes/{id}/messages

Still accessible by ID

The message can still be retrieved via GET /v1/inboxes/{id}/messages/{msgId} if you have the exact ID

Attachments retained

Attachments remain in R2 storage for 30 days before permanent deletion

Thread preserved

Deleting a message does not delete the thread - other messages in the thread remain

Info

Permanent deletion happens automatically after 30 days. If you need immediate permanent deletion, contact support@daimon.email.

Use Cases

Clean up read messages
// Agent deletes messages after processing
const messages = await client.inboxes.messages.list('inb_abc123', {
  read: true,
  limit: 100
});

for (const msg of messages.messages) {
  await client.inboxes.messages.delete('inb_abc123', msg.id);
  console.log(`Deleted: ${msg.subject}`);
}
Delete spam or unwanted messages
// Agent filters and deletes spam
const messages = await client.inboxes.messages.list('inb_abc123', {
  label: 'spam',
  limit: 100
});

for (const msg of messages.messages) {
  await client.inboxes.messages.delete('inb_abc123', msg.id);
}

console.log(`Deleted ${messages.messages.length} spam messages`);
Delete old messages (retention policy)
// Agent implements 90-day retention policy
const ninetyDaysAgo = new Date();
ninetyDaysAgo.setDate(ninetyDaysAgo.getDate() - 90);

const oldMessages = await client.inboxes.messages.list('inb_abc123', {
  before: ninetyDaysAgo.toISOString(),
  limit: 100
});

for (const msg of oldMessages.messages) {
  await client.inboxes.messages.delete('inb_abc123', msg.id);
}

console.log(`Deleted ${oldMessages.messages.length} messages older than 90 days`);
Batch delete with pagination
// Delete all messages in a specific thread
let hasMore = true;
let deleted = 0;

while (hasMore) {
  const messages = await client.inboxes.messages.list('inb_abc123', {
    thread_id: 'thr_def456',
    limit: 100
  });

  for (const msg of messages.messages) {
    await client.inboxes.messages.delete('inb_abc123', msg.id);
    deleted++;
  }

  hasMore = messages.has_more;
}

console.log(`Deleted ${deleted} messages from thread`);