POST
/
v2
/
accounts
/
{account_id}
/
messages
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/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()

  response, httpResp, err := client.MessagesAPI.CreateMessage(
    ctx,
    accountID,
    requests.CreateMessageRequest{
      From: common.SenderAddress{
        Email: "[email protected]",
        Name:  ahasend.String("Example Corp."),
      },
      Recipients: []common.Recipient{
        {
          Email: "[email protected]",
          Name:  ahasend.String("John Smith"),
        },
      },
      Subject:     "Hello",
      TextContent: ahasend.String("Hello world!"),
      Sandbox:     ahasend.Bool(true),
    },
  )
  if err != nil {
    log.Fatalf("Error sending message: %v", err)
  }

  // Check response
  if httpResp.StatusCode == 200 {
    fmt.Printf("✅ Send successful! Status: %d\n", httpResp.StatusCode)
    if response != nil {
      fmt.Printf("Message ID: %s\n", *response.Data[0].ID)
    }
  } else {
    fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
  }
}
{
  "object": "list",
  "data": [
    {
      "object": "message",
      "id": "<[email protected]>",
      "recipient": {
        "email": "[email protected]",
        "name": "John Doe",
        "substitutions": {
          "first_name": "John",
          "order_id": "12345"
        }
      },
      "status": "queued",
      "error": "<string>",
      "schedule": {
        "first_attempt": "2023-12-25T10:30:00Z",
        "expires": "2023-12-26T10:30:00Z"
      }
    }
  ]
}

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 expire after 24 hours.

Maximum length: 255

Path Parameters

account_id
string<uuid>
required

Account ID

Body

application/json

Response

202
application/json

Message created successfully

The response is of type object.