AhaSend Go SDK
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
}
// A recipient comes from a list or from a segment.
source := ""
if recipient.ListName != nil {
source = *recipient.ListName
} else if recipient.SegmentName != nil {
source = *recipient.SegmentName
}
fmt.Printf("%s (%s) %s\n", recipient.Email, source, 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>",
"segment_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"segment_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
List Campaign Recipients via the API
List the recipients of an AhaSend marketing campaign in one status or with one bounce classification, with the source, attempts and bounce details of each.
GET
/
v2
/
accounts
/
{account_id}
/
campaigns
/
{campaign_id}
/
recipients
AhaSend Go SDK
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
}
// A recipient comes from a list or from a segment.
source := ""
if recipient.ListName != nil {
source = *recipient.ListName
} else if recipient.SegmentName != nil {
source = *recipient.SegmentName
}
fmt.Printf("%s (%s) %s\n", recipient.Email, source, 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>",
"segment_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"segment_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"
}The AhaSend API returns the recipients of a campaign, by contact ID, highest first. Access requires
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.
- A recipient sent to from a list has
list_name, andsegment_idandsegment_namearenull. - A recipient sent to from a segment has
segment_idandsegment_name, the name of the segment at the send, andlist_nameisnull. - A contact reached through a list and a segment is recorded under the list. See Audience.
previous_cursor. To start again, read the first page without a cursor.
Related guides
Authorizations
Query Parameters
Response
Paginated campaign recipients

