AhaSend Go SDK
package main
import (
"context"
"fmt"
"log"
"os"
"github.com/AhaSend/ahasend-go/api"
"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()
templateID := uuid.MustParse("11111111-1111-4111-8111-111111111111")
// Versions come newest first, at most 50, with no pagination.
response, _, err := client.TemplatesAPI.GetTemplateVersions(ctx, accountID, templateID)
if err != nil {
log.Fatalf("Error listing template versions: %v", err)
}
for _, version := range response.Data {
publisher := "unknown"
if version.PublishedBy != nil {
publisher = version.PublishedBy.Type + " " + version.PublishedBy.ID.String()
}
fmt.Printf("v%d %s published by %s\n", version.Version, version.PublishedAt, publisher)
}
}import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const templateId = "00000000-0000-4000-8000-000000000009";
const versions = await client.templates.listVersions(templateId);
console.log("Template versions listed.", { count: versions.data.length });
curl --request GET \
--url https://api.ahasend.com/v2/accounts/{account_id}/templates/{template_id}/versions \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.ahasend.com/v2/accounts/{account_id}/templates/{template_id}/versions"
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/{template_id}/versions",
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/{template_id}/versions")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.ahasend.com/v2/accounts/{account_id}/templates/{template_id}/versions")
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_version",
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"version": 123,
"published_at": "2023-11-07T05:31:56Z",
"published_by": {
"type": "user",
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
}
]
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}Transactional Templates
List Template Versions via the API
List the published versions of an AhaSend transactional template, newest first, with the time of each publish and the user or API key that made it.
GET
/
v2
/
accounts
/
{account_id}
/
templates
/
{template_id}
/
versions
AhaSend Go SDK
package main
import (
"context"
"fmt"
"log"
"os"
"github.com/AhaSend/ahasend-go/api"
"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()
templateID := uuid.MustParse("11111111-1111-4111-8111-111111111111")
// Versions come newest first, at most 50, with no pagination.
response, _, err := client.TemplatesAPI.GetTemplateVersions(ctx, accountID, templateID)
if err != nil {
log.Fatalf("Error listing template versions: %v", err)
}
for _, version := range response.Data {
publisher := "unknown"
if version.PublishedBy != nil {
publisher = version.PublishedBy.Type + " " + version.PublishedBy.ID.String()
}
fmt.Printf("v%d %s published by %s\n", version.Version, version.PublishedAt, publisher)
}
}import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const templateId = "00000000-0000-4000-8000-000000000009";
const versions = await client.templates.listVersions(templateId);
console.log("Template versions listed.", { count: versions.data.length });
curl --request GET \
--url https://api.ahasend.com/v2/accounts/{account_id}/templates/{template_id}/versions \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.ahasend.com/v2/accounts/{account_id}/templates/{template_id}/versions"
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/{template_id}/versions",
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/{template_id}/versions")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.ahasend.com/v2/accounts/{account_id}/templates/{template_id}/versions")
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_version",
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"version": 123,
"published_at": "2023-11-07T05:31:56Z",
"published_by": {
"type": "user",
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
}
]
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}The AhaSend API returns the published versions of a template, newest first, without their content. The template keeps its 50 most recent versions and removes older ones. Every publish that has a draft to publish makes a version. Access requires
templates:read.
published_by shows the user or API key that published the version. It is null when neither is known, for example when the API key that published it was deleted. To read the content of a version, use Get Template Version.
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.

