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()
campaignID := uuid.MustParse("11111111-1111-4111-8111-111111111111")
response, _, err := client.CampaignsAPI.GetCampaign(ctx, accountID, campaignID)
if err != nil {
log.Fatalf("Error getting campaign: %v", err)
}
fmt.Printf("%s is %s, sending to %d lists\n", response.Name, response.Status, len(response.ListIDs))
// A draft lists what keeps it from being sent.
for _, issue := range response.Issues {
fmt.Printf("%s: %s\n", issue.Code, issue.Message)
}
}
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const campaignId = "00000000-0000-4000-8000-000000000014";
const campaign = await client.campaigns.get(campaignId);
console.log("Campaign found.", { id: campaign.id, status: campaign.status, ready: campaign.ready });
curl --request GET \
--url https://api.ahasend.com/v2/accounts/{account_id}/campaigns/{campaign_id} \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.ahasend.com/v2/accounts/{account_id}/campaigns/{campaign_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}/campaigns/{campaign_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}/campaigns/{campaign_id}")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.ahasend.com/v2/accounts/{account_id}/campaigns/{campaign_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": "campaign",
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"name": "<string>",
"subject": "<string>",
"preheader": "<string>",
"from": {
"email": "noreply@example.com",
"name": "Example Corp"
},
"reply_to": "jsmith@example.com",
"status": "draft",
"status_reason": "<string>",
"send_at": "2023-11-07T05:31:56Z",
"send_resumes_at": "2023-11-07T05:31:56Z",
"finished_at": "2023-11-07T05:31:56Z",
"list_ids": [
"3c90c3cc-0d44-4b50-8888-8dd25736052a"
],
"editor": "advanced",
"content": {
"text_is_custom": true,
"mjml": "<string>",
"html": "<string>",
"text": "<string>"
},
"ready": true,
"issues": [
{
"code": "sender_missing",
"message": "<string>"
}
]
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}Get a Campaign via the API
Retrieve an AhaSend marketing campaign by ID with its status, sender, lists and design, and for a draft, the issues that stop it from being sent.
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()
campaignID := uuid.MustParse("11111111-1111-4111-8111-111111111111")
response, _, err := client.CampaignsAPI.GetCampaign(ctx, accountID, campaignID)
if err != nil {
log.Fatalf("Error getting campaign: %v", err)
}
fmt.Printf("%s is %s, sending to %d lists\n", response.Name, response.Status, len(response.ListIDs))
// A draft lists what keeps it from being sent.
for _, issue := range response.Issues {
fmt.Printf("%s: %s\n", issue.Code, issue.Message)
}
}
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
const campaignId = "00000000-0000-4000-8000-000000000014";
const campaign = await client.campaigns.get(campaignId);
console.log("Campaign found.", { id: campaign.id, status: campaign.status, ready: campaign.ready });
curl --request GET \
--url https://api.ahasend.com/v2/accounts/{account_id}/campaigns/{campaign_id} \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.ahasend.com/v2/accounts/{account_id}/campaigns/{campaign_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}/campaigns/{campaign_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}/campaigns/{campaign_id}")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.ahasend.com/v2/accounts/{account_id}/campaigns/{campaign_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": "campaign",
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"name": "<string>",
"subject": "<string>",
"preheader": "<string>",
"from": {
"email": "noreply@example.com",
"name": "Example Corp"
},
"reply_to": "jsmith@example.com",
"status": "draft",
"status_reason": "<string>",
"send_at": "2023-11-07T05:31:56Z",
"send_resumes_at": "2023-11-07T05:31:56Z",
"finished_at": "2023-11-07T05:31:56Z",
"list_ids": [
"3c90c3cc-0d44-4b50-8888-8dd25736052a"
],
"editor": "advanced",
"content": {
"text_is_custom": true,
"mjml": "<string>",
"html": "<string>",
"text": "<string>"
},
"ready": true,
"issues": [
{
"code": "sender_missing",
"message": "<string>"
}
]
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}{
"message": "Error message"
}campaigns:read.
readyandissuesapply to a draft.readyistruewhen the draft has no issues.issueslists what to fix, each with acodeand amessage. For a campaign that is not a draft, both arenull. See Issues.statusandstatus_reasonshow where the campaign is after a send. See Campaign status.list_idsholds the lists of the campaign in the order they were saved. A list that was deleted is left out.fromisnulluntil the campaign has a complete sender, and when the domain of the sender was deleted. When the sender has no name,from.nameis an empty string, so you can send the object back as it is.editorisnullwhile the campaign has no design.contentisnullwhile the campaign has no design, and while its design has no HTML and no text. For example, after a create witheditoralone,editoris set andcontentisnull.
Related Guides
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
Campaign
A campaign as List Campaigns returns it, without its lists, content and issues.
Object type identifier
campaign Campaign ID
When the campaign was created
When the campaign's own fields last changed
Campaign name, as it appears in the dashboard. Recipients do not see it.
The subject line. Null until one is set.
The preview text, which most inboxes show after the subject. Null until one is set.
The sender. Null until a complete sender is set, and when its domain was deleted. name is an empty string when the campaign has no sender name, so the object can be sent back as it is.
Show child attributes
Show child attributes
{
"email": "noreply@example.com",
"name": "Example Corp"
}
The reply-to address. Null when none is set.
Where the campaign is in its life. Only a draft can be changed or
deleted.
draft: being prepared.validating: scheduled, and its lists are being checked.waiting_for_review: held for a review before it sends.scheduled: accepted, waiting for its send time.sending: sending now.paused: sending stopped for now;status_reasonsays why.sent: every message was sent.canceled: stopped before it finished;status_reasonsays why.failed: could not be sent;status_reasonsays why.
draft, validating, waiting_for_review, scheduled, sending, paused, sent, canceled, failed Why the campaign is in its status, when there is a reason to give. Null otherwise.
When the campaign sends or sent, in UTC. Null until it is scheduled.
When a send that reached the account's daily marketing limit continues, in UTC. Null otherwise.
When the send ended, in UTC. Null until then.
The lists the campaign sends to, in the order they were saved. A list that was deleted is left out.
The editor of the campaign's design. Null while the campaign has no design.
advanced, simple, html The content of the campaign's design. Null while it has no design, or its design has neither HTML nor text.
Show child attributes
Show child attributes
Whether the draft has no issue, so it can be sent. Null unless the campaign is a draft.
The reasons the draft cannot be sent yet, in a fixed order; empty when it is ready. Null unless the campaign is a draft.
Show child attributes
Show child attributes

