Skip to main content
POST
/
v2
/
accounts
/
{account_id}
/
sub-accounts
AhaSend Go SDK
package main

import (
  "context"
  "fmt"
  "log"

  "github.com/AhaSend/ahasend-go"
  "github.com/AhaSend/ahasend-go/api"
  "github.com/AhaSend/ahasend-go/models/requests"
  "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()

  // Create a sub account with an idempotency key for safe retries
  response, httpResp, err := client.SubAccountsAPI.CreateSubAccount(ctx, accountID, requests.CreateSubAccountRequest{
    Name:          "Acme Subsidiary",
    Website:       "acme.example.com",
    MonthlyCredit: ahasend.Int64(0),
  }, api.WithIdempotencyKey("subacct-20240101-acme"))
  if err != nil {
    log.Fatalf("Error creating sub account: %v", err)
  }

  if httpResp.StatusCode == 201 {
    fmt.Printf("✅ Sub account created! Status: %d\n", httpResp.StatusCode)
    if response != nil {
      fmt.Printf("ID: %s\n", response.ID)
      fmt.Printf("Name: %s\n", response.Name)
      fmt.Printf("Status: %s\n", response.Status)
    }
  } else {
    fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
  }
}
{
  "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"
}
Platform Partner feature: Sub Accounts is part of our Platform Partner capabilities and is currently in early access. Contact us to enable it on your account.

Authorizations

Authorization
string
header
required

API key for authentication

Headers

Idempotency-Key
string

Optional idempotency key for safe request retries. Must be a unique string for each logical request. Requests with the same key will return the same response. Keys for non-secret responses expire after 24 hours. API-key create responses include a one-time secret_key, so their encrypted replay responses expire after 5 minutes.

Maximum string length: 255

Path Parameters

account_id
string<uuid>
required

Parent account ID

Body

application/json
name
string
required

Human-readable name for the sub account; leading and trailing whitespace is trimmed and the result must not be blank

Required string length: 1 - 255
website
string<fqdn>
required

Account website domain

Maximum string length: 255
monthly_credit
integer<int64>
default:0

Optional monthly cap; 0 means no cap

Required range: 0 <= x <= 1000000000

Response

Sub account created successfully

object
enum<string>
required

Object type identifier

Available options:
sub_account
id
string<uuid>
required

Unique identifier for the sub account

parent_account_id
string<uuid>
required

Parent account ID

created_at
string<date-time>
required

When the sub account was created

name
string
required

Sub account name

website
string<fqdn>
required

Account website domain

Maximum string length: 255
status
enum<string>
required

Current sub-account status

Available options:
active,
suspended,
parent-suspended,
deleted
monthly_credit
integer<int64>
required

Optional monthly cap; 0 means no cap

Required range: x >= 0
domain_count
integer<int64>
required

Number of domains owned by the sub account

Required range: x >= 0
member_count
integer<int64>
required

Number of direct members on the sub account

Required range: x >= 0
last_activity_at
string<date-time> | null
required

Last recorded sub-account email activity