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()
subAccountID := uuid.MustParse("7d3c9f5e-2a41-4b8e-9c6d-0f1e2a3b4c5d")
response, _, err := client.SubAccountsAPI.GetSubAccount(ctx, accountID, subAccountID)
if err != nil {
log.Fatalf("Error getting sub account: %v", err)
}
fmt.Printf("%s %s (%s)\n", response.Name, response.Website, response.Status)
fmt.Printf("Domains: %d, members: %d\n", response.DomainCount, response.MemberCount)
}import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const subAccountId = "00000000-0000-4000-8000-000000000004";
const subAccount = await client.subAccounts.get(subAccountId);
console.log("Sub-account found.", { id: subAccount.id, status: subAccount.status });
curl --request GET \
--url https://api.ahasend.com/v2/accounts/{account_id}/sub-accounts/{sub_account_id} \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.ahasend.com/v2/accounts/{account_id}/sub-accounts/{sub_account_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}/sub-accounts/{sub_account_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}/sub-accounts/{sub_account_id}")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.ahasend.com/v2/accounts/{account_id}/sub-accounts/{sub_account_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": "sub_account",
"id": "2f3c5d2a-9ef8-4c91-a5f4-79990c8c1d3a",
"parent_account_id": "9d0cf9d0-4f5e-4674-bcf1-8ec39968b6e1",
"name": "Acme Subsidiary",
"website": "acme.example.com",
"status": "active",
"monthly_credit": 0,
"created_at": "2024-01-01T00:00:00Z",
"domain_count": 2,
"member_count": 3,
"last_activity_at": "2024-01-15T12:00:00Z"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}Get a Sub-Account via the API
Retrieve one AhaSend sub-account by ID, including its status, monthly credit cap, domain and member counts, and last activity time.
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()
subAccountID := uuid.MustParse("7d3c9f5e-2a41-4b8e-9c6d-0f1e2a3b4c5d")
response, _, err := client.SubAccountsAPI.GetSubAccount(ctx, accountID, subAccountID)
if err != nil {
log.Fatalf("Error getting sub account: %v", err)
}
fmt.Printf("%s %s (%s)\n", response.Name, response.Website, response.Status)
fmt.Printf("Domains: %d, members: %d\n", response.DomainCount, response.MemberCount)
}import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const subAccountId = "00000000-0000-4000-8000-000000000004";
const subAccount = await client.subAccounts.get(subAccountId);
console.log("Sub-account found.", { id: subAccount.id, status: subAccount.status });
curl --request GET \
--url https://api.ahasend.com/v2/accounts/{account_id}/sub-accounts/{sub_account_id} \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.ahasend.com/v2/accounts/{account_id}/sub-accounts/{sub_account_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}/sub-accounts/{sub_account_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}/sub-accounts/{sub_account_id}")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.ahasend.com/v2/accounts/{account_id}/sub-accounts/{sub_account_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": "sub_account",
"id": "2f3c5d2a-9ef8-4c91-a5f4-79990c8c1d3a",
"parent_account_id": "9d0cf9d0-4f5e-4674-bcf1-8ec39968b6e1",
"name": "Acme Subsidiary",
"website": "acme.example.com",
"status": "active",
"monthly_credit": 0,
"created_at": "2024-01-01T00:00:00Z",
"domain_count": 2,
"member_count": 3,
"last_activity_at": "2024-01-15T12:00:00Z"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}Related Guides
- API authentication, Permission scopes, Sub-account setup.
- Sub-account API rules, Sub-account CLI, Child API keys.
- API errors, API rate limits, Plans and limits.
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
Parent account ID
Sub account ID
Response
Sub account details
Object type identifier
sub_account Unique identifier for the sub account
Parent account ID
When the sub account was created
Sub account name
Account website, stored as a bare domain such as acme.com
255Current sub-account status
active, suspended, parent-suspended, deleted Optional monthly cap; 0 means no cap
x >= 0Number of domains owned by the sub account
x >= 0Number of direct members on the sub account
x >= 0Last recorded sub-account email activity

