AhaSend Go SDK
package main
import (
"context"
"fmt"
"log"
"time"
"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.SuppressionsAPI.CreateSuppression(
ctx,
accountID,
requests.CreateSuppressionRequest{
Email: "test@example.com",
Reason: ahasend.String("Inbox full"),
ExpiresAt: time.Now().Add(time.Hour * 24 * 30),
},
)
if err != nil {
log.Fatalf("Error creating suppression: %v", err)
}
// Check response
if httpResp.StatusCode == 201 {
fmt.Printf("✅ Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("Created suppression: %#v\n", response)
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}curl --request POST \
--url https://api.ahasend.com/v2/accounts/{account_id}/suppressions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"email": "user@example.com",
"domain": "example.com",
"reason": "User requested removal",
"expires_at": "2024-12-25T10:30:00Z"
}
'import requests
url = "https://api.ahasend.com/v2/accounts/{account_id}/suppressions"
payload = {
"email": "user@example.com",
"domain": "example.com",
"reason": "User requested removal",
"expires_at": "2024-12-25T10:30:00Z"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
email: 'user@example.com',
domain: 'example.com',
reason: 'User requested removal',
expires_at: '2024-12-25T10:30:00Z'
})
};
fetch('https://api.ahasend.com/v2/accounts/{account_id}/suppressions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.ahasend.com/v2/accounts/{account_id}/suppressions",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'email' => 'user@example.com',
'domain' => 'example.com',
'reason' => 'User requested removal',
'expires_at' => '2024-12-25T10:30:00Z'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}HttpResponse<String> response = Unirest.post("https://api.ahasend.com/v2/accounts/{account_id}/suppressions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"email\": \"user@example.com\",\n \"domain\": \"example.com\",\n \"reason\": \"User requested removal\",\n \"expires_at\": \"2024-12-25T10:30:00Z\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.ahasend.com/v2/accounts/{account_id}/suppressions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"email\": \"user@example.com\",\n \"domain\": \"example.com\",\n \"reason\": \"User requested removal\",\n \"expires_at\": \"2024-12-25T10:30:00Z\"\n}"
response = http.request(request)
puts response.read_body{
"object": "list",
"data": [
{
"object": "suppression",
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"created_at": "2023-11-07T05:31:56Z",
"email": "jsmith@example.com",
"expires_at": "2023-11-07T05:31:56Z",
"domain": "<string>",
"reason": "<string>"
}
]
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "idempotency key was already used with a different request payload"
}{
"message": "Error message"
}Suppressions
Create Suppression
Creates a new suppression for an email address
Validation Requirements:
emailmust be a valid email addressexpires_atmust be in RFC3339 formatdomainis optional - if not provided, applies to all account domains
POST
/
v2
/
accounts
/
{account_id}
/
suppressions
AhaSend Go SDK
package main
import (
"context"
"fmt"
"log"
"time"
"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.SuppressionsAPI.CreateSuppression(
ctx,
accountID,
requests.CreateSuppressionRequest{
Email: "test@example.com",
Reason: ahasend.String("Inbox full"),
ExpiresAt: time.Now().Add(time.Hour * 24 * 30),
},
)
if err != nil {
log.Fatalf("Error creating suppression: %v", err)
}
// Check response
if httpResp.StatusCode == 201 {
fmt.Printf("✅ Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("Created suppression: %#v\n", response)
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}curl --request POST \
--url https://api.ahasend.com/v2/accounts/{account_id}/suppressions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"email": "user@example.com",
"domain": "example.com",
"reason": "User requested removal",
"expires_at": "2024-12-25T10:30:00Z"
}
'import requests
url = "https://api.ahasend.com/v2/accounts/{account_id}/suppressions"
payload = {
"email": "user@example.com",
"domain": "example.com",
"reason": "User requested removal",
"expires_at": "2024-12-25T10:30:00Z"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
email: 'user@example.com',
domain: 'example.com',
reason: 'User requested removal',
expires_at: '2024-12-25T10:30:00Z'
})
};
fetch('https://api.ahasend.com/v2/accounts/{account_id}/suppressions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.ahasend.com/v2/accounts/{account_id}/suppressions",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'email' => 'user@example.com',
'domain' => 'example.com',
'reason' => 'User requested removal',
'expires_at' => '2024-12-25T10:30:00Z'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}HttpResponse<String> response = Unirest.post("https://api.ahasend.com/v2/accounts/{account_id}/suppressions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"email\": \"user@example.com\",\n \"domain\": \"example.com\",\n \"reason\": \"User requested removal\",\n \"expires_at\": \"2024-12-25T10:30:00Z\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.ahasend.com/v2/accounts/{account_id}/suppressions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"email\": \"user@example.com\",\n \"domain\": \"example.com\",\n \"reason\": \"User requested removal\",\n \"expires_at\": \"2024-12-25T10:30:00Z\"\n}"
response = http.request(request)
puts response.read_body{
"object": "list",
"data": [
{
"object": "suppression",
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"created_at": "2023-11-07T05:31:56Z",
"email": "jsmith@example.com",
"expires_at": "2023-11-07T05:31:56Z",
"domain": "<string>",
"reason": "<string>"
}
]
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "idempotency key was already used with a different request payload"
}{
"message": "Error message"
}Authorizations
API key for authentication
Headers
Optional idempotency key for safe request retries. Must be a unique string for each logical request.
Requests with the same key will return the same response. Keys for non-secret responses expire after 24 hours.
API-key create responses include a one-time secret_key, so their encrypted replay responses expire after 5 minutes.
Maximum string length:
255Path Parameters
Account ID
Body
application/json
⌘I

