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)
}
}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 });
curl --request GET \
--url https://api.ahasend.com/v2/accounts/{account_id}/messages \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.ahasend.com/v2/accounts/{account_id}/messages"
headers = {"Authorization": "Bearer <token>"}
response = requests.get(url, headers=headers)
print(response.text)<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.ahasend.com/v2/accounts/{account_id}/messages",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}HttpResponse<String> response = Unirest.get("https://api.ahasend.com/v2/accounts/{account_id}/messages")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.ahasend.com/v2/accounts/{account_id}/messages")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"object": "list",
"data": [
{
"object": "message",
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"sent_at": "2023-11-07T05:31:56Z",
"delivered_at": "2023-11-07T05:31:56Z",
"retain_until": "2023-11-07T05:31:56Z",
"direction": "inbound",
"is_bounce_notification": true,
"bounce_classification": "<string>",
"delivery_attempts": [
{
"time": "2023-11-07T05:31:56Z",
"log": "<string>",
"status": "<string>"
}
],
"message_id": "<string>",
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"subject": "<string>",
"tags": [
"<string>"
],
"sender": "jsmith@example.com",
"recipient": "jsmith@example.com",
"status": "<string>",
"num_attempts": 123,
"click_count": 123,
"open_count": 123,
"reference_message_id": 123,
"domain_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"account_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
],
"pagination": {
"has_more": true,
"next_cursor": "eyJpZCI6MTIzNH0="
}
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}List Messages
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.
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)
}
}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 });
curl --request GET \
--url https://api.ahasend.com/v2/accounts/{account_id}/messages \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.ahasend.com/v2/accounts/{account_id}/messages"
headers = {"Authorization": "Bearer <token>"}
response = requests.get(url, headers=headers)
print(response.text)<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.ahasend.com/v2/accounts/{account_id}/messages",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}HttpResponse<String> response = Unirest.get("https://api.ahasend.com/v2/accounts/{account_id}/messages")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.ahasend.com/v2/accounts/{account_id}/messages")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"object": "list",
"data": [
{
"object": "message",
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"sent_at": "2023-11-07T05:31:56Z",
"delivered_at": "2023-11-07T05:31:56Z",
"retain_until": "2023-11-07T05:31:56Z",
"direction": "inbound",
"is_bounce_notification": true,
"bounce_classification": "<string>",
"delivery_attempts": [
{
"time": "2023-11-07T05:31:56Z",
"log": "<string>",
"status": "<string>"
}
],
"message_id": "<string>",
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"subject": "<string>",
"tags": [
"<string>"
],
"sender": "jsmith@example.com",
"recipient": "jsmith@example.com",
"status": "<string>",
"num_attempts": 123,
"click_count": 123,
"open_count": 123,
"reference_message_id": 123,
"domain_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"account_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
],
"pagination": {
"has_more": true,
"next_cursor": "eyJpZCI6MTIzNH0="
}
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}content field is omitted from list responses for performance reasons. Use the
Get Message endpoint to retrieve the full
message content.Authorizations
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.
Path Parameters
Account ID
Query Parameters
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.
Sender email address (must be from domain in API key scopes)
Recipient email address
Filter by subject text
Filter by message ID header (same ID returned by CreateMessage API)
Filter by comma-separated list of tags (max 20)
Filter messages created after this time (RFC3339 format)
Filter messages created before this time (RFC3339 format)
Maximum number of items to return (1-100)
1 <= x <= 100Pagination cursor for the next page. Provide the value provided in next_cursor from the response.
Pagination cursor for the previous page.
Response
List of messages
Object type identifier
list Array of message summaries (content and content_parsed fields omitted for performance)
Show child attributes
Show child attributes
Show child attributes
Show child attributes
{
"has_more": true,
"next_cursor": "eyJpZCI6MTIzNH0="
}

