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")
versionID := uuid.MustParse("22222222-2222-4222-8222-222222222222")
response, _, err := client.TemplatesAPI.GetTemplateVersion(ctx, accountID, templateID, versionID)
if err != nil {
log.Fatalf("Error getting template version: %v", err)
}
fmt.Printf("v%d subject: %s\n", response.Version, response.Subject)
if response.Content != nil {
fmt.Println(response.Content.Text)
}
}
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const templateId = "00000000-0000-4000-8000-000000000009";
const versionId = "00000000-0000-4000-8000-000000000012";
const version = await client.templates.getVersion(templateId, versionId);
console.log("Template version found.", { id: version.id, version: version.version });
curl --request GET \
--url https://api.ahasend.com/v2/accounts/{account_id}/templates/{template_id}/versions/{version_id} \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.ahasend.com/v2/accounts/{account_id}/templates/{template_id}/versions/{version_id}"
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/{version_id}",
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/{version_id}")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.ahasend.com/v2/accounts/{account_id}/templates/{template_id}/versions/{version_id}")
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": "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"
},
"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"
},
"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"
}
}
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}Transactional Templates
Get a Template Version via the API
Retrieve one published version of an AhaSend transactional template with its content, subject, sender and variables, to compare or restore it.
GET
/
v2
/
accounts
/
{account_id}
/
templates
/
{template_id}
/
versions
/
{version_id}
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")
versionID := uuid.MustParse("22222222-2222-4222-8222-222222222222")
response, _, err := client.TemplatesAPI.GetTemplateVersion(ctx, accountID, templateID, versionID)
if err != nil {
log.Fatalf("Error getting template version: %v", err)
}
fmt.Printf("v%d subject: %s\n", response.Version, response.Subject)
if response.Content != nil {
fmt.Println(response.Content.Text)
}
}
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const templateId = "00000000-0000-4000-8000-000000000009";
const versionId = "00000000-0000-4000-8000-000000000012";
const version = await client.templates.getVersion(templateId, versionId);
console.log("Template version found.", { id: version.id, version: version.version });
curl --request GET \
--url https://api.ahasend.com/v2/accounts/{account_id}/templates/{template_id}/versions/{version_id} \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.ahasend.com/v2/accounts/{account_id}/templates/{template_id}/versions/{version_id}"
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/{version_id}",
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/{version_id}")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.ahasend.com/v2/accounts/{account_id}/templates/{template_id}/versions/{version_id}")
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": "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"
},
"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"
},
"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"
}
}
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}The AhaSend API returns one published version of a template with its content. Access requires
templates:read.
A version’s variables are as saved when the version was published. A version published before variable kinds were recorded shows every variable with kind value and no item_fields. Save and publish the template again to get a version that records them. A published template has no draft, so make an edit and save it first.
To bring a version back, use Restore Template Version.
Related guides
Authorizations
Path Parameters
Response
Template version
One published version of a template, without its content.

