openapi: 3.1.0
info:
title: AhaSend API v2
description: |
The AhaSend API v2 allows you to send transactional emails, manage domains, webhooks, routes, API keys, and view statistics.
## Authentication
All API requests must be authenticated using a Bearer token in the Authorization header:
```
Authorization: Bearer aha-sk-64-CHARACTER-RANDOM-STRING
```
## Scopes
API keys have specific scopes that control access to different resources and actions:
### Message Scopes
- `messages:send:all` - Send messages from any domain in the account
- `messages:send:{domain}` - Send messages from a specific domain
- `messages:cancel:all` - Cancel messages from any domain
- `messages:cancel:{domain}` - Cancel messages from a specific domain
- `messages:read:all` - Read messages from any domain
- `messages:read:{domain}` - Read messages from a specific domain
### Domain Scopes
- `domains:read` - Read all domains
- `domains:write` - Create and update domains
- `domains:delete:all` - Delete any domain
- `domains:delete:{domain}` - Delete a specific domain
### Account Scopes
- `accounts:read` - Read account information
- `accounts:write` - Update account settings
- `accounts:billing` - Access billing information
- `accounts:members:read` - Read account members
- `accounts:members:add` - Add account members
- `accounts:members:update` - Update account members
- `accounts:members:remove` - Remove account members
### Webhook Scopes
- `webhooks:read:all` - Read all webhooks
- `webhooks:read:{domain}` - Read webhooks for a specific domain
- `webhooks:write:all` - Create and update webhooks
- `webhooks:write:{domain}` - Create and update webhooks for a specific domain
- `webhooks:delete:all` - Delete any webhook
- `webhooks:delete:{domain}` - Delete webhooks for a specific domain
### Route Scopes
- `routes:read:all` - Read all routes
- `routes:read:{domain}` - Read routes for a specific domain
- `routes:write:all` - Create and update routes
- `routes:write:{domain}` - Create and update routes for a specific domain
- `routes:delete:all` - Delete any route
- `routes:delete:{domain}` - Delete routes for a specific domain
### Suppression Scopes
- `suppressions:read` - Read suppressions
- `suppressions:write` - Create suppressions
- `suppressions:delete` - Delete suppressions
- `suppressions:wipe` - Delete all suppressions (dangerous)
### SMTP Credentials Scopes
- `smtp-credentials:read:all` - Read all SMTP credentials
- `smtp-credentials:read:{domain}` - Read SMTP credentials for a specific domain
- `smtp-credentials:write:all` - Create SMTP credentials
- `smtp-credentials:write:{domain}` - Create SMTP credentials for a specific domain
- `smtp-credentials:delete:all` - Delete any SMTP credentials
- `smtp-credentials:delete:{domain}` - Delete SMTP credentials for a specific domain
### Statistics Scopes
- `statistics-transactional:read:all` - Read all transactional statistics
- `statistics-transactional:read:{domain}` - Read transactional statistics for a specific domain
### API Key Scopes
- `api-keys:read` - Read API keys
- `api-keys:write` - Create and update API keys
- `api-keys:delete` - Delete API keys
### Sub-Account Scopes
- `sub-accounts:read` - List and read sub accounts under the parent
- `sub-accounts:write` - Create and update sub accounts
- `sub-accounts:delete` - Soft-delete sub accounts
- `sub-accounts:suspend` - Suspend and unsuspend sub accounts
- `sub-accounts:usage` - Read per-sub-account usage and allocated cost
- `sub-account-api-keys:read` - List and read API keys owned by sub accounts
- `sub-account-api-keys:write` - Create and update API keys owned by sub accounts
- `sub-account-api-keys:delete` - Delete API keys owned by sub accounts
## Rate Limiting
- General API endpoints: 100 requests per second, 200 burst
- Statistics endpoints: 1 request per second, 1 burst
## Pagination
List endpoints use cursor-based pagination with the following parameters:
- `limit`: Maximum number of items to return (default: 100, max: 100)
- `after`: Pass `pagination.next_cursor` to fetch the next page
- `before`: Pass `pagination.previous_cursor` to fetch the previous page
`after` and `before` are mutually exclusive. A legacy `cursor` query may be
accepted by parts of the server for backwards compatibility, but it is not
part of the v2 public contract.
## Time Formats
All timestamps must be in RFC3339 format, e.g., `2023-12-25T10:30:00Z`
## Idempotency
The operations that explicitly declare the optional `Idempotency-Key`
header support idempotency. Other POST operations do not gain idempotency
implicitly. When the header is provided:
- A fresh execution does not return `Idempotent-Replayed`.
- A completed stored response is replayed with its original status and body
and `Idempotent-Replayed: true`.
- An unexpired in-progress execution returns HTTP 409 with
`Idempotent-Replayed: false` and a positive integer `Retry-After` header.
- Reusing a key with a different HTTP method, resolved request path, or
request body returns HTTP 422. That response has neither
`Idempotent-Replayed` nor `Retry-After`.
- For ordinary idempotent operations, deterministic 2xx and 4xx outcomes
produced after the idempotency middleware are stored and replayed.
Authentication and IP-allow-list failures happen before idempotency and
are therefore not stored.
- The two secret-bearing API-key create operations use manual encrypted
completion. They store and replay a successful 201, including the same
one-time `secret_key`; a controller-produced 4xx is not stored and leaves
the key in progress until its execution lease expires.
- Server errors (5xx), handler failures, and panics are not stored. The key
is released so retrying the same request with the same key re-executes it.
The v2 API does not use an HTTP 412 failed-key tombstone.
- Idempotency keys for non-secret responses expire after 24 hours.
- Encrypted API-key creation replay responses expire after 5 minutes.
## IP Allow Lists
Each API key can carry an `ip_allow_list`: a set of source IPs that restrict where the key may authenticate from.
- Entries are CIDR blocks (e.g. `203.0.113.0/24`) or bare IPv4/IPv6 addresses (stored as a `/32` or `/128`). They are canonicalized and de-duplicated; the allow-all prefixes `0.0.0.0/0` and `::/0` are rejected, and at most 100 entries are allowed after de-duplication (a longer list is rejected with HTTP 400).
- An empty list (the default) places no restriction.
- When the list is non-empty, any authenticated request whose client IP is not covered by an entry is rejected with HTTP 403 on every v2 endpoint, regardless of the key's scopes.
- Manage the list with the `ip_allow_list` field on the API-key create and update endpoints (including the sub-account API-key endpoints).
- When a key updates its own `ip_allow_list` to a value that excludes the caller's current IP, the update is rejected with HTTP 409 to prevent self-lockout. Updating a sub-account key from a parent key has no such guard.
version: "2.0.0"
contact:
email: support@ahasend.com
license:
name: MIT
identifier: MIT
servers:
- url: https://api.ahasend.com
description: Production server
security:
- BearerAuth: []
components:
securitySchemes:
BearerAuth:
type: http
scheme: bearer
bearerFormat: "aha-sk-64-CHARACTER-RANDOM-STRING"
description: |
API key for authentication. Non-empty Security Requirement values are
AhaSend API-key roles. Roles listed within one requirement object are
jointly required; separate requirement objects are alternatives.
parameters:
IdempotencyKey:
name: Idempotency-Key
in: header
required: false
description: |
Optional idempotency key for safe request retries. Must be a unique string for each logical request.
An identical request with a completed stored outcome returns the original status and body. An in-progress
execution returns 409, a changed method/path/body returns 422, and a released 5xx execution may run again.
Keys for non-secret responses expire after 24 hours. API-key create responses include a one-time `secret_key`,
so successful encrypted replay responses for those operations expire after 5 minutes.
schema:
type: string
maxLength: 255
example: "user-12345-create-domain-20240101"
headers:
IdempotentReplayed:
description: |
Indicates that this response is a stored replay of a previous identical request.
When this header is absent, the response is not a stored replay. Ordinary fresh
responses do not send `false`; that value is reserved for an in-progress 409.
schema:
type: string
enum: ['true']
IdempotencyInProgress:
description: |
Identifies an idempotency-key execution that is still in progress. This
header is emitted only on the specialized HTTP 409 response.
schema:
type: string
enum: ['false']
IdempotencyRetryAfter:
description: |
Positive whole number of seconds after which the in-progress execution
lease may be retried with the same key and unchanged request.
schema:
type: integer
minimum: 1
responses:
IdempotencyConflict:
description: |
Request in progress. This response always includes
`Idempotent-Replayed: false` and a positive integer `Retry-After`.
Clients must use that header tuple, not the human-readable message, to
distinguish this retryable idempotency state from other HTTP 409s.
headers:
Idempotent-Replayed:
$ref: '#/components/headers/IdempotencyInProgress'
Retry-After:
$ref: '#/components/headers/IdempotencyRetryAfter'
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
example:
message: "A request with this idempotency key is already in progress"
IdempotencyPayloadMismatch:
description: |
Idempotency key was already used with a different HTTP method, resolved
request path, or request body. This response includes neither
`Idempotent-Replayed` nor `Retry-After`.
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
example:
message: "idempotency key was already used with a different request payload"
schemas:
ErrorResponse:
type: object
description: |
Human-readable API error. The server currently sends no stable machine
error code. In particular, clients must not parse `message` to
distinguish IP-allow-list, scope, ownership, plan, self-lockout,
suppression-duplicate, or other errors that share an HTTP status.
additionalProperties: false
required:
- message
properties:
message:
type: string
description: Error description
example:
message: "Error message"
SuccessResponse:
type: object
required:
- message
properties:
message:
type: string
description: Success message
example:
message: "Operation completed successfully"
PaginationInfo:
type: object
required:
- has_more
properties:
has_more:
type: boolean
description: Whether more items exist after the last item of this page
next_cursor:
type: string
description: Pass as `after` to fetch the next page
previous_cursor:
type: string
description: Pass as `before` to fetch the previous page; absent on a `before` page when the start of the list has been reached
example:
has_more: true
next_cursor: "eyJpZCI6MTIzNH0="
# API Key Schemas
APIKeyScope:
type: object
properties:
id:
type: string
format: uuid
description: Unique identifier for the scope
created_at:
type: string
format: date-time
description: When the scope was created
updated_at:
type: string
format: date-time
description: When the scope was last updated
api_key_id:
type: string
format: uuid
description: ID of the API key this scope belongs to
scope:
type: string
description: The scope string
domain_id:
type: [string, 'null']
format: uuid
description: Domain ID for domain-specific scopes; always present and null for non-domain scopes
required:
- id
- created_at
- updated_at
- api_key_id
- scope
- domain_id
APIKey:
type: object
properties:
object:
type: string
enum: [api_key]
description: Object type identifier
id:
type: string
format: uuid
description: Unique identifier for the API key
created_at:
type: string
format: date-time
description: When the API key was created
updated_at:
type: string
format: date-time
description: When the API key was last updated
last_used_at:
type: [string, 'null']
format: date-time
description: When the API key was last used (updates every 5-10 minutes)
account_id:
type: string
format: uuid
description: Account ID this API key belongs to
label:
type: string
description: Human-readable label for the API key
public_key:
type: string
description: Public portion of the API key
scopes:
type: array
items:
$ref: '#/components/schemas/APIKeyScope'
description: Scopes granted to this API key
ip_allow_list:
type: array
items:
type: string
description: >-
Source IPs allowed to authenticate with this API key, as canonical
CIDR blocks (a bare address is stored as a `/32` for IPv4 or `/128`
for IPv6). Always present; an empty array means the key may be used
from any source IP. When non-empty, an authenticated request whose
client IP is not covered by an entry is rejected with HTTP 403 on
every v2 endpoint, regardless of the key's scopes.
required:
- object
- id
- created_at
- updated_at
- last_used_at
- account_id
- label
- public_key
- scopes
- ip_allow_list
CreateAPIKeyRequest:
type: object
required:
- label
- scopes
properties:
label:
type: string
minLength: 1
maxLength: 255
description: Human-readable label for the API key; must not be empty
scopes:
type: array
items:
type: string
minItems: 1
description: Array of scope strings to grant to this API key
ip_allow_list:
type: array
items:
type: string
description: >-
Optional list of source IPs allowed to authenticate with this key.
Each entry is a CIDR block (e.g. `203.0.113.0/24`) or a bare
IPv4/IPv6 address (stored as a `/32` or `/128`). Entries are
canonicalized (host bits are masked) and de-duplicated. The
allow-all prefixes `0.0.0.0/0` and `::/0` are rejected, and at most
100 entries are allowed after de-duplication. Omit the field or
pass an empty array to leave the key usable from any IP.
example:
label: "Production API Key"
scopes: ["messages:send:all", "domains:read"]
ip_allow_list: ["203.0.113.0/24", "198.51.100.7"]
UpdateAPIKeyRequest:
type: object
description: At least one non-null field must be provided, and at least one provided value must differ from the current value. Omitted or null fields are left unchanged.
anyOf:
- required: [label]
properties:
label:
type: string
- required: [scopes]
properties:
scopes:
type: array
- required: [ip_allow_list]
properties:
ip_allow_list:
type: array
properties:
label:
type: [string, 'null']
minLength: 1
maxLength: 255
description: Human-readable label for the API key. Omit to keep the existing label.
scopes:
type: [array, 'null']
items:
type: string
minItems: 1
description: Array of scope strings to grant to this API key
ip_allow_list:
type: [array, 'null']
items:
type: string
description: >-
Replacement list of allowed source IPs (CIDR blocks or bare
IPv4/IPv6 addresses; canonicalized and de-duplicated, at most 100
entries, allow-all prefixes `0.0.0.0/0` and `::/0` rejected). Omit
the field or send null to leave the existing list unchanged; send an
empty array to clear it (key usable from any IP); send a non-empty
array to replace it.
example:
label: "Updated API Key"
scopes: ["messages:send:{example.com}", "domains:read"]
ip_allow_list: ["203.0.113.0/24"]
PaginatedAPIKeysResponse:
type: object
required:
- object
- data
- pagination
properties:
object:
type: string
enum: [list]
description: Object type identifier
data:
type: array
items:
$ref: '#/components/schemas/APIKey'
description: Array of API keys
pagination:
$ref: '#/components/schemas/PaginationInfo'
# Domain Schemas
DNSRecord:
type: object
properties:
type:
type: string
description: DNS record type (e.g., CNAME, TXT, MX)
label:
type: string
description: Human-readable DNS record label
host:
type: string
description: DNS record host/name
content:
type: string
description: DNS record content/value
required:
type: boolean
description: Whether this DNS record is required for domain verification
propagated:
type: boolean
description: Whether this DNS record has been propagated and verified
required:
- type
- host
- content
- required
- propagated
Domain:
type: object
properties:
object:
type: string
enum: [domain]
description: Object type identifier
id:
type: string
format: uuid
description: Unique identifier for the domain
created_at:
type: string
format: date-time
description: When the domain was created
updated_at:
type: string
format: date-time
description: When the domain was last updated
domain:
type: string
description: The domain name
account_id:
type: string
format: uuid
description: Account ID this domain belongs to
dns_records:
type: array
items:
$ref: '#/components/schemas/DNSRecord'
description: DNS records required for domain verification
last_dns_check_at:
type: [string, 'null']
format: date-time
description: When DNS records were last checked
dns_valid:
type: boolean
description: Whether all required DNS records are properly configured
tracking_subdomain:
type: [string, 'null']
description: Custom tracking subdomain. Null means the account or product default is used. Applies to both manual-DNS and managed-DNS domains.
return_path_subdomain:
type: [string, 'null']
description: Custom return-path subdomain. Null means the account or product default is used. Applies to both manual-DNS and managed-DNS domains.
subscription_subdomain:
type: [string, 'null']
description: Custom subscription management subdomain. Null means the account or product default is used. Applies to both manual-DNS and managed-DNS domains.
media_subdomain:
type: [string, 'null']
description: Custom media subdomain. Null means the account or product default is used. Applies to both manual-DNS and managed-DNS domains.
dkim_rotation_interval_days:
type: [integer, 'null']
description: Custom DKIM rotation interval in days. Null means the account default is used. Only supported for managed DNS domains.
dkim_selector:
type: [string, 'null']
description: |
Per-domain DKIM selector override. Null means no per-domain override is set.
This reports the configured per-domain override only, not the effective selector used for DKIM signing. The effective selector is resolved separately and can differ — for example, a selector locked after DNS verification takes precedence over this override.
rotation_ready:
type: boolean
description: Whether the standby DKIM slot is ready for rotation.
dsn_recipient:
type: [string, 'null']
description: Optional recipient address for delivery status notifications.
required:
- object
- id
- created_at
- updated_at
- domain
- account_id
- dns_records
- last_dns_check_at
- dns_valid
- tracking_subdomain
- return_path_subdomain
- subscription_subdomain
- media_subdomain
- dkim_rotation_interval_days
- dkim_selector
- rotation_ready
- dsn_recipient
CreateDomainRequest:
type: object
required:
- domain
properties:
domain:
type: string
format: hostname
description: Fully qualified domain name
dkim_private_key:
type: string
description: |
DKIM Private Key for the domain. Only RSA keys with a minimum key size of 1024 bits are supported.
**Note:** This parameter is only supported on [Platform Partner](https://ahasend.com/partners) accounts.
Key size of at least 1024 bits is supported; 2048 bit keys are strongly recommended for improved security.
tracking_subdomain:
type: string
description: Optional custom tracking subdomain. Omit to use the default on create. Applies to both manual-DNS and managed-DNS domains.
return_path_subdomain:
type: string
description: Optional custom return-path subdomain. Omit to use the default on create. Applies to both manual-DNS and managed-DNS domains.
subscription_subdomain:
type: string
description: Optional custom subscription management subdomain. Omit to use the default on create. Applies to both manual-DNS and managed-DNS domains.
media_subdomain:
type: string
description: Optional custom media subdomain. Omit to use the default on create. Applies to both manual-DNS and managed-DNS domains.
dkim_rotation_interval_days:
type: integer
description: Optional custom DKIM rotation interval in days. Only supported for managed DNS domains on eligible plans.
dkim_selector:
type: [string, 'null']
description: |
Optional custom DKIM selector for the domain. Omit, send null, or send an empty or whitespace-only string to use the default selector (no per-domain override); the value is trimmed before it is interpreted, so whitespace-only input is treated as empty.
When provided, it is normalized to lowercase and must be a single DNS label: 1-62 characters using lowercase letters, numbers, and hyphens only, without a leading or trailing hyphen.
**Note:** This parameter is only supported on [Platform Partner](https://ahasend.com/partners) accounts.
example:
domain: "example.com"
tracking_subdomain: "click"
return_path_subdomain: "mail"
subscription_subdomain: "preferences"
media_subdomain: "media"
dkim_rotation_interval_days: 45
UpdateDomainRequest:
type: object
properties:
tracking_subdomain:
type: string
description: Optional custom tracking subdomain. Omit to leave the current value unchanged. Applies to both manual-DNS and managed-DNS domains.
return_path_subdomain:
type: string
description: Optional custom return-path subdomain. Omit to leave the current value unchanged. Applies to both manual-DNS and managed-DNS domains.
subscription_subdomain:
type: string
description: Optional custom subscription management subdomain. Omit to leave the current value unchanged. Applies to both manual-DNS and managed-DNS domains.
media_subdomain:
type: string
description: Optional custom media subdomain. Omit to leave the current value unchanged. Applies to both manual-DNS and managed-DNS domains.
dkim_rotation_interval_days:
type: integer
description: Optional custom DKIM rotation interval in days. Omit to leave the current value unchanged. Only supported for managed DNS domains on eligible plans.
dkim_selector:
type: [string, 'null']
description: |
Optional custom DKIM selector for the domain. Omit or send null to leave the current value unchanged; send an empty or whitespace-only string to clear the override and revert to the default selector. The value is trimmed before it is interpreted, so whitespace-only input clears the override just like an empty string.
When provided, it is normalized to lowercase and must be a single DNS label: 1-62 characters using lowercase letters, numbers, and hyphens only, without a leading or trailing hyphen. It cannot be changed once the selector locks after DNS verification or while a DKIM key rotation is in progress.
**Note:** This parameter is only supported on [Platform Partner](https://ahasend.com/partners) accounts.
example:
tracking_subdomain: "click"
return_path_subdomain: "mail"
subscription_subdomain: "preferences"
media_subdomain: "media"
dkim_rotation_interval_days: 45
PaginatedDomainsResponse:
type: object
required:
- object
- data
- pagination
properties:
object:
type: string
enum: [list]
description: Object type identifier
data:
type: array
items:
$ref: '#/components/schemas/Domain'
description: Array of domains
pagination:
$ref: '#/components/schemas/PaginationInfo'
# Message Schemas
Address:
type: object
required:
- email
properties:
email:
type: string
format: email
description: Valid email address from a domain defined in your account with valid DNS records
name:
type: string
description: Display name for the sender
example:
email: "noreply@example.com"
name: "Example Corp"
Recipient:
type: object
required:
- email
properties:
email:
type: string
format: email
description: Recipient email address
name:
type: string
description: Display name for the recipient
substitutions:
type: object
additionalProperties: true
description: Substitution data for the recipient. Used with jinja2 templating language for dynamic content
example:
email: "user@example.com"
name: "John Doe"
substitutions:
first_name: "John"
order_id: "12345"
Attachment:
type: object
required:
- data
- content_type
- file_name
properties:
base64:
type: boolean
description: If true, data must be encoded using base64. Otherwise, data will be interpreted as UTF-8
default: false
data:
type: string
description: Either plaintext or base64 encoded attachment data (depending on base64 field)
content_type:
type: string
description: The MIME type of the attachment
content_disposition:
type: string
description: The disposition of the attachment
content_id:
type: string
description: |
Content-ID that lets you reference this attachment as an inline image from your HTML.
The value **must be wrapped in angle brackets**, matching the MIME `Content-ID` header format — for example `""`. Reference it from `html_content` **without** the brackets, e.g. `
`.
If the angle brackets are omitted, the file is delivered as a regular (downloadable) attachment instead of rendering inline.
file_name:
type: string
description: The filename of the attachment
example:
base64: true
data: "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=="
content_type: "image/png"
file_name: "pixel.png"
Tracking:
type: [object, 'null']
properties:
open:
type: [boolean, 'null']
description: Whether to track opens
click:
type: [boolean, 'null']
description: Whether to track clicks
example:
open: true
click: true
Retention:
type: [object, 'null']
properties:
metadata:
type: [integer, 'null']
description: Number of days to retain metadata
minimum: 1
maximum: 30
data:
type: [integer, 'null']
description: Number of days to retain data
minimum: 0
maximum: 30
example:
metadata: 1
data: 0
MessageSchedule:
type: object
properties:
first_attempt:
type: string
format: date-time
description: The time to make the first attempt for delivering the message. Must be RFC3339 format, in the future, and within 7 days of the request.
expires:
type: string
format: date-time
description: Expire and drop the message if not delivered by this time. Must be RFC3339 format, in the future, and within 8 days of the request.
CreateMessageRequest:
type: object
required:
- from
- recipients
- subject
properties:
from:
$ref: '#/components/schemas/Address'
recipients:
type: array
items:
$ref: '#/components/schemas/Recipient'
minItems: 1
maxItems: 100
description: This does not set the To header to multiple addresses, it sends a separate message for each recipient
reply_to:
$ref: '#/components/schemas/Address'
description: If provided, the reply-to header in headers array must not be provided
subject:
type: string
description: Email subject line
text_content:
type: string
description: Plain text content. Required if html_content is empty
html_content:
type: string
description: HTML content. Required if text_content is empty
amp_content:
type: string
description: AMP HTML content
attachments:
type: array
items:
$ref: '#/components/schemas/Attachment'
description: File attachments. For inline images, set the attachment's `content_id` to a value wrapped in angle brackets (e.g. ``) and reference it from `html_content` with `cid:` (e.g. `
`).
headers:
type: object
additionalProperties:
type: string
description: Custom email headers. reply-to header cannot be provided if reply_to is provided, message-id will be ignored and automatically generated
substitutions:
type: object
additionalProperties: true
description: Global substitutions, recipient substitutions override global
tags:
type: array
items:
type: string
description: Tags for categorizing messages
sandbox:
type: boolean
description: If true, the message will be sent to the sandbox environment
default: false
sandbox_result:
type: string
enum: [deliver, bounce, defer, fail, suppress]
description: The result of the sandbox send
tracking:
$ref: '#/components/schemas/Tracking'
description: Tracking settings for the message, overrides default account settings
retention:
$ref: '#/components/schemas/Retention'
description: Retention settings for the message, overrides default account settings
schedule:
$ref: '#/components/schemas/MessageSchedule'
description: Schedule for message delivery
example:
from:
email: "noreply@example.com"
name: "Example Corp"
recipients:
- email: "user@example.com"
name: "John Doe"
subject: "Welcome to Example Corp"
html_content: "Welcome {{first_name}}!
"
text_content: "Welcome {{first_name}}!"
substitutions:
first_name: "John"
CreateConversationMessageRequest:
type: object
required:
- from
- to
- subject
properties:
from:
$ref: '#/components/schemas/Address'
to:
type: array
items:
$ref: '#/components/schemas/Address'
minItems: 1
maxItems: 50
description: This parameter can set the `To` header to multiple addresses. The combined to, cc, and bcc recipient count must not exceed 50.
cc:
type: array
items:
$ref: '#/components/schemas/Address'
minItems: 1
maxItems: 50
description: This parameter can set the `CC` header to multiple addresses. Do not include `cc` in the headers array. The combined to, cc, and bcc recipient count must not exceed 50.
bcc:
type: array
items:
$ref: '#/components/schemas/Address'
minItems: 1
maxItems: 50
description: This parameter can set the `To` header to multiple addresses. The combined to, cc, and bcc recipient count must not exceed 50.
reply_to:
$ref: '#/components/schemas/Address'
description: If provided, the reply-to header in headers array must not be provided
subject:
type: string
description: Email subject line
text_content:
type: string
description: Plain text content. Required if html_content is empty
html_content:
type: string
description: HTML content. Required if text_content is empty
amp_content:
type: string
description: AMP HTML content
attachments:
type: array
items:
$ref: '#/components/schemas/Attachment'
description: File attachments. For inline images, set the attachment's `content_id` to a value wrapped in angle brackets (e.g. ``) and reference it from `html_content` with `cid:` (e.g. `
`).
headers:
type: object
additionalProperties:
type: string
description: Custom email headers. `cc` and `reply-to` headers cannot be provided if `reply_to` or `cc` parameters are provided, message-id will be ignored and automatically generated
tags:
type: array
items:
type: string
description: Tags for categorizing messages
sandbox:
type: boolean
description: If true, the message will be sent to the sandbox environment
default: false
sandbox_result:
type: string
enum: [deliver, bounce, defer, fail, suppress]
description: The result of the sandbox send
tracking:
$ref: '#/components/schemas/Tracking'
description: Tracking settings for the message, overrides default account settings
retention:
$ref: '#/components/schemas/Retention'
description: Retention settings for the message, overrides default account settings
schedule:
$ref: '#/components/schemas/MessageSchedule'
description: Schedule for message delivery
example:
from:
email: "noreply@example.com"
name: "Example Corp"
to:
- email: "user@example.com"
name: "John Doe"
- email: "someone@example.com"
name: "Jane Doe"
cc:
- email: "hr@example.com"
name: "Example Corp HR"
bcc:
- email: "bcc@example.com"
name: "BCC Recipient"
subject: "Welcome to Example Corp"
html_content: "Dear John and Jane, welcome to Example Corp!
"
text_content: "Dear John and Jane, welcome to Example Corp!"
CreateSingleMessageResponse:
type: object
required:
- object
- id
- recipient
- status
- error
properties:
object:
type: string
enum: [message]
description: Object type identifier
id:
type: [string, 'null']
description: Message ID (null if the message was not sent)
example:
recipient:
allOf:
- $ref: '#/components/schemas/Recipient'
- type: object
required:
- name
status:
type: string
enum: [queued, scheduled, error]
description: Status of the message
error:
type: [string, 'null']
description: Error message if the message was not sent
schedule:
$ref: '#/components/schemas/MessageSchedule'
description: Provided if the request contained a schedule
CreateMessageResponse:
type: object
required:
- object
- data
properties:
object:
type: string
enum: [list]
description: Object type identifier
data:
type: array
items:
$ref: '#/components/schemas/CreateSingleMessageResponse'
description: List of messages and their statuses
DeliveryEvent:
type: object
properties:
time:
type: string
format: date-time
description: Timestamp of the delivery event
log:
type: string
description: Log message for the delivery event
status:
type: string
description: Status of the delivery event
required:
- time
- log
- status
MessageContentPart:
type: object
properties:
content_type:
type: string
description: MIME content type (e.g., "text/plain", "text/html")
example: "text/html"
content:
type: string
description: The actual content for this part
required:
- content_type
- content
MessageAttachment:
type: object
properties:
filename:
type: string
description: Original filename of the attachment
example: "document.pdf"
content:
type: string
description: Base64 encoded attachment content
content_type:
type: string
description: MIME content type of the attachment
example: "application/pdf"
content_id:
type: string
description: Content-ID for inline attachments
example: "image001@example.com"
required:
- filename
- content
- content_type
- content_id
MessageContentParsed:
type: object
properties:
parts:
type: array
items:
$ref: '#/components/schemas/MessageContentPart'
description: Array of message content parts (text, HTML, etc.)
attachments:
type: array
items:
$ref: '#/components/schemas/MessageAttachment'
description: Array of message attachments
headers:
type: object
additionalProperties:
type: array
items:
type: string
description: Email headers as key-value pairs (values are arrays to handle multiple headers with same name)
example:
"Content-Type": ["text/html; charset=utf-8"]
"X-Custom-Header": ["value1", "value2"]
required:
- parts
- attachments
- headers
# Base message schema without heavy content fields
MessageSummary:
type: object
properties:
object:
type: string
enum: [message]
description: Object type identifier
created_at:
type: string
format: date-time
description: When the message was created
updated_at:
type: string
format: date-time
description: When the message was last updated
sent_at:
type: [string, 'null']
format: date-time
description: When the message was sent
delivered_at:
type: [string, 'null']
format: date-time
description: When the message was delivered
retain_until:
type: string
format: date-time
description: When the message data will be purged
direction:
type: string
enum: [inbound, outbound]
description: Message direction
is_bounce_notification:
type: boolean
description: Whether this is a bounce notification
bounce_classification:
type: string
description: Classification of bounce if applicable
delivery_attempts:
type: array
items:
$ref: '#/components/schemas/DeliveryEvent'
description: List of delivery attempts for this message
message_id:
type: string
description: Message-ID header value
id:
type: [string, 'null']
format: uuid
description: API-generated message ID
subject:
type: string
description: Message subject
tags:
type: array
items:
type: string
description: Tags associated with the message
sender:
type: string
format: email
description: Sender email address
recipient:
type: string
format: email
description: Recipient email address
status:
type: string
description: Current message status
num_attempts:
type: integer
description: Number of delivery attempts
click_count:
type: integer
description: Number of clicks tracked for this message
open_count:
type: integer
description: Number of opens tracked for this message
reference_message_id:
type: [integer, 'null']
format: int64
description: ID of the original message (for bounce messages)
domain_id:
type: string
format: uuid
description: Domain ID this message was sent from
account_id:
type: string
format: uuid
description: Account ID this message belongs to
required:
- object
- created_at
- updated_at
- sent_at
- delivered_at
- retain_until
- direction
- is_bounce_notification
- bounce_classification
- delivery_attempts
- message_id
- id
- subject
- tags
- sender
- recipient
- status
- num_attempts
- click_count
- open_count
- reference_message_id
- domain_id
- account_id
# Full message schema with content fields
Message:
allOf:
- $ref: '#/components/schemas/MessageSummary'
- type: object
properties:
content:
type: string
description: Original raw email content in RFC822 format. Omitted when message content is unavailable.
content_parsed:
$ref: '#/components/schemas/MessageContentParsed'
description: Parsed message content. Omitted when message content is unavailable.
# Update the paginated response to use the lighter schema
PaginatedMessagesResponse:
type: object
required:
- object
- data
- pagination
properties:
object:
type: string
enum: [list]
description: Object type identifier
data:
type: array
items:
$ref: '#/components/schemas/MessageSummary'
description: Array of message summaries (content and content_parsed fields omitted for performance)
pagination:
$ref: '#/components/schemas/PaginationInfo'
# Account Schemas
Account:
type: object
properties:
object:
type: string
enum: [account]
description: Object type identifier
id:
type: string
format: uuid
description: Unique identifier for the account
parent_account_id:
type: [string, 'null']
format: uuid
description: Parent account ID when this account is a sub account
created_at:
type: string
format: date-time
description: When the account was created
updated_at:
type: string
format: date-time
description: When the account was last updated
name:
type: string
description: Account name
website:
type: string
format: uri
description: Account website URL
about:
type: string
description: Account description
track_opens:
type: boolean
description: Default open tracking setting
track_clicks:
type: boolean
description: Default click tracking setting
reject_bad_recipients:
type: boolean
description: Whether to reject bad recipients
reject_mistyped_recipients:
type: boolean
description: Whether to reject mistyped recipients
message_metadata_retention:
type: integer
description: Default message metadata retention in days
message_data_retention:
type: integer
description: Default message data retention in days
owner_id:
type: string
format: uuid
description: Account owner user ID
required:
- object
- id
- parent_account_id
- created_at
- updated_at
- name
- website
- about
- track_opens
- track_clicks
- reject_bad_recipients
- reject_mistyped_recipients
- message_metadata_retention
- message_data_retention
- owner_id
SubAccount:
type: object
required:
- object
- id
- parent_account_id
- name
- website
- status
- monthly_credit
- created_at
- domain_count
- member_count
- last_activity_at
properties:
object:
type: string
enum: [sub_account]
description: Object type identifier
id:
type: string
format: uuid
description: Unique identifier for the sub account
parent_account_id:
type: string
format: uuid
description: Parent account ID
created_at:
type: string
format: date-time
description: When the sub account was created
name:
type: string
description: Sub account name
website:
type: string
format: fqdn
maxLength: 255
description: Account website domain
status:
type: string
enum: [active, suspended, parent-suspended, deleted]
description: Current sub-account status
monthly_credit:
type: integer
format: int64
minimum: 0
description: Optional monthly cap; 0 means no cap
domain_count:
type: integer
format: int64
minimum: 0
description: Number of domains owned by the sub account
member_count:
type: integer
format: int64
minimum: 0
description: Number of direct members on the sub account
last_activity_at:
type: [string, 'null']
format: date-time
description: Last recorded sub-account email activity
example:
object: sub_account
id: "2f3c5d2a-9ef8-4c91-a5f4-79990c8c1d3a"
parent_account_id: "9d0cf9d0-4f5e-4674-bcf1-8ec39968b6e1"
name: "Acme Subsidiary"
website: "acme.example.com"
status: active
monthly_credit: 0
created_at: "2024-01-01T00:00:00Z"
domain_count: 2
member_count: 3
last_activity_at: "2024-01-15T12:00:00Z"
CreateSubAccountRequest:
type: object
required:
- name
- website
properties:
name:
type: string
minLength: 1
maxLength: 255
description: Human-readable name for the sub account; leading and trailing whitespace is trimmed and the result must not be blank
website:
type: string
format: fqdn
maxLength: 255
description: Account website domain
monthly_credit:
type: integer
format: int64
minimum: 0
maximum: 1000000000
default: 0
description: Optional monthly cap; 0 means no cap
example:
name: "Acme Subsidiary"
website: "acme.example.com"
monthly_credit: 0
UpdateSubAccountRequest:
type: object
description: At least one non-null field must be provided, and at least one provided value must differ from the current value. Omitted or null fields are left unchanged.
anyOf:
- required: [name]
properties:
name:
type: string
- required: [website]
properties:
website:
type: string
- required: [monthly_credit]
properties:
monthly_credit:
type: integer
properties:
name:
type: [string, 'null']
minLength: 1
maxLength: 255
description: Human-readable name for the sub account; leading and trailing whitespace is trimmed and the result must not be blank
website:
type: [string, 'null']
format: fqdn
maxLength: 255
description: Account website domain
monthly_credit:
type: [integer, 'null']
format: int64
minimum: 0
maximum: 1000000000
description: Optional monthly cap; 0 means no cap
example:
name: "Acme Subsidiary"
website: "acme.example.com"
monthly_credit: 50000
SuspendSubAccountRequest:
type: object
required:
- reason
properties:
reason:
type: string
minLength: 1
maxLength: 500
description: Reason shown on the sub account suspension record
example:
reason: "Customer requested temporary pause"
SubAccountUsageBreakdown:
type: object
required:
- reception_count
- allocated_cost
properties:
account_id:
type: string
format: uuid
description: Account ID for this usage bucket
name:
type: string
description: Sub account name when this bucket is for a sub account
reception_count:
type: integer
format: int64
minimum: 0
description: Number of received messages in the billing period
allocated_cost:
type: number
format: double
minimum: 0
description: Proportional allocated cost for this usage bucket
example:
account_id: "2f3c5d2a-9ef8-4c91-a5f4-79990c8c1d3a"
name: "Acme Subsidiary"
reception_count: 3000000
allocated_cost: 60.0
SubAccountUsageResponse:
type: object
required:
- billing_period
- currency
- allocation_method
- allocation_note
- parent
- sub_accounts
- removed_sub_accounts
- total
properties:
billing_period:
type: object
required:
- start
- end
properties:
start:
type: string
format: date-time
description: Billing period start
end:
type: string
format: date-time
description: Billing period end
currency:
type: string
description: Currency code used for cost allocation
allocation_method:
type: string
enum: [proportional]
description: Method used to allocate the pooled parent invoice cost
allocation_note:
type: string
description: Disclaimer explaining that allocated cost is not standalone sub-account pricing
parent:
allOf:
- $ref: '#/components/schemas/SubAccountUsageBreakdown'
- type: object
required:
- account_id
sub_accounts:
type: array
items:
allOf:
- $ref: '#/components/schemas/SubAccountUsageBreakdown'
- type: object
required:
- account_id
- name
description: Per-sub-account usage and allocated cost
removed_sub_accounts:
$ref: '#/components/schemas/SubAccountUsageBreakdown'
description: Aggregated usage from sub accounts deleted during the period; still billed to the parent and not identified individually
total:
$ref: '#/components/schemas/SubAccountUsageBreakdown'
example:
billing_period:
start: "2024-01-01T00:00:00Z"
end: "2024-02-01T00:00:00Z"
currency: usd
allocation_method: proportional
allocation_note: "allocated_cost is a proportional share of the parent's pooled invoice for the period, not what the sub would pay on its own plan."
parent:
account_id: "9d0cf9d0-4f5e-4674-bcf1-8ec39968b6e1"
reception_count: 1000000
allocated_cost: 20.0
sub_accounts:
- account_id: "2f3c5d2a-9ef8-4c91-a5f4-79990c8c1d3a"
name: "Acme Subsidiary"
reception_count: 3000000
allocated_cost: 60.0
removed_sub_accounts:
reception_count: 0
allocated_cost: 0.0
total:
reception_count: 4000000
allocated_cost: 80.0
PaginatedSubAccountsResponse:
type: object
required:
- object
- data
- pagination
properties:
object:
type: string
enum: [list]
description: Object type identifier
data:
type: array
items:
$ref: '#/components/schemas/SubAccount'
description: Array of sub accounts
pagination:
$ref: '#/components/schemas/PaginationInfo'
UpdateAccountRequest:
type: object
properties:
name:
type: string
maxLength: 255
description: Account name
website:
type: string
format: uri
description: Account website URL
about:
type: string
description: Account description (used for account verification)
track_opens:
type: boolean
description: Default open tracking setting
track_clicks:
type: boolean
description: Default click tracking setting
reject_bad_recipients:
type: boolean
description: Whether to reject bad recipients
reject_mistyped_recipients:
type: boolean
description: Whether to reject mistyped recipients
message_metadata_retention:
type: integer
minimum: 1
maximum: 30
description: Default message metadata retention in days
message_data_retention:
type: integer
minimum: 0
maximum: 30
description: Default message data retention in days
example:
name: "Updated Company Name"
website: "https://example.com"
track_opens: true
UserAccount:
type: object
properties:
created_at:
type: string
format: date-time
description: When the relationship was created
updated_at:
type: string
format: date-time
description: When the relationship was last updated
user_id:
type: string
format: uuid
description: User ID
account_id:
type: string
format: uuid
description: Account ID
role:
type: string
enum: [Administrator, Developer, Analyst, "Billing Manager"]
description: User role in the account
required:
- created_at
- updated_at
- user_id
- account_id
- role
AccountMembersResponse:
type: object
required:
- object
- data
properties:
object:
type: string
enum: [list]
description: Object type identifier
data:
type: array
items:
$ref: '#/components/schemas/UserAccount'
description: Array of account members
AddMemberRequest:
type: object
required:
- email
- role
properties:
email:
type: string
format: email
description: Email address of the user to add
name:
type: string
description: Display name for the user
role:
type: string
enum: [Administrator, Developer, Analyst, "Billing Manager"]
description: Role to assign to the user
example:
email: "user@example.com"
name: "John Doe"
role: "Developer"
# Suppression Schemas
Suppression:
type: object
properties:
object:
type: string
enum: [suppression]
description: Object type identifier
id:
type: string
format: uuid
description: Unique identifier for the suppression
created_at:
type: string
format: date-time
description: When the suppression was created
email:
type: string
format: email
description: Suppressed email address
domain:
type: string
description: Domain for which the email is suppressed
reason:
type: string
description: Reason for suppression
expires_at:
type: string
format: date-time
description: When the suppression expires
required:
- object
- id
- created_at
- email
- domain
- reason
- expires_at
CreateSuppressionResponse:
type: object
required:
- object
- data
properties:
object:
type: string
enum: [list]
description: Object type identifier
data:
type: array
items:
$ref: '#/components/schemas/Suppression'
description: Array of suppressions
CreateSuppressionRequest:
type: object
required:
- email
- expires_at
properties:
email:
type: string
format: email
description: Email address to suppress
domain:
type: string
format: hostname
description: Domain for which to suppress the email
reason:
type: string
maxLength: 255
description: Reason for suppression
expires_at:
type: string
format: date-time
description: When the suppression expires (RFC3339 format)
example:
email: "user@example.com"
domain: "example.com"
reason: "User requested removal"
expires_at: "2024-12-25T10:30:00Z"
PaginatedSuppressionsResponse:
type: object
required:
- object
- data
- pagination
properties:
object:
type: string
enum: [list]
description: Object type identifier
data:
type: array
items:
$ref: '#/components/schemas/Suppression'
description: Array of suppressions
pagination:
$ref: '#/components/schemas/PaginationInfo'
# Route Schemas
Route:
type: object
properties:
object:
type: string
enum: [route]
description: Object type identifier
id:
type: string
format: uuid
description: Unique identifier for the route
created_at:
type: string
format: date-time
description: When the route was created
updated_at:
type: string
format: date-time
description: When the route was last updated
name:
type: string
description: Route name
url:
type: string
format: uri
description: Webhook URL for the route
recipient:
type: string
description: Recipient filter; an empty string means no recipient filter
attachments:
type: boolean
description: Whether to include attachments in route payload
headers:
type: boolean
description: Whether to include headers in route payload
group_by_message_id:
type: boolean
description: Whether to group by message ID
strip_replies:
type: boolean
description: Whether to strip reply content
enabled:
type: boolean
description: Whether the route is enabled
success_count:
type: integer
minimum: 0
description: Number of successful calls
error_count:
type: integer
minimum: 0
description: Number of unsuccessful calls
errors_since_last_success:
type: integer
minimum: 0
description: |
Number of consecutive failed calls. Reset to zero by the next
successful call.
last_request_at:
type: [string, 'null']
format: date-time
description: When the route was last called
required:
- object
- id
- created_at
- updated_at
- name
- url
- recipient
- attachments
- headers
- group_by_message_id
- strip_replies
- enabled
- success_count
- error_count
- errors_since_last_success
- last_request_at
CreatedRoute:
allOf:
- $ref: '#/components/schemas/Route'
- type: object
properties:
secret:
type: string
description: Route signing secret. Returned only when the route is created.
required:
- secret
CreateRouteRequest:
type: object
required:
- name
- url
- recipient
properties:
name:
type: string
maxLength: 255
description: Route name
url:
type: string
format: uri
description: Webhook URL for the route
recipient:
type: string
maxLength: 255
description: Recipient filter
attachments:
type: boolean
description: Whether to include attachments in webhooks
default: false
headers:
type: boolean
description: Whether to include headers in webhooks
default: false
group_by_message_id:
type: boolean
description: Whether to group by message ID
default: false
strip_replies:
type: boolean
description: Whether to strip reply content
default: false
enabled:
type: boolean
description: Whether the route is enabled
default: true
example:
name: "Support Route"
url: "https://example.com/webhook"
recipient: "support@example.com"
enabled: true
UpdateRouteRequest:
type: object
properties:
name:
type: [string, 'null']
maxLength: 255
description: Route name
url:
type: [string, 'null']
format: uri
description: Webhook URL for the route
recipient:
type: [string, 'null']
maxLength: 255
description: Recipient filter
attachments:
type: [boolean, 'null']
description: Whether to include attachments in webhooks
headers:
type: [boolean, 'null']
description: Whether to include headers in webhooks
group_by_message_id:
type: [boolean, 'null']
description: Whether to group by message ID
strip_replies:
type: [boolean, 'null']
description: Whether to strip reply content
enabled:
type: [boolean, 'null']
description: Whether the route is enabled
example:
name: "Updated Support Route"
enabled: false
PaginatedRoutesResponse:
type: object
required:
- object
- data
- pagination
properties:
object:
type: string
enum: [list]
description: Object type identifier
data:
type: array
items:
$ref: '#/components/schemas/Route'
description: Array of routes
pagination:
$ref: '#/components/schemas/PaginationInfo'
# Webhook Schemas
Webhook:
type: object
properties:
object:
type: string
enum: [webhook]
description: Object type identifier
id:
type: string
format: uuid
description: Unique identifier for the webhook
created_at:
type: string
format: date-time
description: When the webhook was created
updated_at:
type: string
format: date-time
description: When the webhook was last updated
name:
type: string
description: Webhook name
url:
type: string
format: uri
description: Webhook URL
enabled:
type: boolean
description: Whether the webhook is enabled
on_reception:
type: boolean
description: Trigger on message reception
on_delivered:
type: boolean
description: Trigger on message delivery
on_transient_error:
type: boolean
description: Trigger on transient errors
on_failed:
type: boolean
description: Trigger on permanent failures
on_bounced:
type: boolean
description: Trigger on bounces
on_suppressed:
type: boolean
description: Trigger on suppressions
on_opened:
type: boolean
description: Trigger on opens
on_clicked:
type: boolean
description: Trigger on clicks
on_suppression_created:
type: boolean
description: Trigger on suppression creation
on_dns_error:
type: boolean
description: Trigger on DNS errors
scope:
type: string
enum: [global, scoped]
description: Webhook scope
domains:
type: array
items:
type: string
description: Domains this webhook applies to. Always present; global webhooks return an empty array.
success_count:
type: integer
minimum: 0
description: Number of successful calls
error_count:
type: integer
minimum: 0
description: Number of unsuccessful calls
errors_since_last_success:
type: integer
minimum: 0
description: |
Number of consecutive failed calls. Reset to zero by the next
successful call.
last_request_at:
type: [string, 'null']
format: date-time
description: When the webhook was last called
required:
- object
- id
- created_at
- updated_at
- name
- url
- enabled
- on_reception
- on_delivered
- on_transient_error
- on_failed
- on_bounced
- on_suppressed
- on_opened
- on_clicked
- on_suppression_created
- on_dns_error
- scope
- domains
- success_count
- error_count
- errors_since_last_success
- last_request_at
CreatedWebhook:
allOf:
- $ref: '#/components/schemas/Webhook'
- type: object
properties:
secret:
type: string
description: Webhook signing secret. Returned only when the webhook is created.
required:
- secret
CreateWebhookRequest:
type: object
required:
- name
- url
- scope
properties:
name:
type: string
maxLength: 255
description: Webhook name
url:
type: string
format: uri
description: Webhook URL
enabled:
type: boolean
description: Whether the webhook is enabled
default: true
on_reception:
type: boolean
description: Trigger on message reception
default: false
on_delivered:
type: boolean
description: Trigger on message delivery
default: false
on_transient_error:
type: boolean
description: Trigger on transient errors
default: false
on_failed:
type: boolean
description: Trigger on permanent failures
default: false
on_bounced:
type: boolean
description: Trigger on bounces
default: false
on_suppressed:
type: boolean
description: Trigger on suppressions
default: false
on_opened:
type: boolean
description: Trigger on opens
default: false
on_clicked:
type: boolean
description: Trigger on clicks
default: false
on_suppression_created:
type: boolean
description: Trigger on suppression creation
default: false
on_dns_error:
type: boolean
description: Trigger on DNS errors
default: false
scope:
type: string
enum: [global, scoped]
description: Webhook scope
domains:
type: [array, 'null']
items:
type: string
description: |
For `scoped`, a non-empty array is required. For `global`, this may
be omitted, null, empty, or non-empty; supplied values are accepted
but ignored.
allOf:
- if:
properties:
scope:
const: scoped
required: [scope]
then:
required: [domains]
properties:
domains:
type: array
minItems: 1
items:
type: string
example:
name: "Delivery Webhook"
url: "https://example.com/webhook"
scope: "global"
enabled: true
on_delivered: true
UpdateWebhookRequest:
type: object
description: |
Partial update. Omitted and null scalar fields leave their stored values
unchanged. Domain transition rules depend on the webhook's existing
scope and are described on `domains`.
properties:
name:
type: [string, 'null']
maxLength: 255
description: Webhook name
url:
type: [string, 'null']
format: uri
description: Webhook URL
enabled:
type: [boolean, 'null']
description: Whether the webhook is enabled
on_reception:
type: [boolean, 'null']
description: Trigger on message reception
on_delivered:
type: [boolean, 'null']
description: Trigger on message delivery
on_transient_error:
type: [boolean, 'null']
description: Trigger on transient errors
on_failed:
type: [boolean, 'null']
description: Trigger on permanent failures
on_bounced:
type: [boolean, 'null']
description: Trigger on bounces
on_suppressed:
type: [boolean, 'null']
description: Trigger on suppressions
on_opened:
type: [boolean, 'null']
description: Trigger on opens
on_clicked:
type: [boolean, 'null']
description: Trigger on clicks
on_suppression_created:
type: [boolean, 'null']
description: Trigger on suppression creation
on_dns_error:
type: [boolean, 'null']
description: Trigger on DNS errors
scope:
type: [string, 'null']
enum: [global, scoped, null]
description: Webhook scope. Omit or send null to keep the current scope.
domains:
type: [array, 'null']
items:
type: string
description: |
Omit or send null to leave domain associations unchanged. An array
replaces associations when the resulting scope is `scoped`; `[]`
explicitly clears them. Changing a global webhook to `scoped`
requires a non-empty array in the same request and otherwise
returns HTTP 400. Changing to `global` clears all associations;
supplied domains are ignored when the resulting scope is global.
PaginatedWebhooksResponse:
type: object
required:
- object
- data
- pagination
properties:
object:
type: string
enum: [list]
description: Object type identifier
data:
type: array
items:
$ref: '#/components/schemas/Webhook'
description: Array of webhooks
pagination:
$ref: '#/components/schemas/PaginationInfo'
# SMTP Credentials Schemas
SMTPCredential:
type: object
properties:
object:
type: string
enum: [credential_smtp]
description: Object type identifier
id:
type: string
format: uuid
description: Unique identifier for the SMTP credential
created_at:
type: string
format: date-time
description: When the credential was created
updated_at:
type: string
format: date-time
description: When the credential was last updated
name:
type: string
description: Credential name
username:
type: string
description: SMTP username
sandbox:
type: boolean
description: Whether this is a sandbox credential
scope:
type: string
enum: [global, scoped]
description: Credential scope
domains:
type: array
items:
type: string
description: Domains this credential can send from. Always present; global credentials return an empty array.
required:
- object
- id
- created_at
- updated_at
- name
- username
- sandbox
- scope
- domains
CreatedSMTPCredential:
allOf:
- $ref: '#/components/schemas/SMTPCredential'
- type: object
properties:
password:
type: string
description: SMTP password. Returned only when the credential is created.
required:
- password
CreateSMTPCredentialRequest:
type: object
required:
- name
- scope
properties:
name:
type: string
maxLength: 255
description: Credential name
sandbox:
type: boolean
description: Whether this is a sandbox credential
default: false
scope:
type: string
enum: [global, scoped]
description: Credential scope - "global" or "scoped"
domains:
type: [array, 'null']
items:
type: string
description: |
For `scoped`, a non-empty array is required. For `global`, this may
be omitted, null, empty, or non-empty; supplied values are accepted
but ignored.
allOf:
- if:
properties:
scope:
const: scoped
required: [scope]
then:
required: [domains]
properties:
domains:
type: array
minItems: 1
items:
type: string
example:
name: "Production SMTP"
scope: "global"
PaginatedSMTPCredentialsResponse:
type: object
required:
- object
- data
- pagination
properties:
object:
type: string
enum: [list]
description: Object type identifier
data:
type: array
items:
$ref: '#/components/schemas/SMTPCredential'
description: Array of SMTP credentials
pagination:
$ref: '#/components/schemas/PaginationInfo'
# Statistics Schemas
DeliverabilityStatistics:
type: object
properties:
from_timestamp:
type: string
format: date-time
description: Start time of the statistics bucket
to_timestamp:
type: string
format: date-time
description: End time of the statistics bucket
reception_count:
type: integer
description: Number of messages accepted for delivery
delivered_count:
type: integer
description: Number of messages delivered
deferred_count:
type: integer
description: Number of messages deferred
bounced_count:
type: integer
description: Number of messages bounced
failed_count:
type: integer
description: Number of messages failed
suppressed_count:
type: integer
description: Number of messages suppressed
opened_count:
type: integer
description: Number of messages opened at least once
clicked_count:
type: integer
description: Number of messages that have at least one link in them clicked.
required:
- from_timestamp
- to_timestamp
- reception_count
- delivered_count
- deferred_count
- bounced_count
- failed_count
- suppressed_count
- opened_count
- clicked_count
DeliverabilityStatisticsResponse:
type: object
required:
- object
- data
properties:
object:
type: string
enum: [list]
description: Object type identifier
data:
type: array
items:
$ref: '#/components/schemas/DeliverabilityStatistics'
description: Array of deliverability statistics
Bounce:
type: object
properties:
classification:
type: string
description: Bounce classification
count:
type: integer
description: Number of bounces
required:
- classification
- count
BounceStatistics:
type: object
properties:
from_timestamp:
type: string
format: date-time
description: Start time of the statistics bucket
to_timestamp:
type: string
format: date-time
description: End time of the statistics bucket
bounces:
type: array
items:
$ref: '#/components/schemas/Bounce'
description: Bounce count per bounce classification
required:
- from_timestamp
- to_timestamp
- bounces
BounceStatisticsResponse:
type: object
required:
- object
- data
properties:
object:
type: string
enum: [list]
description: Object type identifier
data:
type: array
items:
$ref: '#/components/schemas/BounceStatistics'
description: Array of bounce statistics
DeliveryTimeStatistics:
type: object
properties:
from_timestamp:
type: string
format: date-time
description: Start time of the statistics bucket
to_timestamp:
type: string
format: date-time
description: End time of the statistics bucket
avg_delivery_time:
type: number
format: double
description: Average delivery time in seconds
delivered_count:
type: integer
description: Number of messages
delivery_times:
type: array
items:
$ref: '#/components/schemas/DeliveryTime'
description: Delivery times per recipient domain
required:
- from_timestamp
- to_timestamp
- avg_delivery_time
- delivered_count
- delivery_times
DeliveryTime:
type: object
properties:
recipient_domain:
type: string
format: fqdn
description: The recipient domain
delivery_time:
type: number
format: double
description: The average time from reception to delivery in seconds
count:
type: integer
format: int64
description: Number of delivered messages included in the average
required:
- recipient_domain
- delivery_time
- count
DeliveryTimeStatisticsResponse:
type: object
required:
- object
- data
properties:
object:
type: string
enum: [list]
description: Object type identifier
data:
type: array
items:
$ref: '#/components/schemas/DeliveryTimeStatistics'
description: Array of delivery time statistics
paths:
# Utility endpoints
/v2/ping:
get:
summary: Ping
description: Health check endpoint that returns a simple pong response
operationId: ping
tags:
- Utility
security:
- BearerAuth: []
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go/api"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
// Create context for the API call
ctx := context.Background()
// Call the ping endpoint
response, httpResp, err := client.UtilityAPI.Ping(ctx)
if err != nil {
log.Fatalf("Error pinging API: %v", err)
}
// Check response
if httpResp.StatusCode == 200 {
fmt.Printf("✅ Ping successful! Status: %d\n", httpResp.StatusCode)
if response != nil && response.Message != "" {
fmt.Printf("Response: %s\n", response.Message)
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const health = await client.ping();
console.log("AhaSend API is reachable.", { message: health.message });
responses:
'200':
description: Pong response
content:
application/json:
schema:
$ref: '#/components/schemas/SuccessResponse'
example:
message: "pong"
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
example:
message: "missing or malformed bearer token"
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
example:
message: invalid API key
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
example:
message: insufficient permissions for the required scope
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
example:
message: internal server error
# API Keys endpoints
/v2/accounts/{account_id}/api-keys:
get:
summary: Get API Keys
description: Returns a list of API keys for the account
operationId: getAPIKeys
tags:
- API Keys
parameters:
- name: account_id
in: path
required: true
description: Account ID
schema:
type: string
format: uuid
- name: limit
in: query
description: Maximum number of items to return
schema:
type: integer
minimum: 1
maximum: 100
default: 100
- name: after
in: query
description: Pagination cursor for the next page. Provide the value provided in `next_cursor` from the response.
schema:
type: string
- name: before
in: query
description: Pagination cursor for the previous page.
schema:
type: string
security:
- BearerAuth: ["api-keys:read"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go/api"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
// Create context for the API call
ctx := context.Background()
// Call the ping endpoint
response, httpResp, err := client.APIKeysAPI.GetAPIKeys(
ctx,
accountID,
nil,
nil,
)
if err != nil {
log.Fatalf("Error getting API keys: %v", err)
}
// Check response
if httpResp.StatusCode == 200 {
fmt.Printf("✅ Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("Found %d API keys\n", len(response.Data))
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const page = await client.apiKeys.list({ limit: 20 });
console.log("API keys listed.", { count: page.data.length });
responses:
'200':
description: List of API keys
content:
application/json:
schema:
$ref: '#/components/schemas/PaginatedAPIKeysResponse'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
post:
summary: Create API Key
description: Creates a new API key with the specified scopes
operationId: createAPIKey
tags:
- API Keys
parameters:
- name: account_id
in: path
required: true
description: Account ID
schema:
type: string
format: uuid
- $ref: '#/components/parameters/IdempotencyKey'
security:
- BearerAuth: ["api-keys:write"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go/api"
"github.com/AhaSend/ahasend-go/models/requests"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
// Create context for the API call
ctx := context.Background()
// Create a new API key
response, httpResp, err := client.APIKeysAPI.CreateAPIKey(
ctx,
accountID,
requests.CreateAPIKeyRequest{
Label: "My API Key",
Scopes: []string{
"messages:read:all",
"domains:read",
},
// Optional: restrict this key to specific source IPs (CIDR
// blocks or bare IPv4/IPv6 addresses). Omit or leave empty to
// allow the key to be used from any IP.
IPAllowList: []string{"203.0.113.0/24", "198.51.100.7"},
},
)
if err != nil {
log.Fatalf("Error creating API key: %v", err)
}
// Check response
if httpResp.StatusCode == 201 {
fmt.Printf("✅ Status: %d\n", httpResp.StatusCode)
// SecretKey is the one-time secret, returned ONLY on create.
if response != nil && response.SecretKey != nil {
// Store this value immediately — it cannot be retrieved again later.
fmt.Printf("Created API key, secret key: %s\n", *response.SecretKey)
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const apiKey = await client.apiKeys.create(
{ label: "Production API key", scopes: ["messages:send:all"] },
{ idempotencyKey: "sdk-sample-create-api-key" },
);
console.log("API key created.", { id: apiKey.id, label: apiKey.label });
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/CreateAPIKeyRequest'
responses:
'201':
description: API key created successfully
headers:
Idempotent-Replayed:
$ref: '#/components/headers/IdempotentReplayed'
content:
application/json:
schema:
allOf:
- $ref: '#/components/schemas/APIKey'
- type: object
required:
- secret_key
properties:
secret_key:
type: string
readOnly: true
description: |
One-time secret key. Store it immediately. Exact
successful idempotent replays return the same secret
during the 5-minute encrypted replay window.
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'409':
$ref: '#/components/responses/IdempotencyConflict'
'422':
$ref: '#/components/responses/IdempotencyPayloadMismatch'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/v2/accounts/{account_id}/api-keys/{key_id}:
get:
summary: Get API Key
description: Returns a specific API key by ID
operationId: getAPIKey
tags:
- API Keys
parameters:
- name: account_id
in: path
required: true
description: Account ID
schema:
type: string
format: uuid
- name: key_id
in: path
required: true
description: API Key ID
schema:
type: string
format: uuid
security:
- BearerAuth: ["api-keys:read"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go/api"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
// Create context for the API call
ctx := context.Background()
// Call the ping endpoint
response, httpResp, err := client.APIKeysAPI.GetAPIKey(
ctx,
accountID,
uuid.MustParse("c5a32c40-b351-439f-8230-779daed3e42c"),
)
if err != nil {
log.Fatalf("Error getting API key: %v", err)
}
// Check response
if httpResp.StatusCode == 200 {
fmt.Printf("✅ Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("API key: %#v\n", response)
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const keyId = "00000000-0000-4000-8000-000000000001";
const apiKey = await client.apiKeys.get(keyId);
console.log("API key found.", { id: apiKey.id, label: apiKey.label });
responses:
'200':
description: API key details
content:
application/json:
schema:
$ref: '#/components/schemas/APIKey'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: API key not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
put:
summary: Update API Key
description: Updates an existing API key's label and scopes
operationId: updateAPIKey
tags:
- API Keys
parameters:
- name: account_id
in: path
required: true
description: Account ID
schema:
type: string
format: uuid
- name: key_id
in: path
required: true
description: API Key ID
schema:
type: string
format: uuid
security:
- BearerAuth: ["api-keys:write"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go"
"github.com/AhaSend/ahasend-go/api"
"github.com/AhaSend/ahasend-go/models/requests"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
// Create context for the API call
ctx := context.Background()
// Update an existing API key
response, httpResp, err := client.APIKeysAPI.UpdateAPIKey(
ctx,
accountID,
uuid.MustParse("c5a32c40-b351-439f-8230-779daed3e42c"),
requests.UpdateAPIKeyRequest{
Label: ahasend.String("My API Key"),
Scopes: &[]string{
"messages:read:all",
"domains:read",
},
// Replace the allowed source IPs. Use &[]string{} to clear the
// list (usable from any IP), or omit the field to leave the
// current list unchanged.
IPAllowList: &[]string{"203.0.113.0/24"},
},
)
if err != nil {
log.Fatalf("Error updating API key: %v", err)
}
// Check response
if httpResp.StatusCode == 200 {
fmt.Printf("✅ Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("Updated API key: %#v\n", response)
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const keyId = "00000000-0000-4000-8000-000000000001";
const apiKey = await client.apiKeys.update(keyId, { label: "Renamed API key" });
console.log("API key updated.", { id: apiKey.id, label: apiKey.label });
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/UpdateAPIKeyRequest'
responses:
'200':
description: API key updated successfully
content:
application/json:
schema:
$ref: '#/components/schemas/APIKey'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: API key not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'409':
description: >-
Conflict — the request would lock the calling API key out of its own
account. Returned only when a key updates itself with an
`ip_allow_list` that does not cover the caller's current source IP.
No change is persisted. This is a terminal message-only conflict;
it has no server error code or idempotency headers.
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
delete:
summary: Delete API Key
description: Deletes an API key
operationId: deleteAPIKey
tags:
- API Keys
parameters:
- name: account_id
in: path
required: true
description: Account ID
schema:
type: string
format: uuid
- name: key_id
in: path
required: true
description: API Key ID
schema:
type: string
format: uuid
security:
- BearerAuth: ["api-keys:delete"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go/api"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
// Create context for the API call
ctx := context.Background()
// Call the ping endpoint
response, httpResp, err := client.APIKeysAPI.DeleteAPIKey(
ctx,
accountID,
uuid.MustParse("c5a32c40-b351-439f-8230-779daed3e42c"),
)
if err != nil {
log.Fatalf("Error deleting API key: %v", err)
}
// Check response
if httpResp.StatusCode == 200 {
fmt.Printf("✅ Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("Deleted API key: %#v\n", response)
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const keyId = "00000000-0000-4000-8000-000000000001";
const result = await client.apiKeys.delete(keyId);
console.log("API key deleted.", { message: result.message });
responses:
'200':
description: API key deleted successfully
content:
application/json:
schema:
$ref: '#/components/schemas/SuccessResponse'
example:
message: "api key {id} ({label}) deleted successfully"
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: API key not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
# Domains endpoints
/v2/accounts/{account_id}/domains:
get:
summary: Get Domains
description: Returns a list of domains for the account
operationId: getDomains
tags:
- Domains
parameters:
- name: account_id
in: path
required: true
description: Account ID
schema:
type: string
format: uuid
- name: dns_valid
in: query
description: Filter results by DNS validation status
schema:
type: [boolean, 'null']
- name: limit
in: query
description: Maximum number of items to return (1-100)
schema:
type: integer
minimum: 1
maximum: 100
default: 100
- name: after
in: query
description: Pagination cursor for the next page. Provide the value provided in `next_cursor` from the response.
schema:
type: string
- name: before
in: query
description: Pagination cursor for the previous page.
schema:
type: string
security:
- BearerAuth: ["domains:read"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go/api"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
// Create context for the API call
ctx := context.Background()
// Call the ping endpoint
response, httpResp, err := client.DomainsAPI.GetDomains(
ctx,
accountID,
nil,
nil,
nil,
)
if err != nil {
log.Fatalf("Error getting domains: %v", err)
}
// Check response
if httpResp.StatusCode == 200 {
fmt.Printf("✅ Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("Found %d domains\n", len(response.Data))
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const page = await client.domains.list({ limit: 20 });
console.log("Domains listed.", { count: page.data.length });
responses:
'200':
description: List of domains
content:
application/json:
schema:
$ref: '#/components/schemas/PaginatedDomainsResponse'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
post:
summary: Create Domain
description: Creates a new domain
operationId: createDomain
tags:
- Domains
parameters:
- name: account_id
in: path
required: true
description: Account ID
schema:
type: string
format: uuid
- $ref: '#/components/parameters/IdempotencyKey'
security:
- BearerAuth: ["domains:write"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go/api"
"github.com/AhaSend/ahasend-go/models/requests"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
// Create context for the API call
ctx := context.Background()
// Call the ping endpoint
response, httpResp, err := client.DomainsAPI.CreateDomain(
ctx,
accountID,
requests.CreateDomainRequest{
Domain: "example.com",
},
)
if err != nil {
log.Fatalf("Error creating domain: %v", err)
}
// Check response
if httpResp.StatusCode == 201 {
fmt.Printf("✅ Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("Created domain: %#v\n", response)
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const domain = await client.domains.create(
{ domain: "example.com" },
{ idempotencyKey: "sdk-sample-create-domain" },
);
console.log("Domain created.", { id: domain.id, domain: domain.domain });
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/CreateDomainRequest'
responses:
'201':
description: Domain created successfully
headers:
Idempotent-Replayed:
$ref: '#/components/headers/IdempotentReplayed'
content:
application/json:
schema:
$ref: '#/components/schemas/Domain'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'409':
description: |
Either the domain already exists on the account or the idempotency-key
execution is in progress. The in-progress case is identified only
by `Idempotent-Replayed: false` plus a positive integer
`Retry-After`. A new duplicate-domain response has neither
header; a stored replay of that response has
`Idempotent-Replayed: true`. The message is not a stable
discriminator.
headers:
Idempotent-Replayed:
description: |
`false` with a positive `Retry-After` means an execution is in
progress. `true` means a stored duplicate-domain 409 was
replayed. Absent means a fresh duplicate-domain conflict.
schema:
type: string
enum: ['true', 'false']
Retry-After:
$ref: '#/components/headers/IdempotencyRetryAfter'
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'422':
$ref: '#/components/responses/IdempotencyPayloadMismatch'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/v2/accounts/{account_id}/domains/{domain}:
get:
summary: Get Domain
description: Returns a specific domain by name
operationId: getDomain
tags:
- Domains
parameters:
- name: account_id
in: path
required: true
description: Account ID
schema:
type: string
format: uuid
- name: domain
in: path
required: true
description: Domain name
schema:
type: string
format: hostname
security:
- BearerAuth: ["domains:read"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go/api"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
// Create context for the API call
ctx := context.Background()
// Call the ping endpoint
response, httpResp, err := client.DomainsAPI.GetDomain(
ctx,
accountID,
"example.com",
)
if err != nil {
log.Fatalf("Error getting domain: %v", err)
}
// Check response
if httpResp.StatusCode == 200 {
fmt.Printf("✅ Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("Domain: %#v\n", response)
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const domainName = "example.com";
const domain = await client.domains.get(domainName);
console.log("Domain found.", { domain: domain.domain, dnsValid: domain.dns_valid });
responses:
'200':
description: Domain details
content:
application/json:
schema:
$ref: '#/components/schemas/Domain'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: Domain not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
put:
summary: Update Domain
description: Updates DNS domain settings such as custom subdomains and DKIM rotation interval.
operationId: updateDomain
tags:
- Domains
parameters:
- name: account_id
in: path
required: true
description: Account ID
schema:
type: string
format: uuid
- name: domain
in: path
required: true
description: Domain name
schema:
type: string
format: hostname
security:
- BearerAuth: ["domains:write"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
ahasend "github.com/AhaSend/ahasend-go"
"github.com/AhaSend/ahasend-go/api"
"github.com/AhaSend/ahasend-go/models/requests"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
// Create context for the API call
ctx := context.Background()
// Update domain settings
response, httpResp, err := client.DomainsAPI.UpdateDomain(
ctx,
accountID,
"example.com",
requests.UpdateDomainRequest{
TrackingSubdomain: ahasend.String("click"),
ReturnPathSubdomain: ahasend.String("mail"),
DKIMRotationIntervalDays: ahasend.Int(45),
},
)
if err != nil {
log.Fatalf("Error updating domain: %v", err)
}
fmt.Printf("Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("Updated domain: %s\n", response.Domain)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const domainName = "example.com";
const domain = await client.domains.update(domainName, { tracking_subdomain: "click" });
console.log("Domain updated.", { domain: domain.domain });
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/UpdateDomainRequest'
responses:
'200':
description: Domain updated successfully
content:
application/json:
schema:
$ref: '#/components/schemas/Domain'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: Domain not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
delete:
summary: Delete Domain
description: Deletes a domain
operationId: deleteDomain
tags:
- Domains
parameters:
- name: account_id
in: path
required: true
description: Account ID
schema:
type: string
format: uuid
- name: domain
in: path
required: true
description: Domain name
schema:
type: string
format: hostname
security:
- BearerAuth: ["domains:delete:{domain}"]
- BearerAuth: ["domains:delete:all"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go/api"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
// Create context for the API call
ctx := context.Background()
// Call the ping endpoint
response, httpResp, err := client.DomainsAPI.DeleteDomain(
ctx,
accountID,
"example.com",
)
if err != nil {
log.Fatalf("Error deleting domain: %v", err)
}
// Check response
if httpResp.StatusCode == 200 {
fmt.Printf("✅ Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("Deleted domain: %#v\n", response)
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const domainName = "example.com";
const result = await client.domains.delete(domainName);
console.log("Domain deleted.", { message: result.message });
responses:
'200':
description: Domain deleted successfully
content:
application/json:
schema:
$ref: '#/components/schemas/SuccessResponse'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: Domain not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/v2/accounts/{account_id}/domains/{domain}/check-dns:
post:
summary: Check Domain DNS
description: Triggers a DNS validation check for the domain. If the domain was checked within the last 60 seconds, the cached validation result is returned instead of performing a fresh lookup.
operationId: checkDomainDNS
tags:
- Domains
parameters:
- name: account_id
in: path
required: true
description: Account ID
schema:
type: string
format: uuid
- name: domain
in: path
required: true
description: Domain name
schema:
type: string
format: hostname
security:
- BearerAuth: ["domains:write"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go/api"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
// Create context for the API call
ctx := context.Background()
// Trigger a DNS validation check
response, httpResp, err := client.DomainsAPI.CheckDomainDNS(
ctx,
accountID,
"example.com",
)
if err != nil {
log.Fatalf("Error checking domain DNS: %v", err)
}
fmt.Printf("Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("DNS valid: %t\n", response.DNSValid)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const domainName = "example.com";
const domain = await client.domains.checkDns(domainName);
console.log("DNS check completed.", { domain: domain.domain, dnsValid: domain.dns_valid });
responses:
'200':
description: Domain DNS status
content:
application/json:
schema:
$ref: '#/components/schemas/Domain'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: Domain not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'503':
description: Managed DNS is currently unavailable
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
# Messages endpoints
/v2/accounts/{account_id}/messages:
get:
summary: Get Messages
description: |
Returns a list of message summaries for the account. Can be filtered by various parameters.
`messages:read:all` can read across the account. Domain-scoped keys see
only messages for domains authorized by their matching read roles.
operationId: getMessages
tags:
- Messages
parameters:
- name: account_id
in: path
required: true
description: Account ID
schema:
type: string
format: uuid
- name: status
in: query
description: |
Filter by comma-separated list of message statuses. Allowed values are:
`Received`, `Delivered`, `Deferred`, `Bounced`, `Failed`, `Suppressed`,
`Sandbox Delivered`, `Sandbox Deferred`, `Sandbox Failed`, `Sandbox Bounced`,
and `Sandbox Suppressed`.
schema:
type: string
example: "Bounced,Failed"
- name: sender
in: query
description: Sender email address (must be from domain in API key scopes)
schema:
type: string
format: email
- name: recipient
in: query
description: Recipient email address
schema:
type: string
format: email
- name: subject
in: query
description: Filter by subject text
schema:
type: string
- name: message_id_header
in: query
description: Filter by message ID header (same ID returned by CreateMessage API)
schema:
type: string
- name: tags
in: query
description: Filter by comma-separated list of tags (max 20)
schema:
type: string
example: "billing,urgent"
- name: from_time
in: query
description: Filter messages created after this time (RFC3339 format)
schema:
type: string
format: date-time
example: "2023-12-25T10:30:00Z"
- name: to_time
in: query
description: Filter messages created before this time (RFC3339 format)
schema:
type: string
format: date-time
example: "2023-12-26T10:30:00Z"
- name: limit
in: query
description: Maximum number of items to return (1-100)
schema:
type: integer
minimum: 1
maximum: 100
default: 100
- name: after
in: query
description: Pagination cursor for the next page. Provide the value provided in `next_cursor` from the response.
schema:
type: string
- name: before
in: query
description: Pagination cursor for the previous page.
schema:
type: string
security:
- BearerAuth: ["messages:read:all"]
- BearerAuth: ["messages:read:{domain}"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go"
"github.com/AhaSend/ahasend-go/api"
"github.com/AhaSend/ahasend-go/models/requests"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
// Create context for the API call
ctx := context.Background()
// Call the ping endpoint
response, httpResp, err := client.MessagesAPI.GetMessages(
ctx,
accountID,
requests.GetMessagesParams{
Status: ahasend.String("Bounced,Failed"),
Sender: ahasend.String("info@example.com"),
Tags: []string{"billing", "urgent"},
},
)
if err != nil {
log.Fatalf("Error getting messages: %v", err)
}
// Check response
if httpResp.StatusCode == 200 {
fmt.Printf("✅ Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("Found %d messages\n", len(response.Data))
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const page = await client.messages.list({ limit: 20 });
console.log("Messages listed.", { count: page.data.length });
responses:
'200':
description: List of messages
content:
application/json:
schema:
$ref: '#/components/schemas/PaginatedMessagesResponse'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
post:
summary: Create Message
description: |
Creates and sends a message to one or more recipients. This API cannot be used if you want to send a conversational/P2P message and set CC or BCC. Use [Create Conversation Message](https://ahasend.com/docs/api-reference/messages/create-conversation) instead.
**Validation Requirements:**
- Either `text_content` or `html_content` is required
- `from.email` must be from a domain you own with valid DNS records
- `retention.metadata` must be between 1 and 30 days
- `retention.data` must be between 0 and 30 days
- If `reply_to` is provided, do not include `reply-to` in headers
- `message-id` header will be ignored and automatically generated
- Schedule times must be in RFC3339 format
- `schedule.first_attempt` must be in the future and within 7 days of the request
- `schedule.expires` must be in the future and within 8 days of the request
Authorization uses the domain in `from.email`: either
`messages:send:all` or the matching domain-specific send role is
sufficient.
operationId: createMessage
tags:
- Messages
parameters:
- name: account_id
in: path
required: true
description: Account ID
schema:
type: string
format: uuid
- $ref: '#/components/parameters/IdempotencyKey'
security:
- BearerAuth: ["messages:send:all"]
- BearerAuth: ["messages:send:{domain}"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go"
"github.com/AhaSend/ahasend-go/api"
"github.com/AhaSend/ahasend-go/models/common"
"github.com/AhaSend/ahasend-go/models/requests"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
// Create context for the API call
ctx := context.Background()
response, httpResp, err := client.MessagesAPI.CreateMessage(
ctx,
accountID,
requests.CreateMessageRequest{
From: common.Address{
Email: "info@example.com",
Name: ahasend.String("Example Corp."),
},
Recipients: []common.Recipient{
{
Email: "john@example.com",
Name: ahasend.String("John Smith"),
},
},
Subject: "Hello",
TextContent: ahasend.String("Hello world!"),
Sandbox: ahasend.Bool(true),
},
)
if err != nil {
log.Fatalf("Error sending message: %v", err)
}
// Check response
if httpResp.StatusCode == 202 {
fmt.Printf("✅ Send successful! Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("Message ID: %s\n", *response.Data[0].ID)
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const result = await client.messages.send(
{
from: { email: "sender@example.com", name: "Example" },
recipients: [{ email: "recipient@example.net" }],
subject: "Hello from AhaSend",
html_content: "Hello!
",
sandbox: true,
},
{ idempotencyKey: "sdk-sample-send-message" },
);
console.log("Sandbox message accepted.", { count: result.data.length });
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/CreateMessageRequest'
responses:
'202':
description: Message created successfully
headers:
Idempotent-Replayed:
$ref: '#/components/headers/IdempotentReplayed'
content:
application/json:
schema:
$ref: '#/components/schemas/CreateMessageResponse'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'409':
$ref: '#/components/responses/IdempotencyConflict'
'422':
$ref: '#/components/responses/IdempotencyPayloadMismatch'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/v2/accounts/{account_id}/messages/conversation:
post:
summary: Create Conversational Message
description: |
Creates and sends a conversational message (with support for CC and BCC) to one or more recipients. This API does not support template substitutions, use [Create Message](https://ahasend.com/docs/api-reference/messages/create-message) instead if you need substitutions.
**Validation Requirements:**
- Either `text_content` or `html_content` is required
- `from.email` must be from a domain you own with valid DNS records
- `retention.metadata` must be between 1 and 30 days
- `retention.data` must be between 0 and 30 days
- If the `reply_to` parameter is provided, do not include `reply-to` in headers
- If the `cc` parameter is provided, do not include `cc` in headers
- `message-id` header will be ignored and automatically generated
- Schedule times must be in RFC3339 format
- `schedule.first_attempt` must be in the future and within 7 days of the request
- `schedule.expires` must be in the future and within 8 days of the request
Authorization uses the domain in `from.email`: either
`messages:send:all` or the matching domain-specific send role is
sufficient.
operationId: createConversationMessage
tags:
- Messages
parameters:
- name: account_id
in: path
required: true
description: Account ID
schema:
type: string
format: uuid
- $ref: '#/components/parameters/IdempotencyKey'
security:
- BearerAuth: ["messages:send:all"]
- BearerAuth: ["messages:send:{domain}"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go"
"github.com/AhaSend/ahasend-go/api"
"github.com/AhaSend/ahasend-go/models/common"
"github.com/AhaSend/ahasend-go/models/requests"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
// Create context for the API call
ctx := context.Background()
// A conversational message sets the To/CC/BCC headers directly, so
// recipients can see each other (BCC excluded). The combined
// To + CC + BCC count must not exceed 50. Unlike Create Message,
// this endpoint does not support template substitutions.
response, httpResp, err := client.MessagesAPI.CreateConversationMessage(
ctx,
accountID,
requests.CreateConversationMessageRequest{
From: common.SenderAddress{
Email: "info@example.com",
Name: ahasend.String("Example Corp."),
},
To: []common.SenderAddress{
{Email: "john@example.com", Name: ahasend.String("John Smith")},
{Email: "jane@example.com", Name: ahasend.String("Jane Doe")},
},
CC: []common.SenderAddress{
{Email: "hr@example.com", Name: ahasend.String("Example Corp HR")},
},
BCC: []common.SenderAddress{
{Email: "archive@example.com"},
},
Subject: "Welcome to Example Corp",
HtmlContent: ahasend.String("Dear John and Jane, welcome to Example Corp!
"),
TextContent: ahasend.String("Dear John and Jane, welcome to Example Corp!"),
Sandbox: ahasend.Bool(true),
},
)
if err != nil {
log.Fatalf("Error sending conversational message: %v", err)
}
// Check response
if httpResp.StatusCode == 202 {
fmt.Printf("✅ Send successful! Status: %d\n", httpResp.StatusCode)
if response != nil && len(response.Data) > 0 && response.Data[0].ID != nil {
fmt.Printf("Message ID: %s\n", *response.Data[0].ID)
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const result = await client.messages.sendConversation(
{
from: { email: "sender@example.com", name: "Example" },
to: [{ email: "recipient@example.net" }],
subject: "Hello from AhaSend",
html_content: "Hello!
",
sandbox: true,
},
{ idempotencyKey: "sdk-sample-send-conversation" },
);
console.log("Sandbox conversation accepted.", { count: result.data.length });
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/CreateConversationMessageRequest'
responses:
'202':
description: Message created successfully
headers:
Idempotent-Replayed:
$ref: '#/components/headers/IdempotentReplayed'
content:
application/json:
schema:
$ref: '#/components/schemas/CreateMessageResponse'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'409':
$ref: '#/components/responses/IdempotencyConflict'
'422':
$ref: '#/components/responses/IdempotencyPayloadMismatch'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/v2/accounts/{account_id}/messages/{message_id}:
get:
summary: Get Message
description: |
Returns the complete message by its ID, including raw content and parsed content structure.
Access requires `messages:read:all` or a read role matching the
message's sender domain.
operationId: getMessage
tags:
- Messages
parameters:
- name: account_id
in: path
required: true
description: Account ID
schema:
type: string
format: uuid
- name: message_id
in: path
required: true
description: Message API ID. Accepts the generated Message-ID returned by [Create Message API](https://ahasend.com/docs/api-reference/messages/create-message), for example ``, or the bare UUID portion.
schema:
type: string
security:
- BearerAuth: ["messages:read:all"]
- BearerAuth: ["messages:read:{domain}"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go/api"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
messageID := uuid.New()
// Create context for the API call
ctx := context.Background()
// Fetch a single message by ID
response, httpResp, err := client.MessagesAPI.GetMessage(ctx, accountID, messageID)
if err != nil {
log.Fatalf("Error getting message: %v", err)
}
if httpResp.StatusCode == 200 {
fmt.Printf("✅ Message retrieved! Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("Subject: %s\n", response.Subject)
fmt.Printf("Status: %s\n", response.Status)
fmt.Printf("Sender: %s\n", response.Sender)
fmt.Printf("Recipient: %s\n", response.Recipient)
fmt.Printf("Attempts: %d\n", response.NumAttempts)
fmt.Printf("Opens: %d\n", response.OpenCount)
fmt.Printf("Clicks: %d\n", response.ClickCount)
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const messageId = "00000000-0000-4000-8000-000000000002";
const message = await client.messages.get(messageId);
console.log("Message found.", { id: message.id, status: message.status });
responses:
'200':
description: Message details
content:
application/json:
schema:
$ref: '#/components/schemas/Message'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: Message not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/v2/accounts/{account_id}/messages/{message_id}/cancel:
delete:
summary: Cancel Message
description: |
Cancels a scheduled message. Access requires `messages:cancel:all` or a
cancel role matching the message's sender domain.
operationId: cancelMessage
tags:
- Messages
parameters:
- name: account_id
in: path
required: true
description: Account ID
schema:
type: string
format: uuid
- name: message_id
in: path
required: true
description: Message API ID. Accepts the generated Message-ID returned by [Create Message API](https://ahasend.com/docs/api-reference/messages/create-message), for example ``, or the bare UUID portion.
schema:
type: string
security:
- BearerAuth: ["messages:cancel:all"]
- BearerAuth: ["messages:cancel:{domain}"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go/api"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
// Create context for the API call
ctx := context.Background()
response, httpResp, err := client.MessagesAPI.CancelMessage(
ctx,
accountID,
"",
)
if err != nil {
log.Fatalf("Error canceling message: %v", err)
}
// Check response
if httpResp.StatusCode == 200 {
fmt.Printf("✅ Successfully canceled! Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("Message canceled: %s\n", response.Message)
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const messageId = "00000000-0000-4000-8000-000000000002";
const result = await client.messages.cancel(messageId);
console.log("Message cancellation requested.", { message: result.message });
responses:
'200':
description: Scheduled message is cancelled
content:
application/json:
schema:
$ref: '#/components/schemas/SuccessResponse'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: Message not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
# Account endpoints
/v2/accounts/{account_id}:
get:
summary: Get Account
description: Returns account information
operationId: getAccount
tags:
- Accounts
parameters:
- name: account_id
in: path
required: true
description: Account ID
schema:
type: string
format: uuid
security:
- BearerAuth: ["accounts:read"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go/api"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
// Create context for the API call
ctx := context.Background()
response, httpResp, err := client.AccountsAPI.GetAccount(ctx, accountID)
if err != nil {
log.Fatalf("Error getting account: %v", err)
}
if httpResp.StatusCode == 200 {
fmt.Printf("✅ Account retrieved. Status: %d\n", httpResp.StatusCode)
fmt.Printf("ID: %s\n", response.ID)
fmt.Printf("Name: %s\n", response.Name)
fmt.Printf("Owner ID: %s\n", response.OwnerID)
if response.Website != nil {
fmt.Printf("Website: %s\n", *response.Website)
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const account = await client.accounts.get();
console.log("Account found.", { id: account.id, name: account.name });
responses:
'200':
description: Account details
content:
application/json:
schema:
$ref: '#/components/schemas/Account'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: Account not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
put:
summary: Update Account
description: |
Updates account settings
**Validation Requirements:**
- `name` must be maximum 255 characters
- `website` must be a valid URL
- `message_metadata_retention` must be between 1 and 30 days
- `message_data_retention` must be between 0 and 30 days
operationId: updateAccount
tags:
- Accounts
parameters:
- name: account_id
in: path
required: true
description: Account ID
schema:
type: string
format: uuid
security:
- BearerAuth: ["accounts:write"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go"
"github.com/AhaSend/ahasend-go/api"
"github.com/AhaSend/ahasend-go/models/requests"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
// Create context for the API call
ctx := context.Background()
// Update the account name and open/click tracking settings
response, httpResp, err := client.AccountsAPI.UpdateAccount(ctx, accountID, requests.UpdateAccountRequest{
Name: ahasend.String("Acme Corp"),
TrackOpens: ahasend.Bool(true),
TrackClicks: ahasend.Bool(true),
})
if err != nil {
log.Fatalf("Error updating account: %v", err)
}
if httpResp.StatusCode == 200 {
fmt.Printf("✅ Account updated! Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("ID: %s\n", response.ID)
fmt.Printf("Name: %s\n", response.Name)
if response.TrackOpens != nil {
fmt.Printf("Track Opens: %t\n", *response.TrackOpens)
}
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const account = await client.accounts.update({ name: "Example, Inc." });
console.log("Account updated.", { id: account.id, name: account.name });
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/UpdateAccountRequest'
responses:
'200':
description: Account updated successfully
content:
application/json:
schema:
$ref: '#/components/schemas/Account'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: Account not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/v2/accounts/{account_id}/members:
get:
summary: Get Account Members
description: Returns a list of account members
operationId: getAccountMembers
tags:
- Accounts
parameters:
- name: account_id
in: path
required: true
description: Account ID
schema:
type: string
format: uuid
security:
- BearerAuth: ["accounts:members:read"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go/api"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
// Create context for the API call
ctx := context.Background()
// List the members of the account
response, httpResp, err := client.AccountsAPI.GetAccountMembers(ctx, accountID)
if err != nil {
log.Fatalf("Error listing account members: %v", err)
}
// Check response
if httpResp.StatusCode == 200 {
fmt.Printf("✅ Retrieved account members! Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("Found %d account members\n", len(response.Data))
for _, member := range response.Data {
fmt.Printf("- User: %s, Role: %s\n", member.UserID, member.Role)
}
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const members = await client.accounts.listMembers();
console.log("Account members listed.", { count: members.data.length });
responses:
'200':
description: List of account members
content:
application/json:
schema:
$ref: '#/components/schemas/AccountMembersResponse'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
post:
summary: Add Account Member
description: |
Adds a new member to the account
**Validation Requirements:**
- `email` must be a valid email address
- `role` must be one of: Administrator, Developer, Analyst, Billing Manager
operationId: addAccountMember
tags:
- Accounts
parameters:
- name: account_id
in: path
required: true
description: Account ID
schema:
type: string
format: uuid
- $ref: '#/components/parameters/IdempotencyKey'
security:
- BearerAuth: ["accounts:members:add"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go"
"github.com/AhaSend/ahasend-go/api"
"github.com/AhaSend/ahasend-go/models/requests"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
// Create context for the API call
ctx := context.Background()
response, httpResp, err := client.AccountsAPI.AddAccountMember(ctx, accountID, requests.AddMemberRequest{
Email: "teammate@example.com",
Name: ahasend.String("Jordan Lee"),
Role: "Developer",
}, api.WithIdempotencyKey("add-member-20240101-jordan"))
if err != nil {
log.Fatalf("Error adding account member: %v", err)
}
if httpResp.StatusCode == 201 {
fmt.Printf("✅ Member added successfully! Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("User ID: %s\n", response.UserID)
fmt.Printf("Role: %s\n", response.Role)
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const member = await client.accounts.addMember(
{ email: "developer@example.com", role: "Developer" },
{ idempotencyKey: "sdk-sample-add-account-member" },
);
console.log("Account member added.", { userId: member.user_id, role: member.role });
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/AddMemberRequest'
responses:
'201':
description: Member added successfully
headers:
Idempotent-Replayed:
$ref: '#/components/headers/IdempotentReplayed'
content:
application/json:
schema:
$ref: '#/components/schemas/UserAccount'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'409':
description: |
Either the user is already a member of the account or the idempotency-key
execution is in progress. The in-progress case is identified only
by `Idempotent-Replayed: false` plus a positive integer
`Retry-After`. A new duplicate-member response has neither
header; a stored replay of that response has
`Idempotent-Replayed: true`. The message is not a stable
discriminator.
headers:
Idempotent-Replayed:
description: |
`false` with a positive `Retry-After` means an execution is in
progress. `true` means a stored duplicate-member 409 was
replayed. Absent means a fresh duplicate-member conflict.
schema:
type: string
enum: ['true', 'false']
Retry-After:
$ref: '#/components/headers/IdempotencyRetryAfter'
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'422':
$ref: '#/components/responses/IdempotencyPayloadMismatch'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/v2/accounts/{account_id}/members/{user_id}:
delete:
summary: Remove Account Member
description: |
Removes a member from the account
**Restrictions:**
- You cannot delete yourself
- You cannot delete the account owner
operationId: removeAccountMember
tags:
- Accounts
parameters:
- name: account_id
in: path
required: true
description: Account ID
schema:
type: string
format: uuid
- name: user_id
in: path
required: true
description: User ID
schema:
type: string
format: uuid
security:
- BearerAuth: ["accounts:members:remove"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go/api"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
userID := uuid.New()
// Create context for the API call
ctx := context.Background()
// Remove the member from the account by user ID
response, httpResp, err := client.AccountsAPI.RemoveAccountMember(ctx, accountID, userID)
if err != nil {
log.Fatalf("Error removing account member: %v", err)
}
if httpResp.StatusCode == 200 {
fmt.Printf("✅ Account member removed! Status: %d\n", httpResp.StatusCode)
if response != nil && response.Message != "" {
fmt.Printf("Response: %s\n", response.Message)
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const userId = "00000000-0000-4000-8000-000000000003";
const result = await client.accounts.removeMember(userId);
console.log("Account member removed.", { message: result.message });
responses:
'200':
description: Member removed successfully
content:
application/json:
schema:
$ref: '#/components/schemas/SuccessResponse'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: Member not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
# Sub-account endpoints
/v2/accounts/{account_id}/sub-accounts:
get:
summary: List Sub Accounts
description: Returns a cursor-paginated list of sub accounts under the parent account. Soft-deleted sub accounts are not included; usage billed for sub accounts deleted during the current period is reported by the usage endpoint's `removed_sub_accounts` aggregate.
operationId: listSubAccounts
tags:
- Sub Accounts
parameters:
- name: account_id
in: path
required: true
description: Parent account ID
schema:
type: string
format: uuid
- name: limit
in: query
description: Maximum number of items to return (1-100)
schema:
type: integer
minimum: 1
maximum: 100
default: 100
- name: after
in: query
description: Pagination cursor for the next page. Provide the value from `next_cursor` in the response.
schema:
type: string
- name: before
in: query
description: Pagination cursor for the previous page. Provide the value from `previous_cursor` in the response.
schema:
type: string
security:
- BearerAuth: ["sub-accounts:read"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go"
"github.com/AhaSend/ahasend-go/api"
"github.com/AhaSend/ahasend-go/models/common"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
// Create context for the API call
ctx := context.Background()
// List sub accounts (limit results to 50 per page)
response, httpResp, err := client.SubAccountsAPI.ListSubAccounts(ctx, accountID, &common.PaginationParams{Limit: ahasend.Int32(50)})
if err != nil {
log.Fatalf("Error listing sub accounts: %v", err)
}
if httpResp.StatusCode == 200 {
fmt.Printf("✅ Sub accounts listed! Status: %d\n", httpResp.StatusCode)
fmt.Printf("Found %d sub accounts\n", len(response.Data))
for _, sub := range response.Data {
fmt.Printf("- ID: %s, Name: %s, Status: %s\n", sub.ID, sub.Name, sub.Status)
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const page = await client.subAccounts.list({ limit: 20 });
console.log("Sub-accounts listed.", { count: page.data.length });
responses:
'200':
description: List of sub accounts
content:
application/json:
schema:
$ref: '#/components/schemas/PaginatedSubAccountsResponse'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: Parent account not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
post:
summary: Create Sub Account
description: Creates a new sub account under the parent account
operationId: createSubAccount
tags:
- Sub Accounts
parameters:
- name: account_id
in: path
required: true
description: Parent account ID
schema:
type: string
format: uuid
- $ref: '#/components/parameters/IdempotencyKey'
security:
- BearerAuth: ["sub-accounts:write"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go"
"github.com/AhaSend/ahasend-go/api"
"github.com/AhaSend/ahasend-go/models/requests"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
// Create context for the API call
ctx := context.Background()
// Create a sub account with an idempotency key for safe retries
response, httpResp, err := client.SubAccountsAPI.CreateSubAccount(ctx, accountID, requests.CreateSubAccountRequest{
Name: "Acme Subsidiary",
Website: "acme.example.com",
MonthlyCredit: ahasend.Int64(0),
}, api.WithIdempotencyKey("subacct-20240101-acme"))
if err != nil {
log.Fatalf("Error creating sub account: %v", err)
}
if httpResp.StatusCode == 201 {
fmt.Printf("✅ Sub account created! Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("ID: %s\n", response.ID)
fmt.Printf("Name: %s\n", response.Name)
fmt.Printf("Status: %s\n", response.Status)
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const subAccount = await client.subAccounts.create(
{ name: "Example subsidiary", website: "subsidiary.example.com" },
{ idempotencyKey: "sdk-sample-create-sub-account" },
);
console.log("Sub-account created.", { id: subAccount.id, status: subAccount.status });
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/CreateSubAccountRequest'
responses:
'201':
description: Sub account created successfully
headers:
Idempotent-Replayed:
$ref: '#/components/headers/IdempotentReplayed'
content:
application/json:
schema:
$ref: '#/components/schemas/SubAccount'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: Parent account not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'409':
$ref: '#/components/responses/IdempotencyConflict'
'422':
$ref: '#/components/responses/IdempotencyPayloadMismatch'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/v2/accounts/{account_id}/sub-accounts/usage:
get:
summary: Get Sub-Account Usage
description: Returns current billing-period usage and proportional allocated cost for the parent and active sub accounts
operationId: getSubAccountsUsage
tags:
- Sub Accounts
parameters:
- name: account_id
in: path
required: true
description: Parent account ID
schema:
type: string
format: uuid
security:
- BearerAuth: ["sub-accounts:usage"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go/api"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
// Create context for the API call
ctx := context.Background()
response, httpResp, err := client.SubAccountsAPI.GetSubAccountsUsage(ctx, accountID)
if err != nil {
log.Fatalf("Error getting sub-accounts usage: %v", err)
}
if httpResp.StatusCode == 200 {
fmt.Printf("✅ Retrieved sub-accounts usage! Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("Currency: %s\n", response.Currency)
fmt.Printf("Allocation method: %s\n", response.AllocationMethod)
fmt.Printf("Total reception count: %d\n", response.Total.ReceptionCount)
fmt.Printf("Total allocated cost: %.2f\n", response.Total.AllocatedCost)
fmt.Printf("Sub-accounts: %d\n", len(response.SubAccounts))
for i, sub := range response.SubAccounts {
fmt.Printf(" [%d] reception count: %d, allocated cost: %.2f\n", i, sub.ReceptionCount, sub.AllocatedCost)
}
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const usage = await client.subAccounts.usage();
console.log("Sub-account usage loaded.", {
currency: usage.currency,
subAccountCount: usage.sub_accounts.length,
});
responses:
'200':
description: Sub-account usage breakdown
content:
application/json:
schema:
$ref: '#/components/schemas/SubAccountUsageResponse'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: Parent account not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/v2/accounts/{account_id}/sub-accounts/{sub_account_id}:
get:
summary: Get Sub Account
description: Returns a specific sub account under the parent account
operationId: getSubAccount
tags:
- Sub Accounts
parameters:
- name: account_id
in: path
required: true
description: Parent account ID
schema:
type: string
format: uuid
- name: sub_account_id
in: path
required: true
description: Sub account ID
schema:
type: string
format: uuid
security:
- BearerAuth: ["sub-accounts:read"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go/api"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
subAccountID := uuid.New()
// Create context for the API call
ctx := context.Background()
// Get a single sub account by ID
response, httpResp, err := client.SubAccountsAPI.GetSubAccount(
ctx,
accountID,
subAccountID,
)
if err != nil {
log.Fatalf("Error getting sub account: %v", err)
}
if httpResp.StatusCode == 200 {
fmt.Printf("✅ Retrieved sub account. Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("ID: %s\n", response.ID)
fmt.Printf("Name: %s\n", response.Name)
fmt.Printf("Website: %s\n", response.Website)
fmt.Printf("Status: %s\n", response.Status)
fmt.Printf("Domain count: %d\n", response.DomainCount)
fmt.Printf("Member count: %d\n", response.MemberCount)
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const subAccountId = "00000000-0000-4000-8000-000000000004";
const subAccount = await client.subAccounts.get(subAccountId);
console.log("Sub-account found.", { id: subAccount.id, status: subAccount.status });
responses:
'200':
description: Sub account details
content:
application/json:
schema:
$ref: '#/components/schemas/SubAccount'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: Sub account not found under the parent account
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
put:
summary: Update Sub Account
description: Updates a sub account's editable settings
operationId: updateSubAccount
tags:
- Sub Accounts
parameters:
- name: account_id
in: path
required: true
description: Parent account ID
schema:
type: string
format: uuid
- name: sub_account_id
in: path
required: true
description: Sub account ID
schema:
type: string
format: uuid
security:
- BearerAuth: ["sub-accounts:write"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go"
"github.com/AhaSend/ahasend-go/api"
"github.com/AhaSend/ahasend-go/models/requests"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
subAccountID := uuid.New()
// Create context for the API call
ctx := context.Background()
response, httpResp, err := client.SubAccountsAPI.UpdateSubAccount(ctx, accountID, subAccountID, requests.UpdateSubAccountRequest{Name: ahasend.String("Acme Subsidiary"), MonthlyCredit: ahasend.Int64(50000)})
if err != nil {
log.Fatalf("Error updating sub account: %v", err)
}
if httpResp.StatusCode == 200 {
fmt.Printf("✅ Sub account updated! Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("ID: %s\n", response.ID)
fmt.Printf("Name: %s\n", response.Name)
fmt.Printf("MonthlyCredit: %d\n", response.MonthlyCredit)
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const subAccountId = "00000000-0000-4000-8000-000000000004";
const subAccount = await client.subAccounts.update(subAccountId, {
name: "Renamed subsidiary",
});
console.log("Sub-account updated.", { id: subAccount.id, status: subAccount.status });
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/UpdateSubAccountRequest'
responses:
'200':
description: Sub account updated successfully
content:
application/json:
schema:
$ref: '#/components/schemas/SubAccount'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: Sub account not found under the parent account
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
delete:
summary: Delete Sub Account
description: Soft-deletes a sub account under the parent account
operationId: deleteSubAccount
tags:
- Sub Accounts
parameters:
- name: account_id
in: path
required: true
description: Parent account ID
schema:
type: string
format: uuid
- name: sub_account_id
in: path
required: true
description: Sub account ID
schema:
type: string
format: uuid
security:
- BearerAuth: ["sub-accounts:delete"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go/api"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
subAccountID := uuid.New()
// Create context for the API call
ctx := context.Background()
// Soft-delete the sub account
response, httpResp, err := client.SubAccountsAPI.DeleteSubAccount(ctx, accountID, subAccountID)
if err != nil {
log.Fatalf("Error deleting sub account: %v", err)
}
if httpResp.StatusCode == 200 {
fmt.Printf("✅ Sub account deleted! Status: %d\n", httpResp.StatusCode)
if response != nil && response.Message != "" {
fmt.Printf("Response: %s\n", response.Message)
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const subAccountId = "00000000-0000-4000-8000-000000000004";
const result = await client.subAccounts.delete(subAccountId);
console.log("Sub-account deleted.", { message: result.message });
responses:
'200':
description: Sub account deleted successfully
content:
application/json:
schema:
$ref: '#/components/schemas/SuccessResponse'
example:
message: "sub account deleted"
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: Sub account not found under the parent account
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/v2/accounts/{account_id}/sub-accounts/{sub_account_id}/suspend:
post:
summary: Suspend Sub Account
description: Suspends a sub account under the parent account
operationId: suspendSubAccount
tags:
- Sub Accounts
parameters:
- name: account_id
in: path
required: true
description: Parent account ID
schema:
type: string
format: uuid
- name: sub_account_id
in: path
required: true
description: Sub account ID
schema:
type: string
format: uuid
security:
- BearerAuth: ["sub-accounts:suspend"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go/api"
"github.com/AhaSend/ahasend-go/models/requests"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
subAccountID := uuid.New()
// Create context for the API call
ctx := context.Background()
response, httpResp, err := client.SubAccountsAPI.SuspendSubAccount(ctx, accountID, subAccountID, requests.SuspendSubAccountRequest{
Reason: "Customer requested temporary pause",
})
if err != nil {
log.Fatalf("Error suspending sub account: %v", err)
}
if httpResp.StatusCode == 200 {
fmt.Printf("✅ Sub account suspended. Status: %d\n", httpResp.StatusCode)
fmt.Printf("ID: %s\n", response.ID)
fmt.Printf("Status: %s\n", response.Status)
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const subAccountId = "00000000-0000-4000-8000-000000000004";
const subAccount = await client.subAccounts.suspend(subAccountId, {
reason: "Requested by account administrator",
});
console.log("Sub-account suspended.", { id: subAccount.id, status: subAccount.status });
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/SuspendSubAccountRequest'
responses:
'200':
description: Sub account suspended successfully
content:
application/json:
schema:
$ref: '#/components/schemas/SubAccount'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: Sub account not found under the parent account
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/v2/accounts/{account_id}/sub-accounts/{sub_account_id}/unsuspend:
post:
summary: Unsuspend Sub Account
description: Unsuspends a sub account under the parent account
operationId: unsuspendSubAccount
tags:
- Sub Accounts
parameters:
- name: account_id
in: path
required: true
description: Parent account ID
schema:
type: string
format: uuid
- name: sub_account_id
in: path
required: true
description: Sub account ID
schema:
type: string
format: uuid
security:
- BearerAuth: ["sub-accounts:suspend"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go/api"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
subAccountID := uuid.New()
// Create context for the API call
ctx := context.Background()
// Unsuspend the sub account
response, httpResp, err := client.SubAccountsAPI.UnsuspendSubAccount(ctx, accountID, subAccountID)
if err != nil {
log.Fatalf("Error unsuspending sub account: %v", err)
}
if httpResp.StatusCode == 200 {
fmt.Printf("✅ Sub account unsuspended! Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("Sub Account ID: %s\n", response.ID)
fmt.Printf("Status: %s\n", response.Status)
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const subAccountId = "00000000-0000-4000-8000-000000000004";
const subAccount = await client.subAccounts.unsuspend(subAccountId);
console.log("Sub-account unsuspended.", { id: subAccount.id, status: subAccount.status });
responses:
'200':
description: Sub account unsuspended successfully
content:
application/json:
schema:
$ref: '#/components/schemas/SubAccount'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: Sub account not found under the parent account
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/v2/accounts/{account_id}/sub-accounts/{sub_account_id}/api-keys:
get:
summary: List Sub-Account API Keys
description: Returns a cursor-paginated list of API keys owned by a sub account. The `secret_key` field is omitted from list responses.
operationId: listSubAccountAPIKeys
tags:
- Sub Accounts
parameters:
- name: account_id
in: path
required: true
description: Parent account ID
schema:
type: string
format: uuid
- name: sub_account_id
in: path
required: true
description: Sub account ID
schema:
type: string
format: uuid
- name: limit
in: query
description: Maximum number of items to return (1-100)
schema:
type: integer
minimum: 1
maximum: 100
default: 100
- name: after
in: query
description: Pagination cursor for the next page. Provide the value from `next_cursor` in the response.
schema:
type: string
- name: before
in: query
description: Pagination cursor for the previous page. Provide the value from `previous_cursor` in the response.
schema:
type: string
security:
- BearerAuth: ["sub-account-api-keys:read"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go"
"github.com/AhaSend/ahasend-go/api"
"github.com/AhaSend/ahasend-go/models/common"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
subAccountID := uuid.New()
// Create context for the API call
ctx := context.Background()
// List a sub-account's API keys (paginated, up to 50 per page).
// Note: secret_key is omitted from list responses; only create returns it once.
response, httpResp, err := client.SubAccountsAPI.ListSubAccountAPIKeys(
ctx,
accountID,
subAccountID,
&common.PaginationParams{Limit: ahasend.Int32(50)},
)
if err != nil {
log.Fatalf("Error listing sub-account API keys: %v", err)
}
if httpResp.StatusCode == 200 {
fmt.Printf("✅ Listed sub-account API keys. Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("Found %d API keys\n", len(response.Data))
for _, key := range response.Data {
fmt.Printf("API key %s: %s\n", key.ID, key.Label)
}
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const subAccountId = "00000000-0000-4000-8000-000000000004";
const page = await client.subAccounts.apiKeys.list(subAccountId, { limit: 20 });
console.log("Sub-account API keys listed.", { count: page.data.length });
responses:
'200':
description: List of sub-account API keys
content:
application/json:
schema:
$ref: '#/components/schemas/PaginatedAPIKeysResponse'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: Sub account not found under the parent account
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
post:
summary: Create Sub-Account API Key
description: |
Creates an API key owned by the sub account. Parent credentials must belong to the parent account and include `sub-account-api-keys:write`; sub-account credentials cannot manage nested API keys. The returned `secret_key` authenticates as the child account and should be stored immediately.
Bootstrap example:
1. Create the sub account with `POST /v2/accounts/{account_id}/sub-accounts` and a unique `Idempotency-Key`.
2. Create the bootstrap child API key with this endpoint and a different unique `Idempotency-Key`.
3. Store the one-time `secret_key` from the `201` response. Exact idempotent replays within 5 minutes return the same `secret_key`.
4. Use that child secret with the child `sub_account_id` as the `account_id` on ordinary v2 routes.
operationId: createSubAccountAPIKey
tags:
- Sub Accounts
parameters:
- name: account_id
in: path
required: true
description: Parent account ID
schema:
type: string
format: uuid
- name: sub_account_id
in: path
required: true
description: Sub account ID
schema:
type: string
format: uuid
- $ref: '#/components/parameters/IdempotencyKey'
security:
- BearerAuth: ["sub-account-api-keys:write"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go/api"
"github.com/AhaSend/ahasend-go/models/requests"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
subAccountID := uuid.New()
// Create context for the API call
ctx := context.Background()
// Bootstrap an API key for the sub-account (idempotency key makes retries safe)
response, httpResp, err := client.SubAccountsAPI.CreateSubAccountAPIKey(
ctx,
accountID,
subAccountID,
requests.CreateAPIKeyRequest{
Label: "Bootstrap key",
Scopes: []string{"messages:send:all", "domains:read"},
// Optional: restrict the sub-account key to specific source IPs.
IPAllowList: []string{"203.0.113.0/24"},
},
api.WithIdempotencyKey("child-bootstrap-key-20240101-acme"),
)
if err != nil {
log.Fatalf("Error creating sub-account API key: %v", err)
}
if httpResp.StatusCode == 201 {
fmt.Printf("✅ Sub-account API key created. Status: %d\n", httpResp.StatusCode)
fmt.Printf("ID: %s\n", response.ID)
fmt.Printf("Label: %s\n", response.Label)
fmt.Printf("Public key: %s\n", response.PublicKey)
// SecretKey is the one-time secret, returned ONLY on create.
if response.SecretKey != nil {
// Store this value immediately — it cannot be retrieved again later.
fmt.Printf("Secret key (store this now, shown only once): %s\n", *response.SecretKey)
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: shell
label: Bootstrap child API key
source: |
PARENT_ACCOUNT_ID="9d0cf9d0-4f5e-4674-bcf1-8ec39968b6e1"
PARENT_SECRET="aha-sk-parent-64-character-key"
curl -sS -X POST "https://api.ahasend.com/v2/accounts/${PARENT_ACCOUNT_ID}/sub-accounts" \
-H "Authorization: Bearer ${PARENT_SECRET}" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: subacct-20240101-acme" \
-d '{"name":"Acme Subsidiary","website":"acme.example.com"}' \
> sub-account.json
CHILD_ACCOUNT_ID="$(jq -r '.id' sub-account.json)"
curl -sS -X POST "https://api.ahasend.com/v2/accounts/${PARENT_ACCOUNT_ID}/sub-accounts/${CHILD_ACCOUNT_ID}/api-keys" \
-H "Authorization: Bearer ${PARENT_SECRET}" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: child-bootstrap-key-20240101-acme" \
-d '{"label":"Bootstrap key","scopes":["messages:send:all","domains:read"]}' \
> child-api-key.json
CHILD_SECRET="$(jq -r '.secret_key' child-api-key.json)"
printf 'Store this one-time child secret securely: %s\n' "${CHILD_SECRET}"
curl -sS "https://api.ahasend.com/v2/accounts/${CHILD_ACCOUNT_ID}/domains" \
-H "Authorization: Bearer ${CHILD_SECRET}"
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const subAccountId = "00000000-0000-4000-8000-000000000004";
const apiKey = await client.subAccounts.apiKeys.create(
subAccountId,
{ label: "Bootstrap key", scopes: ["messages:send:all"] },
{ idempotencyKey: "sdk-sample-create-sub-account-api-key" },
);
console.log("Sub-account API key created.", { id: apiKey.id, label: apiKey.label });
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/CreateAPIKeyRequest'
example:
label: "Bootstrap key"
scopes: ["messages:send:all", "domains:read"]
responses:
'201':
description: Sub-account API key created successfully
headers:
Idempotent-Replayed:
$ref: '#/components/headers/IdempotentReplayed'
content:
application/json:
schema:
allOf:
- $ref: '#/components/schemas/APIKey'
- type: object
required:
- secret_key
properties:
secret_key:
type: string
readOnly: true
description: |
One-time secret key. Store it immediately. Exact
successful idempotent replays return the same secret
during the 5-minute encrypted replay window.
example:
object: api_key
id: "13b3aa8e-78d3-48a1-92d2-4b8b1228c2dd"
created_at: "2024-01-01T00:05:00Z"
updated_at: "2024-01-01T00:05:00Z"
last_used_at: null
account_id: "2f3c5d2a-9ef8-4c91-a5f4-79990c8c1d3a"
label: "Bootstrap key"
public_key: "aha-pk-child-public-key"
secret_key: "aha-sk-child-secret-key"
scopes:
- id: "c574470d-76ef-4f74-9b24-70a583a17e03"
created_at: "2024-01-01T00:05:00Z"
updated_at: "2024-01-01T00:05:00Z"
api_key_id: "13b3aa8e-78d3-48a1-92d2-4b8b1228c2dd"
scope: "messages:send:all"
domain_id: null
ip_allow_list: []
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: Sub account not found under the parent account
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'409':
$ref: '#/components/responses/IdempotencyConflict'
'422':
$ref: '#/components/responses/IdempotencyPayloadMismatch'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/v2/accounts/{account_id}/sub-accounts/{sub_account_id}/api-keys/{key_id}:
get:
summary: Get Sub-Account API Key
description: Returns a specific API key owned by a sub account. The `secret_key` field is omitted from read responses.
operationId: getSubAccountAPIKey
tags:
- Sub Accounts
parameters:
- name: account_id
in: path
required: true
description: Parent account ID
schema:
type: string
format: uuid
- name: sub_account_id
in: path
required: true
description: Sub account ID
schema:
type: string
format: uuid
- name: key_id
in: path
required: true
description: API key ID
schema:
type: string
format: uuid
security:
- BearerAuth: ["sub-account-api-keys:read"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go/api"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
subAccountID := uuid.New()
keyID := uuid.New()
// Create context for the API call
ctx := context.Background()
// Get a single sub-account API key
response, httpResp, err := client.SubAccountsAPI.GetSubAccountAPIKey(
ctx,
accountID,
subAccountID,
keyID,
)
if err != nil {
log.Fatalf("Error getting sub-account API key: %v", err)
}
// Check response
if httpResp.StatusCode == 200 {
fmt.Printf("✅ Retrieved sub-account API key. Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("ID: %s\n", response.ID)
fmt.Printf("Label: %s\n", response.Label)
fmt.Printf("PublicKey: %s\n", response.PublicKey)
fmt.Printf("Scopes: %d\n", len(response.Scopes))
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const subAccountId = "00000000-0000-4000-8000-000000000004";
const keyId = "00000000-0000-4000-8000-000000000005";
const apiKey = await client.subAccounts.apiKeys.get(subAccountId, keyId);
console.log("Sub-account API key found.", { id: apiKey.id, label: apiKey.label });
responses:
'200':
description: Sub-account API key details
content:
application/json:
schema:
$ref: '#/components/schemas/APIKey'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: API key or sub account not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
put:
summary: Update Sub-Account API Key
description: Updates the label and scopes for an API key owned by a sub account. Updated scopes are validated against the child account.
operationId: updateSubAccountAPIKey
tags:
- Sub Accounts
parameters:
- name: account_id
in: path
required: true
description: Parent account ID
schema:
type: string
format: uuid
- name: sub_account_id
in: path
required: true
description: Sub account ID
schema:
type: string
format: uuid
- name: key_id
in: path
required: true
description: API key ID
schema:
type: string
format: uuid
security:
- BearerAuth: ["sub-account-api-keys:write"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go"
"github.com/AhaSend/ahasend-go/api"
"github.com/AhaSend/ahasend-go/models/requests"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
subAccountID := uuid.New()
keyID := uuid.New()
// Create context for the API call
ctx := context.Background()
// IPAllowList replaces the allowed source IPs; use &[]string{} to
// clear it (any IP), or omit it to leave the current list unchanged.
response, httpResp, err := client.SubAccountsAPI.UpdateSubAccountAPIKey(ctx, accountID, subAccountID, keyID, requests.UpdateAPIKeyRequest{Label: ahasend.String("Updated bootstrap key"), Scopes: &[]string{"messages:send:all", "domains:read"}, IPAllowList: &[]string{"203.0.113.0/24"}})
if err != nil {
log.Fatalf("Error updating sub-account API key: %v", err)
}
if httpResp.StatusCode == 200 {
fmt.Printf("✅ Sub-account API key updated. Status: %d\n", httpResp.StatusCode)
fmt.Printf("ID: %s\n", response.ID)
fmt.Printf("Label: %s\n", response.Label)
fmt.Printf("Scopes: %d\n", len(response.Scopes))
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const subAccountId = "00000000-0000-4000-8000-000000000004";
const keyId = "00000000-0000-4000-8000-000000000005";
const apiKey = await client.subAccounts.apiKeys.update(subAccountId, keyId, {
label: "Renamed bootstrap key",
});
console.log("Sub-account API key updated.", { id: apiKey.id, label: apiKey.label });
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/UpdateAPIKeyRequest'
example:
label: "Updated bootstrap key"
scopes: ["messages:send:all", "domains:read"]
responses:
'200':
description: Sub-account API key updated successfully
content:
application/json:
schema:
$ref: '#/components/schemas/APIKey'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: API key or sub account not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
delete:
summary: Delete Sub-Account API Key
description: Deletes an API key owned by a sub account.
operationId: deleteSubAccountAPIKey
tags:
- Sub Accounts
parameters:
- name: account_id
in: path
required: true
description: Parent account ID
schema:
type: string
format: uuid
- name: sub_account_id
in: path
required: true
description: Sub account ID
schema:
type: string
format: uuid
- name: key_id
in: path
required: true
description: API key ID
schema:
type: string
format: uuid
security:
- BearerAuth: ["sub-account-api-keys:delete"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go/api"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
subAccountID := uuid.New()
keyID := uuid.New()
// Create context for the API call
ctx := context.Background()
response, httpResp, err := client.SubAccountsAPI.DeleteSubAccountAPIKey(ctx, accountID, subAccountID, keyID)
if err != nil {
log.Fatalf("Error deleting sub-account API key: %v", err)
}
if httpResp.StatusCode == 200 {
fmt.Printf("✅ Sub-account API key deleted. Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("Message: %s\n", response.Message)
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const subAccountId = "00000000-0000-4000-8000-000000000004";
const keyId = "00000000-0000-4000-8000-000000000005";
const result = await client.subAccounts.apiKeys.delete(subAccountId, keyId);
console.log("Sub-account API key deleted.", { message: result.message });
responses:
'200':
description: Sub-account API key deleted successfully
content:
application/json:
schema:
$ref: '#/components/schemas/SuccessResponse'
example:
message: "api key {id} ({label}) deleted successfully"
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: API key or sub account not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
# Suppressions endpoints
/v2/accounts/{account_id}/suppressions:
get:
summary: Get Suppressions
description: |
Returns a list of suppressions for the account
**Query Parameters:**
- `domain`: Filter by domain (optional)
- `email`: Filter by email (optional)
- `from_time`: Filter suppressions created after this time (RFC3339 format, optional)
- `to_time`: Filter suppressions created before this time (RFC3339 format, optional)
- `limit`: Maximum number of items to return (1-100, default: 100)
- `after`: Pagination cursor for the next page
- `before`: Pagination cursor for the previous page
operationId: getSuppressions
tags:
- Suppressions
parameters:
- name: account_id
in: path
required: true
description: Account ID
schema:
type: string
format: uuid
- name: domain
in: query
description: Filter by domain
schema:
type: string
- name: email
in: query
description: Email address
schema:
type: string
format: email
- name: from_time
in: query
description: Filter suppressions created after this time (RFC3339 format)
schema:
type: string
format: date-time
- name: to_time
in: query
description: Filter suppressions created before this time (RFC3339 format)
schema:
type: string
format: date-time
- name: limit
in: query
description: Maximum number of items to return (1-100)
schema:
type: integer
minimum: 1
maximum: 100
default: 100
- name: after
in: query
description: Pagination cursor for the next page. Provide the value provided in `next_cursor` from the response.
schema:
type: string
- name: before
in: query
description: Pagination cursor for the previous page. Provide the value provided in `previous_cursor` from the response.
schema:
type: string
security:
- BearerAuth: ["suppressions:read"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go/api"
"github.com/AhaSend/ahasend-go/models/requests"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
// Create context for the API call
ctx := context.Background()
// Call the ping endpoint
response, httpResp, err := client.SuppressionsAPI.GetSuppressions(
ctx,
accountID,
requests.GetSuppressionsParams{},
nil,
)
if err != nil {
log.Fatalf("Error getting suppressions: %v", err)
}
// Check response
if httpResp.StatusCode == 200 {
fmt.Printf("✅ Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("Found %d suppressions\n", len(response.Data))
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const page = await client.suppressions.list({ limit: 20 });
console.log("Suppressions listed.", { count: page.data.length });
responses:
'200':
description: List of suppressions
content:
application/json:
schema:
$ref: '#/components/schemas/PaginatedSuppressionsResponse'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: Domain not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
post:
summary: Create Suppression
description: |
Creates a new suppression for an email address
**Validation Requirements:**
- `email` must be a valid email address
- `expires_at` must be in RFC3339 format
- `domain` is optional - if not provided, applies to all account domains
operationId: createSuppression
tags:
- Suppressions
parameters:
- name: account_id
in: path
required: true
description: Account ID
schema:
type: string
format: uuid
- $ref: '#/components/parameters/IdempotencyKey'
security:
- BearerAuth: ["suppressions:write"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"time"
"github.com/AhaSend/ahasend-go"
"github.com/AhaSend/ahasend-go/api"
"github.com/AhaSend/ahasend-go/models/requests"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
// Create context for the API call
ctx := context.Background()
// Call the ping endpoint
response, httpResp, err := client.SuppressionsAPI.CreateSuppression(
ctx,
accountID,
requests.CreateSuppressionRequest{
Email: "test@example.com",
Reason: ahasend.String("Inbox full"),
ExpiresAt: time.Now().Add(time.Hour * 24 * 30),
},
)
if err != nil {
log.Fatalf("Error creating suppression: %v", err)
}
// Check response
if httpResp.StatusCode == 201 {
fmt.Printf("✅ Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("Created suppression: %#v\n", response)
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const result = await client.suppressions.create(
{
email: "recipient@example.net",
reason: "User requested removal",
expires_at: "2030-01-01T00:00:00Z",
},
{ idempotencyKey: "sdk-sample-create-suppression" },
);
console.log("Suppression created.", { count: result.data.length });
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/CreateSuppressionRequest'
responses:
'201':
description: Suppression created successfully
headers:
Idempotent-Replayed:
$ref: '#/components/headers/IdempotentReplayed'
content:
application/json:
schema:
$ref: '#/components/schemas/CreateSuppressionResponse'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'409':
description: |
Either the suppression already exists or the idempotency-key
execution is in progress. The in-progress case is identified only
by `Idempotent-Replayed: false` plus a positive integer
`Retry-After`. A new duplicate-suppression response has neither
header; a stored replay of that response has
`Idempotent-Replayed: true`. The message is not a stable
discriminator.
headers:
Idempotent-Replayed:
description: |
`false` with a positive `Retry-After` means an execution is in
progress. `true` means a stored duplicate-suppression 409 was
replayed. Absent means a fresh duplicate-suppression conflict.
schema:
type: string
enum: ['true', 'false']
Retry-After:
$ref: '#/components/headers/IdempotencyRetryAfter'
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'422':
$ref: '#/components/responses/IdempotencyPayloadMismatch'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
delete:
summary: Delete Suppression
description: |
Deletes suppressions for an email address
**Query Parameters:**
- `email`: Required email address to delete from suppression list
- `domain`: Optional domain filter to delete suppressions for specific domain only
operationId: deleteSuppression
tags:
- Suppressions
parameters:
- name: account_id
in: path
required: true
description: Account ID
schema:
type: string
format: uuid
- name: email
in: query
required: true
description: Email address
schema:
type: string
format: email
- name: domain
in: query
description: Optional domain filter
schema:
type: string
security:
- BearerAuth: ["suppressions:delete"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go"
"github.com/AhaSend/ahasend-go/api"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
// Create context for the API call
ctx := context.Background()
// Call the ping endpoint
response, httpResp, err := client.SuppressionsAPI.DeleteSuppression(
ctx,
accountID,
"info@bigco.com",
ahasend.String("notifications.example.com"),
)
if err != nil {
log.Fatalf("Error deleting suppression: %v", err)
}
// Check response
if httpResp.StatusCode == 200 {
fmt.Printf("✅ Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("Deleted the suppression, response: %s\n", len(response.Message))
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const result = await client.suppressions.delete({ email: "recipient@example.net" });
console.log("Suppression deleted.", { message: result.message });
responses:
'200':
description: Suppression deleted successfully
content:
application/json:
schema:
$ref: '#/components/schemas/SuccessResponse'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: Suppression not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/v2/accounts/{account_id}/suppressions/all:
delete:
summary: Delete All Suppressions
description: |
Deletes all suppressions for the account
**Query Parameters:**
- `domain`: Optional domain filter to delete suppressions for specific domain only
operationId: deleteAllSuppressions
tags:
- Suppressions
parameters:
- name: account_id
in: path
required: true
description: Account ID
schema:
type: string
format: uuid
- name: domain
in: query
description: Optional domain filter
schema:
type: string
security:
- BearerAuth: ["suppressions:wipe"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go/api"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
// Create context for the API call
ctx := context.Background()
// Call the ping endpoint
response, httpResp, err := client.SuppressionsAPI.DeleteAllSuppressions(
ctx,
accountID,
nil,
)
if err != nil {
log.Fatalf("Error deleting all suppressions: %v", err)
}
// Check response
if httpResp.StatusCode == 200 {
fmt.Printf("✅ Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("Deleted all suppressions: %#v\n", response)
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const result = await client.suppressions.wipe({ domain: "example.com" });
console.log("Domain suppressions deleted.", { message: result.message });
responses:
'200':
description: All suppressions deleted successfully
content:
application/json:
schema:
$ref: '#/components/schemas/SuccessResponse'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: Domain not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
# Routes endpoints
/v2/accounts/{account_id}/routes:
get:
summary: Get Routes
description: |
Returns a list of routes for the account. A domain-scoped key must
provide the matching `domain` query parameter; the global read role can
list without that filter.
operationId: getRoutes
tags:
- Routes
parameters:
- name: account_id
in: path
required: true
description: Account ID
schema:
type: string
format: uuid
- name: domain
in: query
description: Domain to filter routes by. Required when using a domain-scoped routes:read:{domain} API key.
schema:
type: string
- name: limit
in: query
description: Maximum number of items to return (1-100)
schema:
type: integer
minimum: 1
maximum: 100
default: 100
- name: after
in: query
description: Pagination cursor for the next page. Provide the value provided in `next_cursor` from the response.
schema:
type: string
- name: before
in: query
description: Pagination cursor for the previous page.
schema:
type: string
security:
- BearerAuth: ["routes:read:all"]
- BearerAuth: ["routes:read:{domain}"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go/api"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
// Create context for the API call
ctx := context.Background()
// Call the ping endpoint
response, httpResp, err := client.RoutesAPI.GetRoutes(
ctx,
accountID,
nil,
nil,
)
if err != nil {
log.Fatalf("Error getting routes: %v", err)
}
// Check response
if httpResp.StatusCode == 200 {
fmt.Printf("✅ Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("Found %d routes\n", len(response.Data))
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const page = await client.routes.list({ domain: "example.com", limit: 20 });
console.log("Routes listed.", { count: page.data.length });
responses:
'200':
description: List of routes
content:
application/json:
schema:
$ref: '#/components/schemas/PaginatedRoutesResponse'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
post:
summary: Create Route
description: |
Creates a new route for inbound email routing. Authorization uses the
domain in `recipient`: the global write role or its matching
domain-specific write role is sufficient.
operationId: createRoute
tags:
- Routes
parameters:
- name: account_id
in: path
required: true
description: Account ID
schema:
type: string
format: uuid
- $ref: '#/components/parameters/IdempotencyKey'
security:
- BearerAuth: ["routes:write:all"]
- BearerAuth: ["routes:write:{domain}"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go/api"
"github.com/AhaSend/ahasend-go/models/requests"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
// Create context for the API call
ctx := context.Background()
// Call the ping endpoint
response, httpResp, err := client.RoutesAPI.CreateRoute(
ctx,
accountID,
requests.CreateRouteRequest{
Name: "My Route",
URL: "https://mystartup.com/tickets",
Recipient: "ticket-*@mystartup.com",
Enabled: true,
Attachments: true,
Headers: true,
StripReplies: true,
},
)
if err != nil {
log.Fatalf("Error creating route: %v", err)
}
// Check response
if httpResp.StatusCode == 201 {
fmt.Printf("✅ Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("Created route: %#v\n", response)
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const route = await client.routes.create(
{
name: "Inbound messages",
url: "https://example.com/inbound",
recipient: "inbound@example.com",
},
{ idempotencyKey: "sdk-sample-create-route" },
);
console.log("Route created.", { id: route.id, name: route.name });
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/CreateRouteRequest'
responses:
'201':
description: Route created successfully
headers:
Idempotent-Replayed:
$ref: '#/components/headers/IdempotentReplayed'
content:
application/json:
schema:
$ref: '#/components/schemas/CreatedRoute'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'409':
$ref: '#/components/responses/IdempotencyConflict'
'422':
$ref: '#/components/responses/IdempotencyPayloadMismatch'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/v2/accounts/{account_id}/routes/{route_id}:
get:
summary: Get Route
description: |
Returns a specific route by ID. Access requires the global read role or
a read role matching the route's recipient domain.
operationId: getRoute
tags:
- Routes
parameters:
- name: account_id
in: path
required: true
description: Account ID
schema:
type: string
format: uuid
- name: route_id
in: path
required: true
description: Route ID
schema:
type: string
format: uuid
security:
- BearerAuth: ["routes:read:all"]
- BearerAuth: ["routes:read:{domain}"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go/api"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
// Create context for the API call
ctx := context.Background()
// Call the ping endpoint
response, httpResp, err := client.RoutesAPI.GetRoute(
ctx,
accountID,
uuid.MustParse("c5a32c40-b351-439f-8230-779daed3e42c"),
)
if err != nil {
log.Fatalf("Error getting route: %v", err)
}
// Check response
if httpResp.StatusCode == 200 {
fmt.Printf("✅ Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("Route: %#v\n", response)
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const routeId = "00000000-0000-4000-8000-000000000006";
const route = await client.routes.get(routeId);
console.log("Route found.", { id: route.id, name: route.name });
responses:
'200':
description: Route details
content:
application/json:
schema:
$ref: '#/components/schemas/Route'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: Route not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
put:
summary: Update Route
description: |
Updates an existing route. A domain-scoped key must authorize the
existing recipient domain and, when `recipient` changes, the new domain;
`routes:write:all` satisfies both checks.
operationId: updateRoute
tags:
- Routes
parameters:
- name: account_id
in: path
required: true
description: Account ID
schema:
type: string
format: uuid
- name: route_id
in: path
required: true
description: Route ID
schema:
type: string
format: uuid
security:
- BearerAuth: ["routes:write:all"]
- BearerAuth: ["routes:write:{domain}"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go"
"github.com/AhaSend/ahasend-go/api"
"github.com/AhaSend/ahasend-go/models/requests"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
// Create context for the API call
ctx := context.Background()
// Call the ping endpoint
response, httpResp, err := client.RoutesAPI.UpdateRoute(
ctx,
accountID,
uuid.MustParse("c5a32c40-b351-439f-8230-779daed3e42c"),
requests.UpdateRouteRequest{
Name: ahasend.String("Updated Name"),
URL: ahasend.String("https://mystartup.com/new-tickets"),
},
)
if err != nil {
log.Fatalf("Error updating route: %v", err)
}
// Check response
if httpResp.StatusCode == 200 {
fmt.Printf("✅ Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("Updated route: %#v\n", response)
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const routeId = "00000000-0000-4000-8000-000000000006";
const route = await client.routes.update(routeId, {
url: "https://example.com/inbound-v2",
});
console.log("Route updated.", { id: route.id, name: route.name });
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/UpdateRouteRequest'
responses:
'200':
description: Route updated successfully
content:
application/json:
schema:
$ref: '#/components/schemas/Route'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: Route not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
delete:
summary: Delete Route
description: |
Deletes a route. Access requires the global delete role or a delete role
matching the route's recipient domain.
operationId: deleteRoute
tags:
- Routes
parameters:
- name: account_id
in: path
required: true
description: Account ID
schema:
type: string
format: uuid
- name: route_id
in: path
required: true
description: Route ID
schema:
type: string
format: uuid
security:
- BearerAuth: ["routes:delete:all"]
- BearerAuth: ["routes:delete:{domain}"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go/api"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
// Create context for the API call
ctx := context.Background()
// Call the ping endpoint
response, httpResp, err := client.RoutesAPI.DeleteRoute(
ctx,
accountID,
uuid.MustParse("c5a32c40-b351-439f-8230-779daed3e42c"),
)
if err != nil {
log.Fatalf("Error deleting route: %v", err)
}
// Check response
if httpResp.StatusCode == 200 {
fmt.Printf("✅ Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("Deleted route: %#v\n", response)
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const routeId = "00000000-0000-4000-8000-000000000006";
const result = await client.routes.delete(routeId);
console.log("Route deleted.", { message: result.message });
responses:
'200':
description: Route deleted successfully
content:
application/json:
schema:
$ref: '#/components/schemas/SuccessResponse'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: Route not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
# Webhooks endpoints
/v2/accounts/{account_id}/webhooks:
get:
summary: Get Webhooks
description: |
Returns a list of webhooks for the account
The global read role sees all webhooks. Domain-scoped read roles return
only webhooks associated with at least one authorized domain.
**Query Parameters:**
- `enabled`: Filter by enabled status
- Event filters: `on_reception`, `on_delivered`, `on_transient_error`, `on_failed`, `on_bounced`, `on_suppressed`, `on_opened`, `on_clicked`, `on_suppression_created`, `on_dns_error`
- `limit`: Maximum number of items to return (1-100, default: 100)
- `after`: Pagination cursor for the next page
- `before`: Pagination cursor for the previous page
operationId: getWebhooks
tags:
- Webhooks
parameters:
- name: account_id
in: path
required: true
description: Account ID
schema:
type: string
format: uuid
- name: enabled
in: query
description: Filter by enabled status
schema:
type: boolean
- name: on_reception
in: query
description: Filter by reception event trigger
schema:
type: boolean
- name: on_delivered
in: query
description: Filter by delivery event trigger
schema:
type: boolean
- name: on_transient_error
in: query
description: Filter by transient error event trigger
schema:
type: boolean
- name: on_failed
in: query
description: Filter by failure event trigger
schema:
type: boolean
- name: on_bounced
in: query
description: Filter by bounce event trigger
schema:
type: boolean
- name: on_suppressed
in: query
description: Filter by suppression event trigger
schema:
type: boolean
- name: on_opened
in: query
description: Filter by open event trigger
schema:
type: boolean
- name: on_clicked
in: query
description: Filter by click event trigger
schema:
type: boolean
- name: on_suppression_created
in: query
description: Filter by suppression creation event trigger
schema:
type: boolean
- name: on_dns_error
in: query
description: Filter by DNS error event trigger
schema:
type: boolean
- name: limit
in: query
description: Maximum number of items to return (1-100)
schema:
type: integer
minimum: 1
maximum: 100
default: 100
- name: after
in: query
description: Pagination cursor for the next page. Provide the value provided in `next_cursor` from the response.
schema:
type: string
- name: before
in: query
description: Pagination cursor for the previous page.
schema:
type: string
security:
- BearerAuth: ["webhooks:read:all"]
- BearerAuth: ["webhooks:read:{domain}"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go"
"github.com/AhaSend/ahasend-go/api"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
// Create context for the API call
ctx := context.Background()
// Call the ping endpoint
response, httpResp, err := client.WebhooksAPI.GetWebhooks(
ctx,
accountID,
api.GetWebhooksParams{
Limit: ahasend.Int32(100),
},
nil,
)
if err != nil {
log.Fatalf("Error getting webhooks: %v", err)
}
// Check response
if httpResp.StatusCode == 200 {
fmt.Printf("✅ Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("Found %d webhooks\n", len(response.Data))
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const page = await client.webhooks.list({ limit: 20 });
console.log("Webhooks listed.", { count: page.data.length });
responses:
'200':
description: List of webhooks
content:
application/json:
schema:
$ref: '#/components/schemas/PaginatedWebhooksResponse'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
post:
summary: Create Webhook
description: |
Creates a new webhook for event notifications. A `scoped` webhook
requires at least one domain and the key must have write permission for
every supplied domain. A `global` webhook requires
`webhooks:write:all`; supplied domains are accepted but ignored, and
the response contains `domains: []`.
operationId: createWebhook
tags:
- Webhooks
parameters:
- name: account_id
in: path
required: true
description: Account ID
schema:
type: string
format: uuid
- $ref: '#/components/parameters/IdempotencyKey'
security:
- BearerAuth: ["webhooks:write:all"]
- BearerAuth: ["webhooks:write:{domain}"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go/api"
"github.com/AhaSend/ahasend-go/models/requests"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
// Create context for the API call
ctx := context.Background()
// Call the ping endpoint
response, httpResp, err := client.WebhooksAPI.CreateWebhook(
ctx,
accountID,
requests.CreateWebhookRequest{
Name: "Failures",
URL: "https://mystartup.com/webhook",
Scope: "global",
Enabled: true,
OnBounced: true,
OnTransientError: true,
OnFailed: true,
},
nil,
)
if err != nil {
log.Fatalf("Error creating webhook: %v", err)
}
// Check response
if httpResp.StatusCode == 201 {
fmt.Printf("✅ Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("Created webhook: %#v\n", response)
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const webhook = await client.webhooks.create(
{
name: "Delivery events",
url: "https://example.com/webhooks/ahasend",
scope: "global",
on_delivered: true,
},
{ idempotencyKey: "sdk-sample-create-webhook" },
);
console.log("Webhook created.", { id: webhook.id, name: webhook.name });
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/CreateWebhookRequest'
responses:
'201':
description: Webhook created successfully
headers:
Idempotent-Replayed:
$ref: '#/components/headers/IdempotentReplayed'
content:
application/json:
schema:
$ref: '#/components/schemas/CreatedWebhook'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'409':
$ref: '#/components/responses/IdempotencyConflict'
'422':
$ref: '#/components/responses/IdempotencyPayloadMismatch'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/v2/accounts/{account_id}/webhooks/{webhook_id}:
get:
summary: Get Webhook
description: |
Returns a specific webhook by ID. Access requires the global read role
or a read role matching at least one associated domain.
operationId: getWebhook
tags:
- Webhooks
parameters:
- name: account_id
in: path
required: true
description: Account ID
schema:
type: string
format: uuid
- name: webhook_id
in: path
required: true
description: Webhook ID
schema:
type: string
format: uuid
security:
- BearerAuth: ["webhooks:read:all"]
- BearerAuth: ["webhooks:read:{domain}"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go/api"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
// Create context for the API call
ctx := context.Background()
// Call the ping endpoint
response, httpResp, err := client.WebhooksAPI.GetWebhook(
ctx,
accountID,
uuid.MustParse("c5a32c40-b351-439f-8230-779daed3e42c"),
nil,
)
if err != nil {
log.Fatalf("Error getting webhook: %v", err)
}
// Check response
if httpResp.StatusCode == 200 {
fmt.Printf("✅ Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("Webhook: %#v\n", response)
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const webhookId = "00000000-0000-4000-8000-000000000007";
const webhook = await client.webhooks.get(webhookId);
console.log("Webhook found.", { id: webhook.id, name: webhook.name });
responses:
'200':
description: Webhook details
content:
application/json:
schema:
$ref: '#/components/schemas/Webhook'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: Webhook not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
put:
summary: Update Webhook
description: |
Updates an existing webhook. Omitted or null fields are unchanged.
Omitted/null `domains` preserves associations, while `[]` clears the
associations of a resulting-scoped webhook. Moving from global to
scoped requires a non-empty `domains` array in the same request. Moving
to global clears associations and ignores supplied domains.
A domain-scoped key must be authorized for the existing webhook and
every newly supplied domain; changing to global requires
`webhooks:write:all`.
**Note:** The webhook secret is not updatable
operationId: updateWebhook
tags:
- Webhooks
parameters:
- name: account_id
in: path
required: true
description: Account ID
schema:
type: string
format: uuid
- name: webhook_id
in: path
required: true
description: Webhook ID
schema:
type: string
format: uuid
security:
- BearerAuth: ["webhooks:write:all"]
- BearerAuth: ["webhooks:write:{domain}"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go"
"github.com/AhaSend/ahasend-go/api"
"github.com/AhaSend/ahasend-go/models/requests"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
// Create context for the API call
ctx := context.Background()
// Call the ping endpoint
response, httpResp, err := client.WebhooksAPI.UpdateWebhook(
ctx,
accountID,
uuid.MustParse("c5a32c40-b351-439f-8230-779daed3e42c"),
requests.UpdateWebhookRequest{
Name: ahasend.String("Failures"),
URL: ahasend.String("https://mystartup.com/webhook"),
Enabled: ahasend.Bool(true),
OnBounced: ahasend.Bool(true),
},
)
if err != nil {
log.Fatalf("Error updating webhook: %v", err)
}
// Check response
if httpResp.StatusCode == 200 {
fmt.Printf("✅ Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("Updated webhook: %#v\n", response)
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const webhookId = "00000000-0000-4000-8000-000000000007";
const webhook = await client.webhooks.update(webhookId, {
name: "Transactional delivery events",
});
console.log("Webhook updated.", { id: webhook.id, name: webhook.name });
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/UpdateWebhookRequest'
responses:
'200':
description: Webhook updated successfully
content:
application/json:
schema:
$ref: '#/components/schemas/Webhook'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: Webhook not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
delete:
summary: Delete Webhook
description: |
Deletes a webhook. Access requires the global delete role or a delete
role matching at least one associated domain.
operationId: deleteWebhook
tags:
- Webhooks
parameters:
- name: account_id
in: path
required: true
description: Account ID
schema:
type: string
format: uuid
- name: webhook_id
in: path
required: true
description: Webhook ID
schema:
type: string
format: uuid
security:
- BearerAuth: ["webhooks:delete:all"]
- BearerAuth: ["webhooks:delete:{domain}"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go/api"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
// Create context for the API call
ctx := context.Background()
// Call the ping endpoint
response, httpResp, err := client.WebhooksAPI.DeleteWebhook(
ctx,
accountID,
uuid.MustParse("c5a32c40-b351-439f-8230-779daed3e42c"),
)
if err != nil {
log.Fatalf("Error deleting webhook: %v", err)
}
// Check response
if httpResp.StatusCode == 200 {
fmt.Printf("✅ Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("Deleted webhook: %#v\n", response)
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const webhookId = "00000000-0000-4000-8000-000000000007";
const result = await client.webhooks.delete(webhookId);
console.log("Webhook deleted.", { message: result.message });
responses:
'200':
description: Webhook deleted successfully
content:
application/json:
schema:
$ref: '#/components/schemas/SuccessResponse'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: Webhook not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
# SMTP Credentials endpoints
/v2/accounts/{account_id}/smtp-credentials:
get:
summary: Get SMTP Credentials
description: |
Returns a list of SMTP credentials for the account. The global read role
sees all credentials; domain-scoped roles return credentials associated
with at least one authorized domain.
operationId: getSMTPCredentials
tags:
- SMTP Credentials
parameters:
- name: account_id
in: path
required: true
description: Account ID
schema:
type: string
format: uuid
- name: limit
in: query
description: Maximum number of items to return (1-100)
schema:
type: integer
minimum: 1
maximum: 100
default: 100
- name: after
in: query
description: Pagination cursor for the next page. Provide the value provided in `next_cursor` from the response.
schema:
type: string
- name: before
in: query
description: Pagination cursor for the previous page.
schema:
type: string
security:
- BearerAuth: ["smtp-credentials:read:all"]
- BearerAuth: ["smtp-credentials:read:{domain}"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go/api"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
// Create context for the API call
ctx := context.Background()
// Call the ping endpoint
response, httpResp, err := client.SMTPCredentialsAPI.GetSMTPCredentials(
ctx,
accountID,
nil,
nil,
)
if err != nil {
log.Fatalf("Error getting SMTP credentials: %v", err)
}
// Check response
if httpResp.StatusCode == 200 {
fmt.Printf("✅ Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("SMTP credentials: %#v\n", response)
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const page = await client.smtpCredentials.list({ limit: 20 });
console.log("SMTP credentials listed.", { count: page.data.length });
responses:
'200':
description: List of SMTP credentials
content:
application/json:
schema:
$ref: '#/components/schemas/PaginatedSMTPCredentialsResponse'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
post:
summary: Create SMTP Credential
description: |
Creates a new SMTP credential for SMTP authentication. A `scoped`
credential requires at least one domain and the key must have write
permission for every supplied domain. A `global` credential requires
`smtp-credentials:write:all`; supplied domains are accepted but ignored,
and the response contains `domains: []`. SMTP credentials have no
update endpoint.
operationId: createSMTPCredential
tags:
- SMTP Credentials
parameters:
- name: account_id
in: path
required: true
description: Account ID
schema:
type: string
format: uuid
- $ref: '#/components/parameters/IdempotencyKey'
security:
- BearerAuth: ["smtp-credentials:write:all"]
- BearerAuth: ["smtp-credentials:write:{domain}"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go/api"
"github.com/AhaSend/ahasend-go/models/requests"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
// Create context for the API call
ctx := context.Background()
// Call the ping endpoint
response, httpResp, err := client.SMTPCredentialsAPI.CreateSMTPCredential(
ctx,
accountID,
requests.CreateSMTPCredentialRequest{
Name: "My SMTP Credential",
Scope: "global",
Sandbox: true,
},
)
if err != nil {
log.Fatalf("Error creating SMTP credentials: %v", err)
}
// Check response
if httpResp.StatusCode == 201 {
fmt.Printf("✅ Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("Created SMTP credentials: %#v\n", response)
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const credential = await client.smtpCredentials.create(
{ name: "Production SMTP", scope: "global" },
{ idempotencyKey: "sdk-sample-create-smtp-credential" },
);
console.log("SMTP credential created.", { id: credential.id, name: credential.name });
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/CreateSMTPCredentialRequest'
responses:
'201':
description: SMTP credential created successfully
headers:
Idempotent-Replayed:
$ref: '#/components/headers/IdempotentReplayed'
content:
application/json:
schema:
$ref: '#/components/schemas/CreatedSMTPCredential'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'409':
$ref: '#/components/responses/IdempotencyConflict'
'422':
$ref: '#/components/responses/IdempotencyPayloadMismatch'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/v2/accounts/{account_id}/smtp-credentials/{smtp_credential_id}:
get:
summary: Get SMTP Credential
description: |
Returns a specific SMTP credential by ID. Access requires the global
read role or a read role matching at least one associated domain.
operationId: getSMTPCredential
tags:
- SMTP Credentials
parameters:
- name: account_id
in: path
required: true
description: Account ID
schema:
type: string
format: uuid
- name: smtp_credential_id
in: path
required: true
description: SMTP Credential ID
schema:
type: string
format: uuid
security:
- BearerAuth: ["smtp-credentials:read:all"]
- BearerAuth: ["smtp-credentials:read:{domain}"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go/api"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
smtpCredentialID := uuid.MustParse("0194f7ac-2f6a-7d29-9f0c-9a27b19f2d1c")
// Create context for the API call
ctx := context.Background()
// Call the ping endpoint
response, httpResp, err := client.SMTPCredentialsAPI.GetSMTPCredential(
ctx,
accountID,
smtpCredentialID,
)
if err != nil {
log.Fatalf("Error getting SMTP credentials: %v", err)
}
// Check response
if httpResp.StatusCode == 200 {
fmt.Printf("✅ Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("SMTP credentials: %#v\n", response)
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const credentialId = "00000000-0000-4000-8000-000000000008";
const credential = await client.smtpCredentials.get(credentialId);
console.log("SMTP credential found.", { id: credential.id, name: credential.name });
responses:
'200':
description: SMTP credential details
content:
application/json:
schema:
$ref: '#/components/schemas/SMTPCredential'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: SMTP credential not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
delete:
summary: Delete SMTP Credential
description: |
Deletes an SMTP credential. Access requires the global delete role or a
delete role matching at least one associated domain.
operationId: deleteSMTPCredential
tags:
- SMTP Credentials
parameters:
- name: account_id
in: path
required: true
description: Account ID
schema:
type: string
format: uuid
- name: smtp_credential_id
in: path
required: true
description: SMTP Credential ID
schema:
type: string
format: uuid
security:
- BearerAuth: ["smtp-credentials:delete:all"]
- BearerAuth: ["smtp-credentials:delete:{domain}"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go/api"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
smtpCredentialID := uuid.MustParse("0194f7ac-2f6a-7d29-9f0c-9a27b19f2d1c")
// Create context for the API call
ctx := context.Background()
// Call the ping endpoint
response, httpResp, err := client.SMTPCredentialsAPI.DeleteSMTPCredential(
ctx,
accountID,
smtpCredentialID,
)
if err != nil {
log.Fatalf("Error deleting SMTP credentials: %v", err)
}
// Check response
if httpResp.StatusCode == 200 {
fmt.Printf("✅ Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("Deleted SMTP credentials: %#v\n", response)
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const credentialId = "00000000-0000-4000-8000-000000000008";
const result = await client.smtpCredentials.delete(credentialId);
console.log("SMTP credential deleted.", { message: result.message });
responses:
'200':
description: SMTP credential deleted successfully
content:
application/json:
schema:
$ref: '#/components/schemas/SuccessResponse'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: SMTP credential not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
# Statistics endpoints
/v2/accounts/{account_id}/statistics/transactional/deliverability:
get:
summary: Get Deliverability Statistics
description: |
Returns transactional deliverability statistics grouped by status
The global statistics role can query all sender domains. A
domain-scoped key is limited to authorized domains and must authorize
every comma-separated value supplied in `sender_domain`.
**Query Parameters:**
- `from_time`: Filter statistics after this date (RFC3339 format)
- `to_time`: Filter statistics before this date (RFC3339 format)
- `sender_domain`: Filter by sender domain
- `recipient_domains`: Filter by recipient domain
- `tags`: Filter by tags (comma-separated)
- `group_by`: Group by time period (hour, day, week, month)
operationId: getDeliverabilityStatistics
tags:
- Statistics
parameters:
- name: account_id
in: path
required: true
description: Account ID
schema:
type: string
format: uuid
- name: from_time
in: query
description: Filter statistics after this datetime (RFC3339 format)
schema:
type: string
format: date-time
- name: to_time
in: query
description: Filter statistics before this datetime (RFC3339 format)
schema:
type: string
format: date-time
- name: sender_domain
in: query
description: Comma-separated sender domains; the key must authorize every requested domain
schema:
type: string
- name: recipient_domains
in: query
description: Filter by a comma separated list of recipient domains
schema:
type: string
example: gmail.com,googlemail.com
- name: tags
in: query
description: Filter by tags (comma-separated)
schema:
type: string
- name: group_by
in: query
description: Group by time period
schema:
type: string
enum: [hour, day, week, month]
default: day
security:
- BearerAuth: ["statistics-transactional:read:all"]
- BearerAuth: ["statistics-transactional:read:{domain}"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"time"
"github.com/AhaSend/ahasend-go"
"github.com/AhaSend/ahasend-go/api"
"github.com/AhaSend/ahasend-go/models/requests"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
// Create context for the API call
ctx := context.Background()
fromTime := time.Now().Add(-time.Hour * 24 * 30)
// Call the ping endpoint
response, httpResp, err := client.StatisticsAPI.GetDeliverabilityStatistics(
ctx,
accountID,
requests.GetDeliverabilityStatisticsParams{
FromTime: &fromTime,
SenderDomain: ahasend.String("example.com"),
RecipientDomains: ahasend.String("gmail.com"),
GroupBy: ahasend.String("week"),
},
)
if err != nil {
log.Fatalf("Error getting deliverability statistics: %v", err)
}
// Check response
if httpResp.StatusCode == 200 {
fmt.Printf("✅ Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("Deliverability statistics: %#v\n", response)
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const statistics = await client.statistics.deliverability({
from_time: "2026-01-01T00:00:00Z",
to_time: "2026-01-02T00:00:00Z",
});
console.log("Deliverability statistics loaded.", { buckets: statistics.data.length });
responses:
'200':
description: Deliverability statistics
content:
application/json:
schema:
$ref: '#/components/schemas/DeliverabilityStatisticsResponse'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'429':
description: Too many requests (rate limited to 1 request per second)
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/v2/accounts/{account_id}/statistics/transactional/bounce:
get:
summary: Get Bounce Statistics
description: |
Returns transactional bounce statistics grouped by classification
The global statistics role can query all sender domains. A
domain-scoped key is limited to authorized domains and must authorize
every comma-separated value supplied in `sender_domain`.
**Query Parameters:**
- `from_time`: Filter statistics after this date (RFC3339 format)
- `to_time`: Filter statistics before this date (RFC3339 format)
- `sender_domain`: Filter by sender domain
- `recipient_domains`: Filter by recipient domain
- `tags`: Filter by tags (comma-separated)
- `group_by`: Group by time period (hour, day, week, month)
operationId: getBounceStatistics
tags:
- Statistics
parameters:
- name: account_id
in: path
required: true
description: Account ID
schema:
type: string
format: uuid
- name: from_time
in: query
description: Filter statistics after this datetime (RFC3339 format)
schema:
type: string
format: date-time
- name: to_time
in: query
description: Filter statistics before this datetime (RFC3339 format)
schema:
type: string
format: date-time
- name: sender_domain
in: query
description: Comma-separated sender domains; the key must authorize every requested domain
schema:
type: string
- name: recipient_domains
in: query
description: Filter by a comma separated list of recipient domains
schema:
type: string
example: gmail.com,googlemail.com
- name: tags
in: query
description: Filter by tags (comma-separated)
schema:
type: string
- name: group_by
in: query
description: Group by time period
schema:
type: string
enum: [hour, day, week, month]
default: day
security:
- BearerAuth: ["statistics-transactional:read:all"]
- BearerAuth: ["statistics-transactional:read:{domain}"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"time"
"github.com/AhaSend/ahasend-go"
"github.com/AhaSend/ahasend-go/api"
"github.com/AhaSend/ahasend-go/models/requests"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
// Create context for the API call
ctx := context.Background()
fromTime := time.Now().Add(-time.Hour * 24 * 30)
// Call the ping endpoint
response, httpResp, err := client.StatisticsAPI.GetBounceStatistics(
ctx,
accountID,
requests.GetBounceStatisticsParams{
FromTime: &fromTime,
SenderDomain: ahasend.String("example.com"),
RecipientDomains: ahasend.String("gmail.com"),
GroupBy: ahasend.String("week"),
},
)
if err != nil {
log.Fatalf("Error getting bounce statistics: %v", err)
}
// Check response
if httpResp.StatusCode == 200 {
fmt.Printf("✅ Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("Bounce statistics: %#v\n", response)
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const statistics = await client.statistics.bounces({
from_time: "2026-01-01T00:00:00Z",
to_time: "2026-01-02T00:00:00Z",
});
console.log("Bounce statistics loaded.", { buckets: statistics.data.length });
responses:
'200':
description: Bounce statistics
content:
application/json:
schema:
$ref: '#/components/schemas/BounceStatisticsResponse'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'429':
description: Too many requests (rate limited to 1 request per second)
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/v2/accounts/{account_id}/statistics/transactional/delivery-time:
get:
summary: Get Delivery Time Statistics
description: |
Returns transactional delivery time statistics grouped by recipient domain
The global statistics role can query all sender domains. A
domain-scoped key is limited to authorized domains and must authorize
every comma-separated value supplied in `sender_domain`.
**Query Parameters:**
- `from_time`: Filter statistics after this date (RFC3339 format)
- `to_time`: Filter statistics before this date (RFC3339 format)
- `sender_domain`: Filter by sender domain
- `recipient_domains`: Filter by recipient domains
- `tags`: Filter by tags (comma-separated)
- `group_by`: Group by time period (hour, day, week, month)
operationId: getDeliveryTimeStatistics
tags:
- Statistics
parameters:
- name: account_id
in: path
required: true
description: Account ID
schema:
type: string
format: uuid
- name: from_time
in: query
description: Filter statistics after this datetime (RFC3339 format)
schema:
type: string
format: date-time
- name: to_time
in: query
description: Filter statistics before this datetime (RFC3339 format)
schema:
type: string
format: date-time
- name: sender_domain
in: query
description: Comma-separated sender domains; the key must authorize every requested domain
schema:
type: string
- name: recipient_domains
in: query
description: Filter by a comma separated list of recipient domains
schema:
type: string
example: gmail.com,googlemail.com
- name: tags
in: query
description: Filter by tags (comma-separated)
schema:
type: string
- name: group_by
in: query
description: Group by time period
schema:
type: string
enum: [hour, day, week, month]
default: day
security:
- BearerAuth: ["statistics-transactional:read:all"]
- BearerAuth: ["statistics-transactional:read:{domain}"]
x-code-samples:
- lang: go
label: AhaSend Go SDK
source: |
package main
import (
"context"
"fmt"
"log"
"time"
"github.com/AhaSend/ahasend-go"
"github.com/AhaSend/ahasend-go/api"
"github.com/AhaSend/ahasend-go/models/requests"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
// Create context for the API call
ctx := context.Background()
fromTime := time.Now().Add(-time.Hour * 24 * 30)
// Call the ping endpoint
response, httpResp, err := client.StatisticsAPI.GetDeliveryTimeStatistics(
ctx,
accountID,
requests.GetDeliveryTimeStatisticsParams{
FromTime: &fromTime,
SenderDomain: ahasend.String("example.com"),
RecipientDomains: ahasend.String("gmail.com"),
GroupBy: ahasend.String("week"),
},
)
if err != nil {
log.Fatalf("Error getting delivery time statistics: %v", err)
}
// Check response
if httpResp.StatusCode == 200 {
fmt.Printf("✅ Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("Delivery time statistics: %#v\n", response)
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}
- lang: javascript
label: Node.js 22+ (AhaSend SDK)
source: |
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const statistics = await client.statistics.deliveryTimes({
from_time: "2026-01-01T00:00:00Z",
to_time: "2026-01-02T00:00:00Z",
});
console.log("Delivery-time statistics loaded.", { buckets: statistics.data.length });
responses:
'200':
description: Delivery time statistics
content:
application/json:
schema:
$ref: '#/components/schemas/DeliveryTimeStatisticsResponse'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'429':
description: Too many requests (rate limited to 1 request per second)
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
tags:
- name: Utility
description: Utility endpoints for health checks and diagnostics
- name: API Keys
description: Manage API keys for authentication and access control
- name: Domains
description: Manage sending domains
- name: Messages
description: Send and manage transactional messages
- name: Accounts
description: Manage account settings and members
- name: Suppressions
description: Manage email suppressions
- name: Routes
description: Manage inbound email routing
- name: Webhooks
description: Manage webhook notifications
- name: SMTP Credentials
description: Manage SMTP authentication credentials
- name: Statistics
description: Access transactional email statistics
- name: Message Events
description: Webhooks for outbound message delivery events
- name: Suppression Events
description: Webhooks for suppression list changes
- name: Domain Events
description: Webhooks for domain configuration issues
- name: Route Events
description: Webhooks for inbound email routing