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()
response, _, err := client.ListsAPI.GetContactLists(ctx, accountID, "user+tag@example.com", requests.GetContactListsParams{
SubscriptionStatus: ahasend.String(requests.ListContactStatusConfirmed),
})
if err != nil {
log.Fatalf("Error getting the contact's lists: %v", err)
}
for _, membership := range response.Data {
if membership.List != nil {
fmt.Printf("%s %s\n", membership.List.Name, membership.SubscriptionStatus)
}
}
}import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const idOrEmail = "User+Tag@Example.COM";
const page = await client.contacts.lists.list(idOrEmail, { subscription_status: "confirmed" });
console.log("Contact lists listed.", { count: page.data.length });
curl --request GET \
--url https://api.ahasend.com/v2/accounts/{account_id}/contacts/{id_or_email}/lists \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.ahasend.com/v2/accounts/{account_id}/contacts/{id_or_email}/lists"
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}/contacts/{id_or_email}/lists",
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}/contacts/{id_or_email}/lists")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.ahasend.com/v2/accounts/{account_id}/contacts/{id_or_email}/lists")
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": "list_contact",
"list_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"contact_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"email": "jsmith@example.com",
"subscription_status": "unconfirmed",
"subscribed_at": "2023-11-07T05:31:56Z",
"unsubscribed_at": "2023-11-07T05:31:56Z",
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"contact": {
"object": "contact",
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"email": "jsmith@example.com",
"first_name": "<string>",
"last_name": "<string>",
"status": "enabled",
"status_reason": "<string>",
"unsubscribed": true,
"unsubscribed_at": "2023-11-07T05:31:56Z",
"attributes": {},
"validation_status": "unvalidated",
"last_validated_at": "2023-11-07T05:31:56Z"
},
"list": {
"object": "contact_list",
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"name": "<string>",
"description": "<string>",
"tags": [
"<string>"
]
}
}
],
"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"
}Lists
List a Contact's Lists via the API
List the AhaSend lists that one contact is on, with its subscription status on each list. Filter by status to see what a person is subscribed to.
GET
/
v2
/
accounts
/
{account_id}
/
contacts
/
{id_or_email}
/
lists
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()
response, _, err := client.ListsAPI.GetContactLists(ctx, accountID, "user+tag@example.com", requests.GetContactListsParams{
SubscriptionStatus: ahasend.String(requests.ListContactStatusConfirmed),
})
if err != nil {
log.Fatalf("Error getting the contact's lists: %v", err)
}
for _, membership := range response.Data {
if membership.List != nil {
fmt.Printf("%s %s\n", membership.List.Name, membership.SubscriptionStatus)
}
}
}import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const idOrEmail = "User+Tag@Example.COM";
const page = await client.contacts.lists.list(idOrEmail, { subscription_status: "confirmed" });
console.log("Contact lists listed.", { count: page.data.length });
curl --request GET \
--url https://api.ahasend.com/v2/accounts/{account_id}/contacts/{id_or_email}/lists \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.ahasend.com/v2/accounts/{account_id}/contacts/{id_or_email}/lists"
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}/contacts/{id_or_email}/lists",
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}/contacts/{id_or_email}/lists")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.ahasend.com/v2/accounts/{account_id}/contacts/{id_or_email}/lists")
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": "list_contact",
"list_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"contact_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"email": "jsmith@example.com",
"subscription_status": "unconfirmed",
"subscribed_at": "2023-11-07T05:31:56Z",
"unsubscribed_at": "2023-11-07T05:31:56Z",
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"contact": {
"object": "contact",
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"email": "jsmith@example.com",
"first_name": "<string>",
"last_name": "<string>",
"status": "enabled",
"status_reason": "<string>",
"unsubscribed": true,
"unsubscribed_at": "2023-11-07T05:31:56Z",
"attributes": {},
"validation_status": "unvalidated",
"last_validated_at": "2023-11-07T05:31:56Z"
},
"list": {
"object": "contact_list",
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"name": "<string>",
"description": "<string>",
"tags": [
"<string>"
]
}
}
],
"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 lists that one contact is on, newest membership first. Access requires
lists:read.
{id_or_email} is the contact ID or its email address. Percent-encode an email address exactly once. See Name a contact in the path.
Each item is a membership with its subscription_status and the list. Deleted lists are left out. subscription_status filters the memberships by unconfirmed, confirmed, unsubscribed or complained. This is the reverse of List Contacts on a List.
There is no operation that removes a contact from all lists. To stop marketing email to the contact on all lists, use Update Contact with unsubscribed: true. This does not change the memberships: each one still shows its status, but the contact no longer counts toward the contact_count of any list. To unsubscribe the contact from one list, use Add or Update a List Contact with subscription_status: "unsubscribed".
Pages use cursors: send after or before, not both. See Pagination.
Related Guides
- API authentication, Permission scopes, Get Contact.
- Lists 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.
Path Parameters
Account ID
Contact UUID or email address. Percent-encode an email exactly once as a path segment; SDK callers pass the raw email value.
Query Parameters
Maximum number of memberships 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
Per-list consent filter
Available options:
unconfirmed, confirmed, unsubscribed, complained 
