Skip to main content
GET
/
v2
/
accounts
/
{account_id}
/
sub-accounts
/
{sub_account_id}
/
api-keys
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/common"
  "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()
  subAccountID := uuid.New()

  // Create context for the API call
  ctx := context.Background()

  // List a sub-account's API keys (paginated, up to 50 per page).
  // Note: secret_key is omitted from list responses; only create returns it once.
  response, httpResp, err := client.SubAccountsAPI.ListSubAccountAPIKeys(
    ctx,
    accountID,
    subAccountID,
    &common.PaginationParams{Limit: ahasend.Int32(50)},
  )
  if err != nil {
    log.Fatalf("Error listing sub-account API keys: %v", err)
  }

  if httpResp.StatusCode == 200 {
    fmt.Printf("✅ Listed sub-account API keys. Status: %d\n", httpResp.StatusCode)
    if response != nil {
      fmt.Printf("Found %d API keys\n", len(response.Data))
      for _, key := range response.Data {
        fmt.Printf("API key %s: %s\n", key.ID, key.Label)
      }
    }
  } else {
    fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
  }
}
{
  "object": "list",
  "data": [
    {
      "object": "api_key",
      "id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
      "created_at": "2023-11-07T05:31:56Z",
      "updated_at": "2023-11-07T05:31:56Z",
      "account_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
      "label": "<string>",
      "public_key": "<string>",
      "scopes": [
        {
          "id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
          "created_at": "2023-11-07T05:31:56Z",
          "updated_at": "2023-11-07T05:31:56Z",
          "api_key_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
          "scope": "<string>",
          "domain_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
        }
      ],
      "ip_allow_list": [
        "<string>"
      ],
      "last_used_at": "2023-11-07T05:31:56Z",
      "secret_key": "<string>"
    }
  ],
  "pagination": {
    "has_more": true,
    "next_cursor": "eyJpZCI6MTIzNH0="
  }
}
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

Path Parameters

account_id
string<uuid>
required

Parent account ID

sub_account_id
string<uuid>
required

Sub account ID

Query Parameters

limit
integer
default:100

Maximum number of items to return (1-100)

Required range: 1 <= x <= 100
after
string

Pagination cursor for the next page. Provide the value from next_cursor in the response.

before
string

Pagination cursor for the previous page. Provide the value from previous_cursor in the response.

Response

List of sub-account API keys

object
enum<string>
required

Object type identifier

Available options:
list
data
object[]
required

Array of API keys

pagination
object
required
Example:
{
"has_more": true,
"next_cursor": "eyJpZCI6MTIzNH0="
}