Messages
Messages are the emails received in your AgentInbox inboxes. List, retrieve, and extract structured data from them.
Message Lifecycle
Listing Messages
List all messages in an inbox. Results are returned in reverse chronological order (newest first).
curl https://agentinbox.in/api/v1/inboxes/inb_123/messages \ -H "Authorization: Bearer $AgentInbox_API_KEY"const messages = await client.messages.list({ inboxId: "inb_123" });for (const msg of messages.data) { console.log(msg.subject, msg.from);}messages = client.messages.list(inbox_id="inb_123")for msg in messages.data: print(msg.subject, msg.from)Getting a Message
Retrieve a specific message by its ID. The response includes headers, body content, and any extractions.
curl https://agentinbox.in/api/v1/messages/msg_456 \ -H "Authorization: Bearer $AgentInbox_API_KEY"const message = await client.messages.get("msg_456");console.log(message.subject);console.log(message.body.text);/api/v1/messages/{messageId}Retrieve a message by ID
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| messageId | string | Required | The unique message identifier. |
Responses
{ "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"}{ "error": "message_not_found", "message": "Message does not exist or has been deleted"}Extracting Data
Automatically extract structured data from messages. AgentInbox supports 8 built-in extraction types plus LLM-powered fallback.
const extraction = await client.extractions.create({ messageId: "msg_456", type: "otp",});console.log(extraction.value); // "123456"extraction = client.extractions.create( message_id="msg_456", type="otp",)print(extraction.value) # "123456"Extraction Types
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.
const message = await client.messages.get("msg_456");console.log(message.body.text); // Plain textconsole.log(message.body.html); // HTML contentconsole.log(message.body.raw); // Raw MIMEBody 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.
{ "event": "email.received", "timestamp": "2024-06-12T10:30:00Z", "data": { "inboxId": "inb_123", "messageId": "msg_456", "subject": "Your verification code", "from": "noreply@example.com" }}