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
}
],
"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>"
}
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}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.
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
}
],
"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>"
}
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}templates:read.
To bring a version back, use Restore 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.
Path Parameters
Account ID
Template ID
Version ID
Response
Template version
One published version of a template, without its content.
Object type identifier
template_version Version ID
The version number, counted from 1 for each template
When the version was published
Who published the version. Null when this is not known, as for versions made before versions recorded it, or when the user or API key was deleted for good.
Show child attributes
Show child attributes
The version's subject
The version's preview text
Every variable the version uses
Show child attributes
Show child attributes
The version's default sender. Null when it has none.
Show child attributes
Show child attributes
{
"email": "noreply@example.com",
"name": "Example Corp"
}
The version's default reply-to address. Null when it has none. Its name is always empty.
Show child attributes
Show child attributes
{
"email": "noreply@example.com",
"name": "Example Corp"
}
The version's content. Null when the version has no body.
Show child attributes
Show child attributes

