API v2 Features: This guide covers the advanced API v2 create-message endpoint, which provides enhanced features like template substitutions, bulk sending, scheduled delivery, and comprehensive webhook support.
Official SDKs
Node.js and TypeScript SDK
Install @ahasend/sdk, send a sandbox email and handle each recipient result.
Go SDK
Install ahasend-go, send a sandbox email and verify webhook signatures.
What Are the API Sending Limits?
How Do I Send an Email Through the API?
Here’s a simple example to send your first email using the API:Which Credentials Do I Need?
All API requests require authentication using your API v2 key:Account ID
Account ID
Replace
{account_id} in the URL with your actual account ID. Find the account ID in the dashboard account settings. Use a send-only key from Credentials → Add → API Key v2 with messages:send:{your-domain}. Use messages:send:all when sending from many domains.Need API Keys? If you haven’t created API v2 credentials yet, check out our API Credentials guide for step-by-step instructions.
Basic Examples
Advanced Examples
Multiple Recipients: When you specify multiple recipients in the recipients array, AhaSend sends separate individual emails to each recipient. This is not one email with multiple addresses in the To/CC headers, but rather individual personalized emails where each recipient only sees their own email address and can receive personalized template substitutions.
How Do I Read the Sending Response?
The API returns a response with information about each message created:Successful Response (202)
Response Fields
Message Status
Message Status
queued- Message accepted and queued for deliveryscheduled- Message scheduled for future deliveryerror- Message failed validation or processing;idisnull
Message ID
Message ID
Unique identifier for tracking the message through webhooks and logs. It is
null when the message was not sent.Schedule Information
Schedule Information
If you include the
schedule parameter in your request, the response will include timing information including the scheduled first attempt and expiration.How Do I Handle a Failed Request?
HTTP202 means the request was accepted for processing. Inspect every item’s status; a rejected recipient has status: "error" and id: null even if the HTTP request succeeded.
Error responses have a human-readable
message field. Its text can change; do not parse it as a machine error code.
Idempotent-Replayed: true. See idempotency and error handling.
Validation Requirements
Based on the API documentation, ensure your requests meet these requirements:Content Requirements
Content Requirements
- Either
text_contentorhtml_contentis required - Both can be provided for multipart emails
- Use proper HTML structure for
html_content
Sender Domain
Sender Domain
from.emailmust be from a domain you own- Domain must have valid DNS records configured
- Domain must be verified in your AhaSend account
Retention Settings
Retention Settings
- Values must be within your plan’s retention range
- New accounts default to 7 days for metadata and message data
- Zero message-data retention needs approval from AhaSend
Scheduling Format
Scheduling Format
- Schedule times must be in RFC3339 format
first_attemptmust be in the future and within 7 days of the requestexpiresmust be afterfirst_attemptand within 8 days of the request- Times should be in UTC timezone
Best Practices
Idempotency
Idempotency
Use idempotency keys for safe retries:Stored send results expire after 24 hours. The same key and exact request replay a stored result; a 5xx can allow re-execution. See idempotency.
Template Variables
Template Variables
AhaSend supports MiniJinja templating language for email content.
- Use descriptive variable names
- Provide fallback values in templates
- Validate variables before sending
- Escape HTML content in variables
Bulk Operations
Bulk Operations
Efficient bulk sending:
- Send up to 100 requests per second
- Send up to 100 recipients per request
- Handle partial failures gracefully
- Implement retry logic for failed messages
Error Handling
Error Handling
Robust error handling:
- Implement exponential backoff for retries
- Log API responses for debugging
- Handle different status codes appropriately
- Use webhooks for delivery confirmation

