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.Address{
        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
from
object
required
Example:
{
"email": "[email protected]",
"name": "Example Corp"
}
recipients
object[]
required

This does not set the To header to multiple addresses, it sends a separate message for each recipient

Minimum length: 1
subject
string
required

Email subject line

reply_to
object

If provided, the reply-to header in headers array must not be provided

Example:
{
"email": "[email protected]",
"name": "Example Corp"
}
text_content
string

Plain text content. Required if html_content is empty

html_content
string

HTML content. Required if text_content is empty

amp_content
string

AMP HTML content

attachments
object[]

File attachments

headers
object

Custom email headers. reply-to header cannot be provided if reply_to is provided, message-id will be ignored and automatically generated

substitutions
object

Global substitutions, recipient substitutions override global

tags
string[]

Tags for categorizing messages

sandbox
boolean
default:false

If true, the message will be sent to the sandbox environment

sandbox_result
enum<string>

The result of the sandbox send

Available options:
deliver,
bounce,
defer,
fail,
suppress
tracking
object | null

Tracking settings for the message, overrides default account settings

Example:
{ "open": true, "click": true }
retention
object | null

Retention settings for the message, overrides default account settings

Example:
{ "metadata": 1, "data": 0 }
schedule
object

Schedule for message delivery

Example:
{
"first_attempt": "2023-12-25T10:30:00Z",
"expires": "2023-12-26T10:30:00Z"
}

Response

Message created successfully

object
enum<string>
required

Object type identifier

Available options:
list
data
object[]
required

List of messages and their statuses