AhaSend Go SDK
package main
import (
"context"
"fmt"
"log"
"os"
"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()
segmentID := uuid.MustParse("11111111-1111-4111-8111-111111111111")
response, _, err := client.SegmentsAPI.GetSegmentContacts(ctx, accountID, segmentID, requests.GetSegmentContactsParams{})
if err != nil {
log.Fatalf("Error listing segment contacts: %v", err)
}
for _, member := range response.Data {
fmt.Printf("%s since %s\n", member.Email, member.EnteredAt)
}
}import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const segmentId = "00000000-0000-4000-8000-000000000015";
const page = await client.segments.contacts.list(segmentId, { limit: 20 });
console.log("Segment members listed.", { count: page.data.length });
curl --request GET \
--url https://api.ahasend.com/v2/accounts/{account_id}/segments/{segment_id}/contacts \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.ahasend.com/v2/accounts/{account_id}/segments/{segment_id}/contacts"
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}/segments/{segment_id}/contacts",
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}/segments/{segment_id}/contacts")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.ahasend.com/v2/accounts/{account_id}/segments/{segment_id}/contacts")
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": "segment_contact",
"segment_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"contact_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"email": "jsmith@example.com",
"entered_at": "2023-11-07T05:31:56Z"
}
],
"pagination": {
"has_more": true,
"next_cursor": "<string>",
"previous_cursor": "<string>"
}
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}Segments
List the Contacts in a Segment via the API
List the members of an AhaSend segment, the contacts that match its rules, with the email address of each and the time it joined the segment.
GET
/
v2
/
accounts
/
{account_id}
/
segments
/
{segment_id}
/
contacts
AhaSend Go SDK
package main
import (
"context"
"fmt"
"log"
"os"
"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()
segmentID := uuid.MustParse("11111111-1111-4111-8111-111111111111")
response, _, err := client.SegmentsAPI.GetSegmentContacts(ctx, accountID, segmentID, requests.GetSegmentContactsParams{})
if err != nil {
log.Fatalf("Error listing segment contacts: %v", err)
}
for _, member := range response.Data {
fmt.Printf("%s since %s\n", member.Email, member.EnteredAt)
}
}import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const segmentId = "00000000-0000-4000-8000-000000000015";
const page = await client.segments.contacts.list(segmentId, { limit: 20 });
console.log("Segment members listed.", { count: page.data.length });
curl --request GET \
--url https://api.ahasend.com/v2/accounts/{account_id}/segments/{segment_id}/contacts \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.ahasend.com/v2/accounts/{account_id}/segments/{segment_id}/contacts"
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}/segments/{segment_id}/contacts",
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}/segments/{segment_id}/contacts")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.ahasend.com/v2/accounts/{account_id}/segments/{segment_id}/contacts")
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": "segment_contact",
"segment_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"contact_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"email": "jsmith@example.com",
"entered_at": "2023-11-07T05:31:56Z"
}
],
"pagination": {
"has_more": true,
"next_cursor": "<string>",
"previous_cursor": "<string>"
}
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}The AhaSend API returns the members of one segment, by contact ID, lowest first. Access requires
segments:read and contacts:read, because the members are contacts.
Each item gives the contact_id, the email address of the contact and entered_at, the time it became a member.
- A member matches the rules whatever its consent, so a campaign can reach fewer contacts than this operation returns. See Members and reachable contacts.
- While the segment is
building, the members may still follow its previous rules. See States.
after or before, not both. See Pagination.
Related Guides
- API authentication, Permission scopes, Get Segment.
- Segments API overview, API errors, API rate limits.
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
Maximum number of members to return
Required range:
1 <= x <= 100Cursor for the next page; cannot be combined with before
Cursor for the previous page; cannot be combined with after

