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.TemplatesAPI.GetTemplates(ctx, accountID, requests.GetTemplatesParams{
Limit: ahasend.Int32(100),
})
if err != nil {
log.Fatalf("Error listing templates: %v", err)
}
for _, template := range response.Data {
fmt.Printf("%s %s\n", template.ID, template.Name)
}
}import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const page = await client.templates.list({ limit: 20 });
console.log("Templates listed.", { count: page.data.length });
curl --request GET \
--url https://api.ahasend.com/v2/accounts/{account_id}/templates \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.ahasend.com/v2/accounts/{account_id}/templates"
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}/templates",
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}/templates")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.ahasend.com/v2/accounts/{account_id}/templates")
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": "template",
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"name": "<string>",
"subject": "<string>",
"preheader": "<string>",
"variables": [
{
"name": "<string>",
"required": true,
"kind": "value",
"item_fields": [
"<string>"
]
}
],
"from": {
"email": "noreply@example.com",
"name": "Example Corp"
},
"reply_to": {
"email": "noreply@example.com",
"name": "Example Corp"
},
"editor": "advanced",
"has_draft": true,
"content": {
"text_is_custom": true,
"mjml": "<string>",
"html": "<string>",
"text": "<string>",
"markup": "<Email version=\"1\">\n <Heading level=\"3\">Welcome</Heading>\n <Paragraph>Thanks for signing up.</Paragraph>\n</Email>\n",
"markup_error": {
"code": "html_block",
"message": "The design holds an HTML block, which AhaML cannot show; remove the block in the dashboard to read and write the design as AhaML"
}
},
"markup_warnings": [
{
"code": "<string>",
"message": "<string>",
"line": 2,
"column": 2,
"path": "<string>",
"hint": "<string>"
}
]
}
],
"pagination": {
"has_more": true,
"next_cursor": "eyJpZCI6MTIzNH0="
}
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}Transactional Templates
List Transactional Templates via the API
List the transactional templates in your AhaSend account, newest first, with their editor and whether each one has unpublished changes.
GET
/
v2
/
accounts
/
{account_id}
/
templates
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.TemplatesAPI.GetTemplates(ctx, accountID, requests.GetTemplatesParams{
Limit: ahasend.Int32(100),
})
if err != nil {
log.Fatalf("Error listing templates: %v", err)
}
for _, template := range response.Data {
fmt.Printf("%s %s\n", template.ID, template.Name)
}
}import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const page = await client.templates.list({ limit: 20 });
console.log("Templates listed.", { count: page.data.length });
curl --request GET \
--url https://api.ahasend.com/v2/accounts/{account_id}/templates \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.ahasend.com/v2/accounts/{account_id}/templates"
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}/templates",
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}/templates")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.ahasend.com/v2/accounts/{account_id}/templates")
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": "template",
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"name": "<string>",
"subject": "<string>",
"preheader": "<string>",
"variables": [
{
"name": "<string>",
"required": true,
"kind": "value",
"item_fields": [
"<string>"
]
}
],
"from": {
"email": "noreply@example.com",
"name": "Example Corp"
},
"reply_to": {
"email": "noreply@example.com",
"name": "Example Corp"
},
"editor": "advanced",
"has_draft": true,
"content": {
"text_is_custom": true,
"mjml": "<string>",
"html": "<string>",
"text": "<string>",
"markup": "<Email version=\"1\">\n <Heading level=\"3\">Welcome</Heading>\n <Paragraph>Thanks for signing up.</Paragraph>\n</Email>\n",
"markup_error": {
"code": "html_block",
"message": "The design holds an HTML block, which AhaML cannot show; remove the block in the dashboard to read and write the design as AhaML"
}
},
"markup_warnings": [
{
"code": "<string>",
"message": "<string>",
"line": 2,
"column": 2,
"path": "<string>",
"hint": "<string>"
}
]
}
],
"pagination": {
"has_more": true,
"next_cursor": "eyJpZCI6MTIzNH0="
}
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}The AhaSend API returns the account’s transactional templates. Access requires
templates:read.
Each template is listed as its published copy, without its content. When has_draft is true, the template has changes that are not published yet. To read the content, use Get Template, which returns the draft while one exists, or Get Published Template.
Campaign templates are not in this list. To list them, use List Campaign Templates.
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.
Path Parameters
Account ID
Query Parameters
Maximum number of items to return (1-100)
Required range:
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.

