Skip to main content
This guide shows how to send email through AhaSend API v2, add substitutions, attachments and schedules, and check each recipient result. Available on Free, Pro and Max. See plans and features.
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.
Choose a framework or platform guide for the full integration, or use the CLI quickstart to send from your terminal.

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:
Include your API key in the Authorization header:
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

  • queued - Message accepted and queued for delivery
  • scheduled - Message scheduled for future delivery
  • error - Message failed validation or processing; id is null
Unique identifier for tracking the message through webhooks and logs. It is null when the message was not sent.
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?

HTTP 202 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.
A completed duplicate request returns its original status and body with Idempotent-Replayed: true. See idempotency and error handling.

Validation Requirements

Based on the API documentation, ensure your requests meet these requirements:
  • Either text_content or html_content is required
  • Both can be provided for multipart emails
  • Use proper HTML structure for html_content
  • from.email must be from a domain you own
  • Domain must have valid DNS records configured
  • Domain must be verified in your AhaSend account
  • 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
  • Schedule times must be in RFC3339 format
  • first_attempt must be in the future and within 7 days of the request
  • expires must be after first_attempt and within 8 days of the request
  • Times should be in UTC timezone

Best Practices

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.
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
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
Robust error handling:
  • Implement exponential backoff for retries
  • Log API responses for debugging
  • Handle different status codes appropriately
  • Use webhooks for delivery confirmation