package main
import (
"context"
"fmt"
"log"
"os"
"github.com/AhaSend/ahasend-go/api"
"github.com/google/uuid"
)
func main() {
client := api.NewAPIClient(api.WithAPIKey(os.Getenv("AHASEND_API_KEY")))
accountID := uuid.MustParse(os.Getenv("AHASEND_ACCOUNT_ID"))
ctx := context.Background()
webhookID := uuid.MustParse("c5a32c40-b351-439f-8230-779daed3e42c")
response, _, err := client.WebhooksAPI.GetWebhook(ctx, accountID, webhookID)
if err != nil {
log.Fatalf("Error getting webhook: %v", err)
}
fmt.Printf("%s -> %s (enabled: %t)\n", response.Name, response.URL, response.Enabled)
}import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const webhookId = "00000000-0000-4000-8000-000000000007";
const webhook = await client.webhooks.get(webhookId);
console.log("Webhook found.", { id: webhook.id, name: webhook.name });
curl --request GET \
--url https://api.ahasend.com/v2/accounts/{account_id}/webhooks/{webhook_id} \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.ahasend.com/v2/accounts/{account_id}/webhooks/{webhook_id}"
headers = {"Authorization": "Bearer <token>"}
response = requests.get(url, headers=headers)
print(response.text)<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.ahasend.com/v2/accounts/{account_id}/webhooks/{webhook_id}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}HttpResponse<String> response = Unirest.get("https://api.ahasend.com/v2/accounts/{account_id}/webhooks/{webhook_id}")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.ahasend.com/v2/accounts/{account_id}/webhooks/{webhook_id}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"object": "webhook",
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"name": "<string>",
"url": "<string>",
"enabled": true,
"on_reception": true,
"on_delivered": true,
"on_transient_error": true,
"on_failed": true,
"on_bounced": true,
"on_suppressed": true,
"on_opened": true,
"on_clicked": true,
"on_unsubscribed": true,
"on_complained": true,
"on_suppression_created": true,
"on_suppression_deleted": true,
"on_dns_error": true,
"on_contact_created": true,
"on_contact_updated": true,
"on_contact_deleted": true,
"on_contact_added_to_list": true,
"on_contact_removed_from_list": true,
"on_contact_subscribed": true,
"on_contact_unsubscribed": true,
"on_contact_complained": true,
"origins": [
"recipient"
],
"scope": "global",
"domains": [
"<string>"
],
"success_count": 1,
"error_count": 1,
"errors_since_last_success": 1,
"last_request_at": "2023-11-07T05:31:56Z"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}Get a Webhook via the API
Retrieve a single AhaSend webhook by ID with the API, including its URL, subscribed event types, enabled status and domain scope.
package main
import (
"context"
"fmt"
"log"
"os"
"github.com/AhaSend/ahasend-go/api"
"github.com/google/uuid"
)
func main() {
client := api.NewAPIClient(api.WithAPIKey(os.Getenv("AHASEND_API_KEY")))
accountID := uuid.MustParse(os.Getenv("AHASEND_ACCOUNT_ID"))
ctx := context.Background()
webhookID := uuid.MustParse("c5a32c40-b351-439f-8230-779daed3e42c")
response, _, err := client.WebhooksAPI.GetWebhook(ctx, accountID, webhookID)
if err != nil {
log.Fatalf("Error getting webhook: %v", err)
}
fmt.Printf("%s -> %s (enabled: %t)\n", response.Name, response.URL, response.Enabled)
}import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const webhookId = "00000000-0000-4000-8000-000000000007";
const webhook = await client.webhooks.get(webhookId);
console.log("Webhook found.", { id: webhook.id, name: webhook.name });
curl --request GET \
--url https://api.ahasend.com/v2/accounts/{account_id}/webhooks/{webhook_id} \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.ahasend.com/v2/accounts/{account_id}/webhooks/{webhook_id}"
headers = {"Authorization": "Bearer <token>"}
response = requests.get(url, headers=headers)
print(response.text)<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.ahasend.com/v2/accounts/{account_id}/webhooks/{webhook_id}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}HttpResponse<String> response = Unirest.get("https://api.ahasend.com/v2/accounts/{account_id}/webhooks/{webhook_id}")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.ahasend.com/v2/accounts/{account_id}/webhooks/{webhook_id}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"object": "webhook",
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"name": "<string>",
"url": "<string>",
"enabled": true,
"on_reception": true,
"on_delivered": true,
"on_transient_error": true,
"on_failed": true,
"on_bounced": true,
"on_suppressed": true,
"on_opened": true,
"on_clicked": true,
"on_unsubscribed": true,
"on_complained": true,
"on_suppression_created": true,
"on_suppression_deleted": true,
"on_dns_error": true,
"on_contact_created": true,
"on_contact_updated": true,
"on_contact_deleted": true,
"on_contact_added_to_list": true,
"on_contact_removed_from_list": true,
"on_contact_subscribed": true,
"on_contact_unsubscribed": true,
"on_contact_complained": true,
"origins": [
"recipient"
],
"scope": "global",
"domains": [
"<string>"
],
"success_count": 1,
"error_count": 1,
"errors_since_last_success": 1,
"last_request_at": "2023-11-07T05:31:56Z"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}Related Guides
- API authentication, Permission scopes, Webhook setup.
- Event reference, Webhook CLI, Local webhook testing.
- Signature verification, Retry policy, API errors.
- API rate limits.
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.
Response
Webhook details
Object type identifier
webhook Unique identifier for the webhook
When the webhook was created
When the webhook was last updated
Webhook name
Webhook URL
Whether the webhook is enabled
Trigger on message reception
Trigger on message delivery
Trigger on transient errors
Trigger on permanent failures
Trigger on bounces
Trigger on suppressions
Trigger on opens
Trigger on clicks
Trigger on unsubscribes
Trigger on spam complaints
Trigger on suppression creation
Trigger on suppression deletion
Trigger on DNS errors
Trigger on contact creation
Trigger on contact updates
Trigger on contact deletion
Trigger when a contact is added to a list
Trigger when a contact is removed from a list
Trigger when a contact subscribes
Trigger when a contact unsubscribes
Trigger when a contact reports spam
The origins of the contact and suppression events that the webhook
gets, or null for every origin. Message events and
domain.dns_error have no origin, and the webhook always gets them.
Who made a change that a contact or suppression event reports:
recipient for the contact or recipient, through an unsubscribe link,
a one-click unsubscribe, or a spam complaint; api for you, through
the AhaSend API; dashboard for you, through the AhaSend dashboard;
system for AhaSend, for example after a bounce, an expired message or
an email validation, or when AhaSend support makes the change.
recipient, api, dashboard, system Webhook scope
global, scoped Domains this webhook applies to. Always present; global webhooks return an empty array.
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 webhook was last called

