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.DomainsAPI.UpdateDomain(ctx, accountID, "example.com", requests.UpdateDomainRequest{
TrackingSubdomain: ahasend.String("click"),
})
if err != nil {
log.Fatalf("Error updating domain: %v", err)
}
fmt.Printf("Updated domain %s\n", response.Domain)
}import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const domainName = "example.com";
const domain = await client.domains.update(domainName, { tracking_subdomain: "click" });
console.log("Domain updated.", { domain: domain.domain });
curl --request PUT \
--url https://api.ahasend.com/v2/accounts/{account_id}/domains/{domain} \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"tracking_subdomain": "click",
"return_path_subdomain": "mail",
"subscription_subdomain": "preferences",
"media_subdomain": "media",
"dkim_rotation_interval_days": 45
}
'import requests
url = "https://api.ahasend.com/v2/accounts/{account_id}/domains/{domain}"
payload = {
"tracking_subdomain": "click",
"return_path_subdomain": "mail",
"subscription_subdomain": "preferences",
"media_subdomain": "media",
"dkim_rotation_interval_days": 45
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.put(url, json=payload, headers=headers)
print(response.text)<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.ahasend.com/v2/accounts/{account_id}/domains/{domain}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'tracking_subdomain' => 'click',
'return_path_subdomain' => 'mail',
'subscription_subdomain' => 'preferences',
'media_subdomain' => 'media',
'dkim_rotation_interval_days' => 45
]),
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.put("https://api.ahasend.com/v2/accounts/{account_id}/domains/{domain}")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"tracking_subdomain\": \"click\",\n \"return_path_subdomain\": \"mail\",\n \"subscription_subdomain\": \"preferences\",\n \"media_subdomain\": \"media\",\n \"dkim_rotation_interval_days\": 45\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.ahasend.com/v2/accounts/{account_id}/domains/{domain}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"tracking_subdomain\": \"click\",\n \"return_path_subdomain\": \"mail\",\n \"subscription_subdomain\": \"preferences\",\n \"media_subdomain\": \"media\",\n \"dkim_rotation_interval_days\": 45\n}"
response = http.request(request)
puts response.read_body{
"object": "domain",
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"domain": "<string>",
"account_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"dns_records": [
{
"type": "<string>",
"host": "<string>",
"content": "<string>",
"required": true,
"propagated": true,
"label": "<string>"
}
],
"last_dns_check_at": "2023-11-07T05:31:56Z",
"dns_valid": true,
"tracking_subdomain": "<string>",
"return_path_subdomain": "<string>",
"subscription_subdomain": "<string>",
"media_subdomain": "<string>",
"dkim_rotation_interval_days": 123,
"dkim_selector": "<string>",
"rotation_ready": true,
"dsn_recipient": "<string>",
"sending_type": "transactional",
"paused": true,
"paused_at": "2023-11-07T05:31:56Z",
"pause_reason": "<string>"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}Update a Sending Domain via the API
Update an AhaSend sending domain’s custom tracking, return-path, subscription and media subdomains, DKIM selector and DKIM rotation interval.
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.DomainsAPI.UpdateDomain(ctx, accountID, "example.com", requests.UpdateDomainRequest{
TrackingSubdomain: ahasend.String("click"),
})
if err != nil {
log.Fatalf("Error updating domain: %v", err)
}
fmt.Printf("Updated domain %s\n", response.Domain)
}import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const domainName = "example.com";
const domain = await client.domains.update(domainName, { tracking_subdomain: "click" });
console.log("Domain updated.", { domain: domain.domain });
curl --request PUT \
--url https://api.ahasend.com/v2/accounts/{account_id}/domains/{domain} \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"tracking_subdomain": "click",
"return_path_subdomain": "mail",
"subscription_subdomain": "preferences",
"media_subdomain": "media",
"dkim_rotation_interval_days": 45
}
'import requests
url = "https://api.ahasend.com/v2/accounts/{account_id}/domains/{domain}"
payload = {
"tracking_subdomain": "click",
"return_path_subdomain": "mail",
"subscription_subdomain": "preferences",
"media_subdomain": "media",
"dkim_rotation_interval_days": 45
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.put(url, json=payload, headers=headers)
print(response.text)<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.ahasend.com/v2/accounts/{account_id}/domains/{domain}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'tracking_subdomain' => 'click',
'return_path_subdomain' => 'mail',
'subscription_subdomain' => 'preferences',
'media_subdomain' => 'media',
'dkim_rotation_interval_days' => 45
]),
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.put("https://api.ahasend.com/v2/accounts/{account_id}/domains/{domain}")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"tracking_subdomain\": \"click\",\n \"return_path_subdomain\": \"mail\",\n \"subscription_subdomain\": \"preferences\",\n \"media_subdomain\": \"media\",\n \"dkim_rotation_interval_days\": 45\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.ahasend.com/v2/accounts/{account_id}/domains/{domain}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"tracking_subdomain\": \"click\",\n \"return_path_subdomain\": \"mail\",\n \"subscription_subdomain\": \"preferences\",\n \"media_subdomain\": \"media\",\n \"dkim_rotation_interval_days\": 45\n}"
response = http.request(request)
puts response.read_body{
"object": "domain",
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"domain": "<string>",
"account_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"dns_records": [
{
"type": "<string>",
"host": "<string>",
"content": "<string>",
"required": true,
"propagated": true,
"label": "<string>"
}
],
"last_dns_check_at": "2023-11-07T05:31:56Z",
"dns_valid": true,
"tracking_subdomain": "<string>",
"return_path_subdomain": "<string>",
"subscription_subdomain": "<string>",
"media_subdomain": "<string>",
"dkim_rotation_interval_days": 123,
"dkim_selector": "<string>",
"rotation_ready": true,
"dsn_recipient": "<string>",
"sending_type": "transactional",
"paused": true,
"paused_at": "2023-11-07T05:31:56Z",
"pause_reason": "<string>"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}Related guides
- API authentication, Permission scopes, Domain setup.
- Domain API, Domain CLI, DNS whitelabel.
- API errors, API rate limits.
Authorizations
Body
Optional custom DKIM selector for the domain. Omit or send null to leave the current value unchanged; send an empty or whitespace-only string to clear the override and revert to the default selector. The value is trimmed before it is interpreted, so whitespace-only input clears the override just like an empty string.
When provided, it is normalized to lowercase and must be a single DNS label: 1-62 characters using lowercase letters, numbers, and hyphens only, without a leading or trailing hyphen. It cannot be changed once the selector locks after DNS verification or while a DKIM key rotation is in progress.
On managed DNS domains, DKIM uses two selectors and switches between them at each key rotation: this selector, and a second selector that is this selector followed by 2. When the selector ends in a 1 that does not follow another digit, that 1 becomes 2 instead: os → os2, os1 → os2, but s11 → s112.
DNS records that already exist at the hosts of a selector sent in this field do not block it. On a managed DNS domain, DKIM passes once the host of the DKIM record marked required in the domain's dns_records (DKIM hosts contain ._domainkey.) points to that record's content, directly or through other CNAME records; point the other DKIM record's host to its content too, so DKIM rotation can run.
Note: This parameter is only supported on Platform Partner accounts.
Response
Domain updated successfully
Per-domain DKIM selector override. Null means no per-domain override is set.
This reports the configured per-domain override only, not the effective selector used for DKIM signing. The effective selector is resolved separately and can differ — for example, a selector locked after DNS verification takes precedence over this override.

