package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go/api"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
// Create context for the API call
ctx := context.Background()
response, httpResp, err := client.SubAccountsAPI.GetSubAccountsUsage(ctx, accountID)
if err != nil {
log.Fatalf("Error getting sub-accounts usage: %v", err)
}
if httpResp.StatusCode == 200 {
fmt.Printf("✅ Retrieved sub-accounts usage! Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("Currency: %s\n", response.Currency)
fmt.Printf("Allocation method: %s\n", response.AllocationMethod)
fmt.Printf("Total reception count: %d\n", response.Total.ReceptionCount)
fmt.Printf("Total allocated cost: %.2f\n", response.Total.AllocatedCost)
fmt.Printf("Sub-accounts: %d\n", len(response.SubAccounts))
for i, sub := range response.SubAccounts {
fmt.Printf(" [%d] reception count: %d, allocated cost: %.2f\n", i, sub.ReceptionCount, sub.AllocatedCost)
}
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}curl --request GET \
--url https://api.ahasend.com/v2/accounts/{account_id}/sub-accounts/usage \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.ahasend.com/v2/accounts/{account_id}/sub-accounts/usage"
headers = {"Authorization": "Bearer <token>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};
fetch('https://api.ahasend.com/v2/accounts/{account_id}/sub-accounts/usage', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.ahasend.com/v2/accounts/{account_id}/sub-accounts/usage",
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/usage")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.ahasend.com/v2/accounts/{account_id}/sub-accounts/usage")
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{
"billing_period": {
"start": "2024-01-01T00:00:00Z",
"end": "2024-02-01T00:00:00Z"
},
"currency": "usd",
"allocation_method": "proportional",
"allocation_note": "allocated_cost is a proportional share of the parent's pooled invoice for the period, not what the sub would pay on its own plan.",
"parent": {
"account_id": "9d0cf9d0-4f5e-4674-bcf1-8ec39968b6e1",
"reception_count": 1000000,
"allocated_cost": 20
},
"sub_accounts": [
{
"account_id": "2f3c5d2a-9ef8-4c91-a5f4-79990c8c1d3a",
"name": "Acme Subsidiary",
"reception_count": 3000000,
"allocated_cost": 60
}
],
"removed_sub_accounts": {
"reception_count": 0,
"allocated_cost": 0
},
"total": {
"reception_count": 4000000,
"allocated_cost": 80
}
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}Get Sub-Account Usage
Returns current billing-period usage and proportional allocated cost for the parent and active sub accounts
package main
import (
"context"
"fmt"
"log"
"github.com/AhaSend/ahasend-go/api"
"github.com/google/uuid"
)
func main() {
// Create API client with authentication
client := api.NewAPIClient(
api.WithAPIKey("aha-sk-your-64-character-key"),
)
accountID := uuid.New()
// Create context for the API call
ctx := context.Background()
response, httpResp, err := client.SubAccountsAPI.GetSubAccountsUsage(ctx, accountID)
if err != nil {
log.Fatalf("Error getting sub-accounts usage: %v", err)
}
if httpResp.StatusCode == 200 {
fmt.Printf("✅ Retrieved sub-accounts usage! Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("Currency: %s\n", response.Currency)
fmt.Printf("Allocation method: %s\n", response.AllocationMethod)
fmt.Printf("Total reception count: %d\n", response.Total.ReceptionCount)
fmt.Printf("Total allocated cost: %.2f\n", response.Total.AllocatedCost)
fmt.Printf("Sub-accounts: %d\n", len(response.SubAccounts))
for i, sub := range response.SubAccounts {
fmt.Printf(" [%d] reception count: %d, allocated cost: %.2f\n", i, sub.ReceptionCount, sub.AllocatedCost)
}
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}curl --request GET \
--url https://api.ahasend.com/v2/accounts/{account_id}/sub-accounts/usage \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.ahasend.com/v2/accounts/{account_id}/sub-accounts/usage"
headers = {"Authorization": "Bearer <token>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};
fetch('https://api.ahasend.com/v2/accounts/{account_id}/sub-accounts/usage', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.ahasend.com/v2/accounts/{account_id}/sub-accounts/usage",
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/usage")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.ahasend.com/v2/accounts/{account_id}/sub-accounts/usage")
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{
"billing_period": {
"start": "2024-01-01T00:00:00Z",
"end": "2024-02-01T00:00:00Z"
},
"currency": "usd",
"allocation_method": "proportional",
"allocation_note": "allocated_cost is a proportional share of the parent's pooled invoice for the period, not what the sub would pay on its own plan.",
"parent": {
"account_id": "9d0cf9d0-4f5e-4674-bcf1-8ec39968b6e1",
"reception_count": 1000000,
"allocated_cost": 20
},
"sub_accounts": [
{
"account_id": "2f3c5d2a-9ef8-4c91-a5f4-79990c8c1d3a",
"name": "Acme Subsidiary",
"reception_count": 3000000,
"allocated_cost": 60
}
],
"removed_sub_accounts": {
"reception_count": 0,
"allocated_cost": 0
},
"total": {
"reception_count": 4000000,
"allocated_cost": 80
}
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}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
Response
Sub-account usage breakdown
Show child attributes
Show child attributes
Currency code used for cost allocation
Method used to allocate the pooled parent invoice cost
proportional Disclaimer explaining that allocated cost is not standalone sub-account pricing
Show child attributes
Show child attributes
{
"account_id": "2f3c5d2a-9ef8-4c91-a5f4-79990c8c1d3a",
"name": "Acme Subsidiary",
"reception_count": 3000000,
"allocated_cost": 60
}
Per-sub-account usage and allocated cost
Show child attributes
Show child attributes
Aggregated usage from sub accounts deleted during the period; still billed to the parent and not identified individually
Show child attributes
Show child attributes
{
"account_id": "2f3c5d2a-9ef8-4c91-a5f4-79990c8c1d3a",
"name": "Acme Subsidiary",
"reception_count": 3000000,
"allocated_cost": 60
}
Show child attributes
Show child attributes
{
"account_id": "2f3c5d2a-9ef8-4c91-a5f4-79990c8c1d3a",
"name": "Acme Subsidiary",
"reception_count": 3000000,
"allocated_cost": 60
}

