package main
import (
"context"
"fmt"
"log"
"os"
"github.com/AhaSend/ahasend-go"
"github.com/AhaSend/ahasend-go/api"
"github.com/AhaSend/ahasend-go/models/requests"
"github.com/google/uuid"
)
func main() {
client := api.NewAPIClient(api.WithAPIKey(os.Getenv("AHASEND_API_KEY")))
accountID := uuid.MustParse(os.Getenv("AHASEND_ACCOUNT_ID"))
ctx := context.Background()
campaignID := uuid.MustParse("11111111-1111-4111-8111-111111111111")
// Set exactly one of Status and BounceClassification, each a key of the
// campaign's stats report.
response, _, err := client.CampaignsAPI.ListCampaignRecipients(ctx, accountID, campaignID, requests.ListCampaignRecipientsParams{
Status: ahasend.String("Bounced"),
Limit: ahasend.Int32(100),
})
if err != nil {
log.Fatalf("Error listing campaign recipients: %v", err)
}
for _, recipient := range response.Data {
reason := ""
if recipient.BounceReason != nil {
reason = *recipient.BounceReason
}
fmt.Printf("%s (%s) %s\n", recipient.Email, recipient.ListName, reason)
}
}import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const campaignId = "00000000-0000-4000-8000-000000000014";
// Send exactly one of status and bounce_classification.
const page = await client.campaigns.recipients.list(campaignId, { status: "Delivered", limit: 20 });
console.log("Campaign recipients listed.", { count: page.data.length });
curl --request GET \
--url https://api.ahasend.com/v2/accounts/{account_id}/campaigns/{campaign_id}/recipients \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.ahasend.com/v2/accounts/{account_id}/campaigns/{campaign_id}/recipients"
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}/campaigns/{campaign_id}/recipients",
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}/campaigns/{campaign_id}/recipients")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.ahasend.com/v2/accounts/{account_id}/campaigns/{campaign_id}/recipients")
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": "campaign_recipient",
"contact_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"email": "<string>",
"list_name": "<string>",
"status": "<string>",
"bounce_classification": "<string>",
"bounce_reason": "<string>",
"bounce_message": "<string>",
"attempts": 123,
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z"
}
],
"pagination": {
"has_more": true,
"next_cursor": "eyJpZCI6MTIzNH0="
}
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}List Campaign Recipients via the API
List the recipients of an AhaSend marketing campaign in one status or with one bounce classification, with the list, attempts and bounce details of each.
package main
import (
"context"
"fmt"
"log"
"os"
"github.com/AhaSend/ahasend-go"
"github.com/AhaSend/ahasend-go/api"
"github.com/AhaSend/ahasend-go/models/requests"
"github.com/google/uuid"
)
func main() {
client := api.NewAPIClient(api.WithAPIKey(os.Getenv("AHASEND_API_KEY")))
accountID := uuid.MustParse(os.Getenv("AHASEND_ACCOUNT_ID"))
ctx := context.Background()
campaignID := uuid.MustParse("11111111-1111-4111-8111-111111111111")
// Set exactly one of Status and BounceClassification, each a key of the
// campaign's stats report.
response, _, err := client.CampaignsAPI.ListCampaignRecipients(ctx, accountID, campaignID, requests.ListCampaignRecipientsParams{
Status: ahasend.String("Bounced"),
Limit: ahasend.Int32(100),
})
if err != nil {
log.Fatalf("Error listing campaign recipients: %v", err)
}
for _, recipient := range response.Data {
reason := ""
if recipient.BounceReason != nil {
reason = *recipient.BounceReason
}
fmt.Printf("%s (%s) %s\n", recipient.Email, recipient.ListName, reason)
}
}import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const campaignId = "00000000-0000-4000-8000-000000000014";
// Send exactly one of status and bounce_classification.
const page = await client.campaigns.recipients.list(campaignId, { status: "Delivered", limit: 20 });
console.log("Campaign recipients listed.", { count: page.data.length });
curl --request GET \
--url https://api.ahasend.com/v2/accounts/{account_id}/campaigns/{campaign_id}/recipients \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.ahasend.com/v2/accounts/{account_id}/campaigns/{campaign_id}/recipients"
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}/campaigns/{campaign_id}/recipients",
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}/campaigns/{campaign_id}/recipients")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.ahasend.com/v2/accounts/{account_id}/campaigns/{campaign_id}/recipients")
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": "campaign_recipient",
"contact_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"email": "<string>",
"list_name": "<string>",
"status": "<string>",
"bounce_classification": "<string>",
"bounce_reason": "<string>",
"bounce_message": "<string>",
"attempts": 123,
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z"
}
],
"pagination": {
"has_more": true,
"next_cursor": "eyJpZCI6MTIzNH0="
}
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}campaigns:read.
Send exactly one of status and bounce_classification:
statusis a key ofreport.by_statusin Get Campaign Stats, such asQueued,DeliveredorAdministratively Bounced.bounce_classificationis a key ofreport.by_bounce_classification.Unknowncounts bounces with no classification and cannot be listed.
previous_cursor. To start again, read the first page without a cursor.
Related Guides
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.
Query Parameters
A status as a key of the stats' by_status names it, such as Queued, Delivered or Administratively Bounced.
1 - 64A key of the stats' by_bounce_classification, except Unknown, which has no recipient page.
1 - 255Maximum number of items to return (1-100)
1 <= x <= 100Pagination cursor for the next page. Provide the value from next_cursor in the response.
Pagination cursor for the previous page. Provide the value from previous_cursor in the response. An empty page past the last recipient has no previous_cursor; read the first page with no cursor.
Response
Paginated campaign recipients

