Messages

Messages are the emails received in your AgentInbox inboxes. List, retrieve, and extract structured data from them.

Message Lifecycle

Messages persist as long as their parent inbox exists. When an inbox expires, all messages are automatically deleted.

Listing Messages

List all messages in an inbox. Results are returned in reverse chronological order (newest first).

bash
curl https://agentinbox.in/api/v1/inboxes/inb_123/messages \
-H "Authorization: Bearer $AgentInbox_API_KEY"

Getting a Message

Retrieve a specific message by its ID. The response includes headers, body content, and any extractions.

bash
curl https://agentinbox.in/api/v1/messages/msg_456 \
-H "Authorization: Bearer $AgentInbox_API_KEY"
GET/api/v1/messages/{messageId}

Retrieve a message by ID

Parameters

NameTypeRequiredDescription
messageIdstringRequiredThe unique message identifier.

Responses

HTTP 200
{
"id": "msg_456",
"inboxId": "inb_123",
"subject": "Your verification code",
"from": "noreply@example.com",
"to": "k3v9x2m4q7tz@agentinbox.in",
"body": {
"text": "Your code is 123456",
"html": "<p>Your code is <b>123456</b></p>",
"raw": "..."
},
"receivedAt": "2024-06-12T10:30:00Z"
}

Extracting Data

Automatically extract structured data from messages. AgentInbox supports 8 built-in extraction types plus LLM-powered fallback.

typescript
const extraction = await client.extractions.create({
messageId: "msg_456",
type: "otp",
});
console.log(extraction.value); // "123456"

Extraction Types

See the Extractions guide for all supported types and confidence scoring.

Supported Extraction Types

otp

One-time passcodes (e.g., 123456)

magic_link

Account verification links

verification_code

Alphanumeric codes

invoice_number

Invoice identifiers

tracking_number

Shipping tracking codes

api_token

API keys and tokens

coupon_code

Discount and promo codes

password_reset_link

Password reset URLs

Body Content

Messages include both text and HTML body content. The API returns both versions when available.

Reading body content
const message = await client.messages.get("msg_456");
console.log(message.body.text); // Plain text
console.log(message.body.html); // HTML content
console.log(message.body.raw); // Raw MIME

Body Fields

  • text — Plain text body, stripped of HTML tags
  • html — Original HTML body content
  • raw — Raw MIME message for advanced use cases

Real-Time Notifications

Use webhooks to receive real-time notifications when messages arrive. See the Webhooks guide for setup instructions.

Webhook payload
{
"event": "email.received",
"timestamp": "2024-06-12T10:30:00Z",
"data": {
"inboxId": "inb_123",
"messageId": "msg_456",
"subject": "Your verification code",
"from": "noreply@example.com"
}
}

Next Steps