package main
import (
"context"
"fmt"
"log"
"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()
// Call the ping endpoint
response, httpResp, err := client.RoutesAPI.CreateRoute(
ctx,
accountID,
requests.CreateRouteRequest{
Name: "My Route",
URL: "https://mystartup.com/tickets",
Recipient: "ticket-*@mystartup.com",
Enabled: true,
Attachments: true,
Headers: true,
StripReplies: true,
},
)
if err != nil {
log.Fatalf("Error creating route: %v", err)
}
// Check response
if httpResp.StatusCode == 201 {
fmt.Printf("✅ Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("Created route: %#v\n", response)
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const route = await client.routes.create(
{
name: "Inbound messages",
url: "https://example.com/inbound",
recipient: "inbound@example.com",
},
{ idempotencyKey: "sdk-sample-create-route" },
);
console.log("Route created.", { id: route.id, name: route.name });
curl --request POST \
--url https://api.ahasend.com/v2/accounts/{account_id}/routes \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "Support Route",
"url": "https://example.com/webhook",
"recipient": "support@example.com",
"enabled": true
}
'import requests
url = "https://api.ahasend.com/v2/accounts/{account_id}/routes"
payload = {
"name": "Support Route",
"url": "https://example.com/webhook",
"recipient": "support@example.com",
"enabled": True
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.ahasend.com/v2/accounts/{account_id}/routes",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'name' => 'Support Route',
'url' => 'https://example.com/webhook',
'recipient' => 'support@example.com',
'enabled' => true
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}HttpResponse<String> response = Unirest.post("https://api.ahasend.com/v2/accounts/{account_id}/routes")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"Support Route\",\n \"url\": \"https://example.com/webhook\",\n \"recipient\": \"support@example.com\",\n \"enabled\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.ahasend.com/v2/accounts/{account_id}/routes")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"Support Route\",\n \"url\": \"https://example.com/webhook\",\n \"recipient\": \"support@example.com\",\n \"enabled\": true\n}"
response = http.request(request)
puts response.read_body{
"object": "route",
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"name": "<string>",
"url": "<string>",
"recipient": "<string>",
"attachments": true,
"headers": true,
"group_by_message_id": true,
"strip_replies": true,
"enabled": true,
"success_count": 1,
"error_count": 1,
"errors_since_last_success": 1,
"last_request_at": "2023-11-07T05:31:56Z",
"secret": "<string>"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "A request with this idempotency key is already in progress"
}{
"message": "idempotency key was already used with a different request payload"
}{
"message": "Error message"
}Create Route
Creates a new route for inbound email routing. Authorization uses the
domain in recipient: the global write role or its matching
domain-specific write role is sufficient.
package main
import (
"context"
"fmt"
"log"
"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()
// Call the ping endpoint
response, httpResp, err := client.RoutesAPI.CreateRoute(
ctx,
accountID,
requests.CreateRouteRequest{
Name: "My Route",
URL: "https://mystartup.com/tickets",
Recipient: "ticket-*@mystartup.com",
Enabled: true,
Attachments: true,
Headers: true,
StripReplies: true,
},
)
if err != nil {
log.Fatalf("Error creating route: %v", err)
}
// Check response
if httpResp.StatusCode == 201 {
fmt.Printf("✅ Status: %d\n", httpResp.StatusCode)
if response != nil {
fmt.Printf("Created route: %#v\n", response)
}
} else {
fmt.Printf("❌ Unexpected status code: %d\n", httpResp.StatusCode)
}
}import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const route = await client.routes.create(
{
name: "Inbound messages",
url: "https://example.com/inbound",
recipient: "inbound@example.com",
},
{ idempotencyKey: "sdk-sample-create-route" },
);
console.log("Route created.", { id: route.id, name: route.name });
curl --request POST \
--url https://api.ahasend.com/v2/accounts/{account_id}/routes \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "Support Route",
"url": "https://example.com/webhook",
"recipient": "support@example.com",
"enabled": true
}
'import requests
url = "https://api.ahasend.com/v2/accounts/{account_id}/routes"
payload = {
"name": "Support Route",
"url": "https://example.com/webhook",
"recipient": "support@example.com",
"enabled": True
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.ahasend.com/v2/accounts/{account_id}/routes",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'name' => 'Support Route',
'url' => 'https://example.com/webhook',
'recipient' => 'support@example.com',
'enabled' => true
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}HttpResponse<String> response = Unirest.post("https://api.ahasend.com/v2/accounts/{account_id}/routes")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"Support Route\",\n \"url\": \"https://example.com/webhook\",\n \"recipient\": \"support@example.com\",\n \"enabled\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.ahasend.com/v2/accounts/{account_id}/routes")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"Support Route\",\n \"url\": \"https://example.com/webhook\",\n \"recipient\": \"support@example.com\",\n \"enabled\": true\n}"
response = http.request(request)
puts response.read_body{
"object": "route",
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"name": "<string>",
"url": "<string>",
"recipient": "<string>",
"attachments": true,
"headers": true,
"group_by_message_id": true,
"strip_replies": true,
"enabled": true,
"success_count": 1,
"error_count": 1,
"errors_since_last_success": 1,
"last_request_at": "2023-11-07T05:31:56Z",
"secret": "<string>"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "A request with this idempotency key is already in progress"
}{
"message": "idempotency key was already used with a different request payload"
}{
"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.
Headers
Optional idempotency key for safe request retries. Must be a unique string for each logical request.
An identical request with a completed stored outcome returns the original status and body. An in-progress
execution returns 409, a changed method/path/body returns 422, and a released 5xx execution may run again.
Keys for non-secret responses expire after 24 hours. API-key create responses include a one-time secret_key,
so successful encrypted replay responses for those operations expire after 5 minutes.
255Path Parameters
Account ID
Body
Route name
255Webhook URL for the route
Recipient filter
255Whether to include attachments in webhooks
Whether to include headers in webhooks
Whether to group by message ID
Whether to strip reply content
Whether the route is enabled
Response
Route created successfully
Object type identifier
route Unique identifier for the route
When the route was created
When the route was last updated
Route name
Webhook URL for the route
Recipient filter; an empty string means no recipient filter
Whether to include attachments in route payload
Whether to include headers in route payload
Whether to group by message ID
Whether to strip reply content
Whether the route is enabled
Number of successful calls
x >= 0Number of unsuccessful calls
x >= 0Number of consecutive failed calls. Reset to zero by the next successful call.
x >= 0When the route was last called
Route signing secret. Returned only when the route is created.

