eusend

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 12 Imported by: 0

README

eusend-go

Official Go SDK for the Eusend API — the EU-native transactional email platform.

Its shape mirrors resend-go, so migrating from Resend is largely a resendeusend rename.

  • NewClient + service methodsclient.Emails.Send(...), with WithContext variants.
  • Zero dependencies — standard library only.
  • Concurrency-safe — create one *Client and share it.
go get github.com/eusend-dev/eusend-go

Requires Go 1.21+.


Getting started

package main

import (
	"fmt"
	"log"

	eusend "github.com/eusend-dev/eusend-go"
)

func main() {
	client := eusend.NewClient("eu_live_...") // or NewClient("") to read EUSEND_API_KEY

	sent, err := client.Emails.Send(&eusend.SendEmailRequest{
		// From accepts a bare email or a display-name form: "Acme <you@yourdomain.com>"
		From:    "Acme <you@yourdomain.com>",
		To:      []string{"user@example.com"},
		Subject: "Hello",
		Html:    "<p>Hello world</p>",
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(sent.Id) // 9a8b7c6d-... (UUID)
}

Every method has a WithContext variant that takes a context.Context as its first argument (e.g. client.Emails.SendWithContext(ctx, params)). The context-free forms use context.Background().

Optional pointer fields (*bool, *string) have helpers: eusend.Bool(true), eusend.String("x").


Emails

Send

From and To are required; provide at least one of Html, Text, or TemplateId.

Field Type Notes
From string Verified domain; bare or display-name form.
To Cc Bcc ReplyTo []string Max 50 each.
Subject string
Html / Text string
TemplateId string Saved template.
Variables map[string]any Template substitutions (HTML-escaped).
Headers map[string]string No line breaks in names or values.
TrackOpens / TrackClicks *bool Default true; eusend.Bool(false) to disable.
Attachments []*Attachment Up to 20, 10 MB combined.
ScheduledAt string Future send, ≤ 30 days.
Attachments

Provide Content (raw bytes, base64-encoded on the wire) or Path (a public URL fetched at send time). Set ContentId for an inline <img src="cid:...">.

pdf, _ := os.ReadFile("invoice.pdf")

client.Emails.Send(&eusend.SendEmailRequest{
	From:    "you@yourdomain.com",
	To:      []string{"user@example.com"},
	Subject: "Your invoice",
	Html:    "<p>Attached.</p>",
	Attachments: []*eusend.Attachment{
		{Filename: "invoice.pdf", Content: pdf, ContentType: "application/pdf"},
	},
})
Idempotent sends
client.Emails.SendWithOptions(ctx, params, &eusend.SendEmailOptions{
	IdempotencyKey: "receipt-" + orderID,
})

Retrying with the same key never sends a duplicate and returns the original ID.

Scheduled sends

ScheduledAt accepts an ISO 8601 string or natural language ("in 1 hour", "tomorrow at 9am"), parsed server-side in UTC.

sent, _ := client.Emails.Send(&eusend.SendEmailRequest{
	From: "you@yourdomain.com", To: []string{"user@example.com"},
	Subject: "Reminder", Html: "<p>Soon.</p>",
	ScheduledAt: "in 1 hour",
})

client.Emails.Update(&eusend.UpdateEmailRequest{Id: sent.Id, ScheduledAt: "in 2 hours"})
client.Emails.Cancel(sent.Id)
Batch

Up to 100 emails in one request. Attachments and scheduling are stripped (not supported on the batch endpoint). Results map positionally to the input: queued items carry Id, rejected items carry Error and Code.

res, _ := client.Batch.Send([]*eusend.SendEmailRequest{
	{From: "you@yourdomain.com", To: []string{"alice@example.com"}, Subject: "Hi", Html: "<p>Hi</p>"},
	{From: "you@yourdomain.com", To: []string{"bob@example.com"},   Subject: "Hi", Html: "<p>Hi</p>"},
})
for _, r := range res.Data {
	if r.Id != "" {
		fmt.Println("queued", r.Id)
	} else {
		fmt.Printf("failed: %s (%s)\n", r.Error, r.Code)
	}
}
Retrieve & list
email, _ := client.Emails.Get("9a8b7c6d-...")
fmt.Println(email.Status, email.Events[0].Type)

page, _ := client.Emails.List(&eusend.ListEmailsOptions{Limit: 20, Status: "delivered"})
for _, e := range page.Data {
	fmt.Println(e.Id, e.Subject)
}
if page.NextCursor != "" {
	page, _ = client.Emails.List(&eusend.ListEmailsOptions{Cursor: page.NextCursor})
}

Statuses: queued scheduled sending sent delivered bounced complained suppressed failed.


Domains

created, _ := client.Domains.Create(&eusend.CreateDomainRequest{Name: "yourdomain.com"})
fmt.Println(created.Dkim.Name, created.Dkim.Value) // DNS records to add
fmt.Println(created.Spf, created.Dmarc)

client.Domains.Verify(created.Id) // after publishing the DNS records
client.Domains.List()
client.Domains.Get(created.Id)
client.Domains.Remove(created.Id)

API keys

key, _ := client.ApiKeys.Create(&eusend.CreateApiKeyRequest{Name: "Production"})
fmt.Println(key.Key) // eu_live_... — returned only once

client.ApiKeys.Create(&eusend.CreateApiKeyRequest{Name: "Sandbox", TestMode: true}) // eu_test_... key
client.ApiKeys.List()                                                               // prefixes only
client.ApiKeys.Remove(key.Id)

Emails sent with a test key are accepted and tracked but never delivered.


Audiences & contacts

Contact operations are grouped under Audiences (they live under a specific audience).

audience, _ := client.Audiences.Create(&eusend.CreateAudienceRequest{Name: "Newsletter"})

client.Audiences.CreateContact(audience.Id, &eusend.CreateContactRequest{
	Email: "user@example.com", FirstName: "Jane",
})

// Bulk upsert (up to 1,000)
client.Audiences.BatchCreateContacts(audience.Id, []*eusend.CreateContactRequest{
	{Email: "alice@example.com", FirstName: "Alice"},
	{Email: "bob@example.com", FirstName: "Bob"},
})

page, _ := client.Audiences.ListContacts(audience.Id, &eusend.ListContactsOptions{
	Subscribed: eusend.Bool(true), Search: "gmail.com",
})
contact := page.Data[0]

client.Audiences.UpdateContact(audience.Id, contact.Id, &eusend.UpdateContactRequest{
	Unsubscribed: eusend.Bool(true),
})
client.Audiences.GetContact(audience.Id, contact.Id)
client.Audiences.RemoveContact(audience.Id, contact.Id)

client.Audiences.List()
client.Audiences.Remove(audience.Id)

Templates

{{variable}} placeholders are substituted at send time; values are HTML-escaped.

tpl, _ := client.Templates.Create(&eusend.CreateTemplateRequest{
	Name:    "Welcome email",
	Subject: "Welcome, {{name}}!",
	Html:    "<h1>Hi {{name}}</h1><p>Welcome to {{product}}.</p>",
})

client.Emails.Send(&eusend.SendEmailRequest{
	From: "you@yourdomain.com", To: []string{"user@example.com"},
	TemplateId: tpl.Id,
	Variables:  map[string]any{"name": "Jane", "product": "Acme"},
})

client.Templates.List()
client.Templates.Get(tpl.Id)
client.Templates.Update(tpl.Id, &eusend.UpdateTemplateRequest{Subject: eusend.String("New subject")})
client.Templates.Remove(tpl.Id)

Webhooks

hook, _ := client.Webhooks.Create(&eusend.CreateWebhookRequest{
	Url:    "https://yourapp.com/webhooks/eusend",
	Events: []string{"email.delivered", "email.bounced", "email.complained"}, // or []string{"*"}
})
fmt.Println(hook.Secret) // signing secret — returned only once

client.Webhooks.List()
client.Webhooks.Get(hook.Id) // includes recent deliveries
client.Webhooks.Update(hook.Id, &eusend.UpdateWebhookRequest{Events: []string{"email.bounced"}})
client.Webhooks.Remove(hook.Id)

Events: email.sent email.delivered email.bounced email.complained email.opened email.clicked. The endpoint must be a public http(s) URL returning 2xx directly (redirects count as failures).

Verifying signatures

Every delivery is signed with HMAC-SHA256 over {webhook-id}.{webhook-timestamp}.{body}:

import (
	"crypto/hmac"
	"crypto/sha256"
	"encoding/base64"
)

func verify(r *http.Request, body []byte, secret string) bool {
	signed := r.Header.Get("webhook-id") + "." + r.Header.Get("webhook-timestamp") + "." + string(body)
	mac := hmac.New(sha256.New, []byte(secret))
	mac.Write([]byte(signed))
	expected := "v1," + base64.StdEncoding.EncodeToString(mac.Sum(nil))
	return hmac.Equal([]byte(r.Header.Get("webhook-signature")), []byte(expected))
}

Broadcasts

Send one email to every contact in an audience. {{first_name}}, {{last_name}}, {{full_name}}, and {{email}} are available per recipient, and RFC 8058 one-click unsubscribe headers are added automatically.

bc, _ := client.Broadcasts.Create(&eusend.CreateBroadcastRequest{
	Name:       "May newsletter",
	AudienceId: audience.Id,
	From:       "Sivert <hello@yourdomain.com>",
	Subject:    "May update",
	Html:       "<p>Hi {{first_name}}, your monthly update is here...</p>",
})

client.Broadcasts.Send(bc.Id, nil)                                          // send now
client.Broadcasts.Send(bc.Id, &eusend.SendBroadcastRequest{ScheduledAt: "2026-06-01T09:00:00Z"}) // or schedule
client.Broadcasts.Cancel(bc.Id)

client.Broadcasts.List()
client.Broadcasts.Get(bc.Id) // includes delivery stats
client.Broadcasts.Update(bc.Id, &eusend.UpdateBroadcastRequest{Subject: eusend.String("Updated")})
client.Broadcasts.Remove(bc.Id)

Calling Send on a paused broadcast resumes it from where it stopped.


Error handling

Every method returns (result, error). Any non-2xx response, and any network failure, is an *eusend.Error:

sent, err := client.Emails.Send(params)
if err != nil {
	var apiErr *eusend.Error
	if errors.As(err, &apiErr) {
		fmt.Println(apiErr.Code)       // "MONTHLY_LIMIT_EXCEEDED"
		fmt.Println(apiErr.Message)    // "Monthly send limit exceeded"
		fmt.Println(apiErr.StatusCode) // 429 (0 for a network failure)

		if apiErr.Code == eusend.CodeMonthlyLimitExceeded {
			// back off and retry later
		}
	}
	return
}

On a 429, apiErr.RetryAfter, RateLimitReset, and RateLimitRemaining are populated from the response headers.

Code constant Wire value Status
CodeUnauthorized UNAUTHORIZED 401
CodeForbidden FORBIDDEN 403
CodeNotFound NOT_FOUND 404
CodeValidationError VALIDATION_ERROR 400
CodeBadRequest BAD_REQUEST 400
CodeConflict CONFLICT 409
CodeRateLimited RATE_LIMITED 429
CodeMonthlyLimitExceeded MONTHLY_LIMIT_EXCEEDED 429
CodeDailyLimitExceeded DAILY_LIMIT_EXCEEDED 429
CodePlanLimitExceeded PLAN_LIMIT_EXCEEDED 403
CodeDomainNotVerified DOMAIN_NOT_VERIFIED 403
CodeSendingSuspended SENDING_SUSPENDED 403
CodeAllSuppressed ALL_SUPPRESSED 422
CodeServicePaused SERVICE_PAUSED 503
CodeInternalError INTERNAL_ERROR 500
CodeApplicationError application_error — (network failure)

Configuration

// Custom http.Client (timeouts, proxies, ...):
client := eusend.NewCustomClient(&http.Client{Timeout: 60 * time.Second}, "eu_live_...")

// Override the base URL (e.g. for testing) after construction:
client.BaseURL, _ = url.Parse("https://api.eusend.dev/")

Documentation

Overview

Package eusend is the official Go SDK for the Eusend API — the EU-native transactional email platform. Its shape mirrors github.com/resend/resend-go, so migrating from Resend is largely a `resend` → `eusend` rename.

client := eusend.NewClient("eu_live_...")
sent, err := client.Emails.Send(&eusend.SendEmailRequest{
    From:    "Acme <you@yourdomain.com>",
    To:      []string{"user@example.com"},
    Subject: "Hello",
    Html:    "<p>Hello world</p>",
})

Index

Constants

View Source
const (
	CodeUnauthorized         = "UNAUTHORIZED"
	CodeForbidden            = "FORBIDDEN"
	CodeNotFound             = "NOT_FOUND"
	CodeValidationError      = "VALIDATION_ERROR"
	CodeBadRequest           = "BAD_REQUEST"
	CodeConflict             = "CONFLICT"
	CodeRateLimited          = "RATE_LIMITED"
	CodeMonthlyLimitExceeded = "MONTHLY_LIMIT_EXCEEDED"
	CodeDailyLimitExceeded   = "DAILY_LIMIT_EXCEEDED"
	CodePlanLimitExceeded    = "PLAN_LIMIT_EXCEEDED"
	CodeDomainNotVerified    = "DOMAIN_NOT_VERIFIED"
	CodeSendingSuspended     = "SENDING_SUSPENDED"
	CodeAllSuppressed        = "ALL_SUPPRESSED"
	CodeAttachmentStorageErr = "ATTACHMENT_STORAGE_ERROR"
	CodeServicePaused        = "SERVICE_PAUSED"
	CodeInternalError        = "INTERNAL_ERROR"
	CodeApplicationError     = "application_error"
)

Error codes returned by the API. CodeApplicationError is SDK-only and signals that the request never reached the server (network failure, DNS, timeout).

Variables

View Source
var (
	ErrFailedToCreateRequest = errors.New("[ERROR]: Failed to create request")
)

Sentinel errors returned when a request object cannot be constructed.

Functions

func Bool

func Bool(v bool) *bool

Bool returns a pointer to v — a convenience for optional *bool fields.

func String

func String(v string) *string

String returns a pointer to v — a convenience for optional *string fields.

Types

type ApiKey

type ApiKey struct {
	Id         string `json:"id"`
	Name       string `json:"name"`
	Prefix     string `json:"prefix"`
	TestMode   bool   `json:"test_mode"`
	CreatedAt  string `json:"created_at"`
	LastUsedAt string `json:"last_used_at"`
}

ApiKey is a row from ApiKeys.List. The full key is never returned after creation.

type ApiKeysSvc

type ApiKeysSvc interface {
	Create(params *CreateApiKeyRequest) (*CreateApiKeyResponse, error)
	CreateWithContext(ctx context.Context, params *CreateApiKeyRequest) (*CreateApiKeyResponse, error)
	List() ([]ApiKey, error)
	ListWithContext(ctx context.Context) ([]ApiKey, error)
	Remove(apiKeyId string) (*GenericResponse, error)
	RemoveWithContext(ctx context.Context, apiKeyId string) (*GenericResponse, error)
}

ApiKeysSvc is the /api-keys API.

type ApiKeysSvcImpl

type ApiKeysSvcImpl struct {
	// contains filtered or unexported fields
}

func (*ApiKeysSvcImpl) Create

func (*ApiKeysSvcImpl) CreateWithContext

func (s *ApiKeysSvcImpl) CreateWithContext(ctx context.Context, params *CreateApiKeyRequest) (*CreateApiKeyResponse, error)

func (*ApiKeysSvcImpl) List

func (s *ApiKeysSvcImpl) List() ([]ApiKey, error)

func (*ApiKeysSvcImpl) ListWithContext

func (s *ApiKeysSvcImpl) ListWithContext(ctx context.Context) ([]ApiKey, error)

func (*ApiKeysSvcImpl) Remove

func (s *ApiKeysSvcImpl) Remove(apiKeyId string) (*GenericResponse, error)

func (*ApiKeysSvcImpl) RemoveWithContext

func (s *ApiKeysSvcImpl) RemoveWithContext(ctx context.Context, apiKeyId string) (*GenericResponse, error)

type Attachment

type Attachment struct {
	Content     []byte `json:"content,omitempty"`
	Filename    string `json:"filename,omitempty"`
	Path        string `json:"path,omitempty"`
	ContentType string `json:"content_type,omitempty"`
	ContentId   string `json:"content_id,omitempty"`
}

Attachment is a file attached to an email. Provide either Content (raw bytes, base64-encoded on the wire) or Path (a public URL fetched at send time). Set ContentId for an inline attachment referenced from HTML with <img src="cid:...">.

type Audience

type Audience struct {
	Id             string `json:"id"`
	Name           string `json:"name"`
	OrganizationId string `json:"organizationId"`
	CreatedAt      string `json:"createdAt"`
	UpdatedAt      string `json:"updatedAt"`
}

Audience is returned by Audiences.Create.

type AudienceListItem

type AudienceListItem struct {
	Id           string `json:"id"`
	Name         string `json:"name"`
	CreatedAt    string `json:"createdAt"`
	ContactCount int    `json:"contactCount"`
}

AudienceListItem is a row from Audiences.List.

type AudiencesSvc

type AudiencesSvc interface {
	Create(params *CreateAudienceRequest) (*Audience, error)
	CreateWithContext(ctx context.Context, params *CreateAudienceRequest) (*Audience, error)
	List() ([]AudienceListItem, error)
	ListWithContext(ctx context.Context) ([]AudienceListItem, error)
	Remove(audienceId string) (*GenericResponse, error)
	RemoveWithContext(ctx context.Context, audienceId string) (*GenericResponse, error)

	CreateContact(audienceId string, params *CreateContactRequest) (*Contact, error)
	CreateContactWithContext(ctx context.Context, audienceId string, params *CreateContactRequest) (*Contact, error)
	BatchCreateContacts(audienceId string, contacts []*CreateContactRequest) (*BatchCreateContactsResponse, error)
	BatchCreateContactsWithContext(ctx context.Context, audienceId string, contacts []*CreateContactRequest) (*BatchCreateContactsResponse, error)
	ListContacts(audienceId string, options *ListContactsOptions) (*ListContactsResponse, error)
	ListContactsWithContext(ctx context.Context, audienceId string, options *ListContactsOptions) (*ListContactsResponse, error)
	GetContact(audienceId, contactId string) (*Contact, error)
	GetContactWithContext(ctx context.Context, audienceId, contactId string) (*Contact, error)
	UpdateContact(audienceId, contactId string, params *UpdateContactRequest) (*Contact, error)
	UpdateContactWithContext(ctx context.Context, audienceId, contactId string, params *UpdateContactRequest) (*Contact, error)
	RemoveContact(audienceId, contactId string) (*GenericResponse, error)
	RemoveContactWithContext(ctx context.Context, audienceId, contactId string) (*GenericResponse, error)
}

AudiencesSvc is the /audiences API, including nested contact operations.

type AudiencesSvcImpl

type AudiencesSvcImpl struct {
	// contains filtered or unexported fields
}

func (*AudiencesSvcImpl) BatchCreateContacts

func (s *AudiencesSvcImpl) BatchCreateContacts(audienceId string, contacts []*CreateContactRequest) (*BatchCreateContactsResponse, error)

func (*AudiencesSvcImpl) BatchCreateContactsWithContext

func (s *AudiencesSvcImpl) BatchCreateContactsWithContext(ctx context.Context, audienceId string, contacts []*CreateContactRequest) (*BatchCreateContactsResponse, error)

func (*AudiencesSvcImpl) Create

func (s *AudiencesSvcImpl) Create(params *CreateAudienceRequest) (*Audience, error)

func (*AudiencesSvcImpl) CreateContact

func (s *AudiencesSvcImpl) CreateContact(audienceId string, params *CreateContactRequest) (*Contact, error)

func (*AudiencesSvcImpl) CreateContactWithContext

func (s *AudiencesSvcImpl) CreateContactWithContext(ctx context.Context, audienceId string, params *CreateContactRequest) (*Contact, error)

func (*AudiencesSvcImpl) CreateWithContext

func (s *AudiencesSvcImpl) CreateWithContext(ctx context.Context, params *CreateAudienceRequest) (*Audience, error)

func (*AudiencesSvcImpl) GetContact

func (s *AudiencesSvcImpl) GetContact(audienceId, contactId string) (*Contact, error)

func (*AudiencesSvcImpl) GetContactWithContext

func (s *AudiencesSvcImpl) GetContactWithContext(ctx context.Context, audienceId, contactId string) (*Contact, error)

func (*AudiencesSvcImpl) List

func (s *AudiencesSvcImpl) List() ([]AudienceListItem, error)

func (*AudiencesSvcImpl) ListContacts

func (s *AudiencesSvcImpl) ListContacts(audienceId string, options *ListContactsOptions) (*ListContactsResponse, error)

func (*AudiencesSvcImpl) ListContactsWithContext

func (s *AudiencesSvcImpl) ListContactsWithContext(ctx context.Context, audienceId string, options *ListContactsOptions) (*ListContactsResponse, error)

func (*AudiencesSvcImpl) ListWithContext

func (s *AudiencesSvcImpl) ListWithContext(ctx context.Context) ([]AudienceListItem, error)

func (*AudiencesSvcImpl) Remove

func (s *AudiencesSvcImpl) Remove(audienceId string) (*GenericResponse, error)

func (*AudiencesSvcImpl) RemoveContact

func (s *AudiencesSvcImpl) RemoveContact(audienceId, contactId string) (*GenericResponse, error)

func (*AudiencesSvcImpl) RemoveContactWithContext

func (s *AudiencesSvcImpl) RemoveContactWithContext(ctx context.Context, audienceId, contactId string) (*GenericResponse, error)

func (*AudiencesSvcImpl) RemoveWithContext

func (s *AudiencesSvcImpl) RemoveWithContext(ctx context.Context, audienceId string) (*GenericResponse, error)

func (*AudiencesSvcImpl) UpdateContact

func (s *AudiencesSvcImpl) UpdateContact(audienceId, contactId string, params *UpdateContactRequest) (*Contact, error)

func (*AudiencesSvcImpl) UpdateContactWithContext

func (s *AudiencesSvcImpl) UpdateContactWithContext(ctx context.Context, audienceId, contactId string, params *UpdateContactRequest) (*Contact, error)

type BatchCreateContactsResponse

type BatchCreateContactsResponse struct {
	Count int `json:"count"`
}

BatchCreateContactsResponse reports how many contacts were written.

type BatchEmailResponse

type BatchEmailResponse struct {
	Data []BatchItemResult `json:"data"`
}

BatchEmailResponse is the response from Batch.Send.

type BatchItemResult

type BatchItemResult struct {
	Id    string `json:"id,omitempty"`
	Error string `json:"error,omitempty"`
	Code  string `json:"code,omitempty"`
}

BatchItemResult is one outcome of a batch send, positionally mapped to the input slice: result[i] describes params[i]. Queued items carry Id; rejected items carry Error and Code. Branch on `if result.Id != ""`.

type BatchSvc

type BatchSvc interface {
	Send(params []*SendEmailRequest) (*BatchEmailResponse, error)
	SendWithContext(ctx context.Context, params []*SendEmailRequest) (*BatchEmailResponse, error)
}

BatchSvc is the /emails/batch API.

type BatchSvcImpl

type BatchSvcImpl struct {
	// contains filtered or unexported fields
}

func (*BatchSvcImpl) Send

func (s *BatchSvcImpl) Send(params []*SendEmailRequest) (*BatchEmailResponse, error)

Send sends up to 100 emails in a single request. Attachments and scheduling are not supported on the batch endpoint and are stripped from each item — send those individually via Emails.Send. A failed item never fails the whole batch; branch on the presence of Id per returned result.

func (*BatchSvcImpl) SendWithContext

func (s *BatchSvcImpl) SendWithContext(ctx context.Context, params []*SendEmailRequest) (*BatchEmailResponse, error)

type Broadcast

type Broadcast struct {
	Id                string            `json:"id"`
	Name              string            `json:"name"`
	Status            string            `json:"status"`
	AudienceId        string            `json:"audienceId"`
	FromAddress       string            `json:"fromAddress"`
	Subject           string            `json:"subject"`
	Html              string            `json:"html"`
	TemplateId        string            `json:"templateId"`
	TemplateVariables map[string]string `json:"templateVariables"`
	ScheduledAt       string            `json:"scheduledAt"`
	RecipientCount    int               `json:"recipientCount"`
	SentCount         int               `json:"sentCount"`
	StartedAt         string            `json:"startedAt"`
	CompletedAt       string            `json:"completedAt"`
	Stats             map[string]int    `json:"stats"`
	CreatedAt         string            `json:"createdAt"`
	UpdatedAt         string            `json:"updatedAt"`
}

Broadcast is returned by Broadcasts.Create/Update/Cancel and (with stats) Get.

type BroadcastListItem

type BroadcastListItem struct {
	Id             string `json:"id"`
	Name           string `json:"name"`
	Status         string `json:"status"`
	AudienceId     string `json:"audienceId"`
	FromAddress    string `json:"fromAddress"`
	Subject        string `json:"subject"`
	RecipientCount int    `json:"recipientCount"`
	SentCount      int    `json:"sentCount"`
	ScheduledAt    string `json:"scheduledAt"`
	StartedAt      string `json:"startedAt"`
	CompletedAt    string `json:"completedAt"`
	CreatedAt      string `json:"createdAt"`
	AudienceName   string `json:"audienceName"`
}

BroadcastListItem is a row from Broadcasts.List.

type BroadcastsSvc

type BroadcastsSvc interface {
	Create(params *CreateBroadcastRequest) (*Broadcast, error)
	CreateWithContext(ctx context.Context, params *CreateBroadcastRequest) (*Broadcast, error)
	List() ([]BroadcastListItem, error)
	ListWithContext(ctx context.Context) ([]BroadcastListItem, error)
	Get(broadcastId string) (*Broadcast, error)
	GetWithContext(ctx context.Context, broadcastId string) (*Broadcast, error)
	Update(broadcastId string, params *UpdateBroadcastRequest) (*Broadcast, error)
	UpdateWithContext(ctx context.Context, broadcastId string, params *UpdateBroadcastRequest) (*Broadcast, error)
	Send(broadcastId string, params *SendBroadcastRequest) (*SendBroadcastResponse, error)
	SendWithContext(ctx context.Context, broadcastId string, params *SendBroadcastRequest) (*SendBroadcastResponse, error)
	Cancel(broadcastId string) (*Broadcast, error)
	CancelWithContext(ctx context.Context, broadcastId string) (*Broadcast, error)
	Remove(broadcastId string) (*GenericResponse, error)
	RemoveWithContext(ctx context.Context, broadcastId string) (*GenericResponse, error)
}

BroadcastsSvc is the /broadcasts API.

type BroadcastsSvcImpl

type BroadcastsSvcImpl struct {
	// contains filtered or unexported fields
}

func (*BroadcastsSvcImpl) Cancel

func (s *BroadcastsSvcImpl) Cancel(broadcastId string) (*Broadcast, error)

func (*BroadcastsSvcImpl) CancelWithContext

func (s *BroadcastsSvcImpl) CancelWithContext(ctx context.Context, broadcastId string) (*Broadcast, error)

func (*BroadcastsSvcImpl) Create

func (*BroadcastsSvcImpl) CreateWithContext

func (s *BroadcastsSvcImpl) CreateWithContext(ctx context.Context, params *CreateBroadcastRequest) (*Broadcast, error)

func (*BroadcastsSvcImpl) Get

func (s *BroadcastsSvcImpl) Get(broadcastId string) (*Broadcast, error)

func (*BroadcastsSvcImpl) GetWithContext

func (s *BroadcastsSvcImpl) GetWithContext(ctx context.Context, broadcastId string) (*Broadcast, error)

func (*BroadcastsSvcImpl) List

func (s *BroadcastsSvcImpl) List() ([]BroadcastListItem, error)

func (*BroadcastsSvcImpl) ListWithContext

func (s *BroadcastsSvcImpl) ListWithContext(ctx context.Context) ([]BroadcastListItem, error)

func (*BroadcastsSvcImpl) Remove

func (s *BroadcastsSvcImpl) Remove(broadcastId string) (*GenericResponse, error)

func (*BroadcastsSvcImpl) RemoveWithContext

func (s *BroadcastsSvcImpl) RemoveWithContext(ctx context.Context, broadcastId string) (*GenericResponse, error)

func (*BroadcastsSvcImpl) Send

func (s *BroadcastsSvcImpl) Send(broadcastId string, params *SendBroadcastRequest) (*SendBroadcastResponse, error)

Send sends a broadcast immediately, or schedules it when params.ScheduledAt is set. Calling Send on a paused broadcast resumes it from where it stopped.

func (*BroadcastsSvcImpl) SendWithContext

func (s *BroadcastsSvcImpl) SendWithContext(ctx context.Context, broadcastId string, params *SendBroadcastRequest) (*SendBroadcastResponse, error)

func (*BroadcastsSvcImpl) Update

func (s *BroadcastsSvcImpl) Update(broadcastId string, params *UpdateBroadcastRequest) (*Broadcast, error)

func (*BroadcastsSvcImpl) UpdateWithContext

func (s *BroadcastsSvcImpl) UpdateWithContext(ctx context.Context, broadcastId string, params *UpdateBroadcastRequest) (*Broadcast, error)

type CancelScheduledEmailResponse

type CancelScheduledEmailResponse struct {
	Id     string `json:"id"`
	Status string `json:"status"`
}

CancelScheduledEmailResponse is the response from Emails.Cancel.

type Client

type Client struct {
	ApiKey    string
	BaseURL   *url.URL
	UserAgent string

	Emails     EmailsSvc
	Batch      BatchSvc
	ApiKeys    ApiKeysSvc
	Domains    DomainsSvc
	Audiences  AudiencesSvc
	Templates  TemplatesSvc
	Webhooks   WebhooksSvc
	Broadcasts BroadcastsSvc
	// contains filtered or unexported fields
}

Client is the entry point to the Eusend API. Create one with NewClient and share it across goroutines — it is safe for concurrent use.

func NewClient

func NewClient(apiKey string) *Client

NewClient creates a Client with the given API key. If apiKey is empty, the EUSEND_API_KEY environment variable is used.

func NewCustomClient

func NewCustomClient(httpClient *http.Client, apiKey string) *Client

NewCustomClient creates a Client with a custom *http.Client (for custom timeouts, proxies, etc.).

func (*Client) NewRequest

func (c *Client) NewRequest(ctx context.Context, method, path string, params any) (*http.Request, error)

NewRequest builds an *http.Request against the API, JSON-encoding params when non-nil.

func (*Client) NewRequestWithOptions

func (c *Client) NewRequestWithOptions(ctx context.Context, method, path string, params any, options Options) (*http.Request, error)

NewRequestWithOptions is NewRequest plus per-call options such as an idempotency key.

func (*Client) Perform

func (c *Client) Perform(req *http.Request, ret any) (*http.Response, error)

Perform sends req and decodes a 2xx JSON body into ret (which may be nil). Non-2xx responses are converted to *Error via handleError.

type Contact

type Contact struct {
	Id             string `json:"id"`
	AudienceId     string `json:"audienceId"`
	Email          string `json:"email"`
	FirstName      string `json:"firstName"`
	LastName       string `json:"lastName"`
	Status         string `json:"status"`
	UnsubscribedAt string `json:"unsubscribedAt"`
	CreatedAt      string `json:"createdAt"`
	UpdatedAt      string `json:"updatedAt"`
}

Contact is a member of an audience.

type CreateApiKeyRequest

type CreateApiKeyRequest struct {
	Name string `json:"name"`
	// TestMode issues a sandbox key. Emails sent with a test key are accepted
	// and tracked but never delivered.
	TestMode bool `json:"test_mode"`
}

CreateApiKeyRequest is the request object for ApiKeys.Create.

type CreateApiKeyResponse

type CreateApiKeyResponse struct {
	Id        string `json:"id"`
	Name      string `json:"name"`
	Key       string `json:"key"`
	Prefix    string `json:"prefix"`
	TestMode  bool   `json:"test_mode"`
	CreatedAt string `json:"created_at"`
}

CreateApiKeyResponse is returned by ApiKeys.Create. Key holds the full secret and is returned only once — store it securely.

type CreateAudienceRequest

type CreateAudienceRequest struct {
	Name string `json:"name"`
}

CreateAudienceRequest is the request object for Audiences.Create.

type CreateBroadcastRequest

type CreateBroadcastRequest struct {
	Name              string            `json:"name"`
	AudienceId        string            `json:"audience_id"`
	From              string            `json:"from"`
	Subject           string            `json:"subject"`
	Html              string            `json:"html,omitempty"`
	TemplateId        string            `json:"template_id,omitempty"`
	TemplateVariables map[string]string `json:"template_variables,omitempty"`
}

CreateBroadcastRequest is the request object for Broadcasts.Create. Provide either Html or TemplateId.

type CreateContactRequest

type CreateContactRequest struct {
	Email     string `json:"email"`
	FirstName string `json:"first_name,omitempty"`
	LastName  string `json:"last_name,omitempty"`
}

CreateContactRequest is the request object for Audiences.CreateContact and the item shape for BatchCreateContacts.

type CreateDomainRequest

type CreateDomainRequest struct {
	Name string `json:"name"`
}

CreateDomainRequest is the request object for Domains.Create.

type CreateDomainResponse

type CreateDomainResponse struct {
	Id    string    `json:"id"`
	Name  string    `json:"name"`
	Dkim  DnsRecord `json:"dkim"`
	Spf   DnsRecord `json:"spf"`
	Dmarc DnsRecord `json:"dmarc"`
}

CreateDomainResponse is returned by Domains.Create and carries the DNS records to add.

type CreateTemplateRequest

type CreateTemplateRequest struct {
	Name    string `json:"name"`
	Subject string `json:"subject"`
	Html    string `json:"html"`
}

CreateTemplateRequest is the request object for Templates.Create. Use {{variable}} placeholders in Subject/Html; values are HTML-escaped at send time.

type CreateWebhookRequest

type CreateWebhookRequest struct {
	Url    string   `json:"url"`
	Events []string `json:"events"`
}

CreateWebhookRequest is the request object for Webhooks.Create. Pass Events []string{"*"} to subscribe to every event.

type DnsRecord

type DnsRecord struct {
	Type  string `json:"type"`
	Name  string `json:"name"`
	Value string `json:"value"`
}

DnsRecord is a DNS entry to publish for a domain.

type Domain

type Domain struct {
	Id            string `json:"id"`
	Name          string `json:"name"`
	DkimPublicKey string `json:"dkimPublicKey"`
	DkimSelector  string `json:"dkimSelector"`
	Status        string `json:"status"`
	CreatedAt     string `json:"createdAt"`
	VerifiedAt    string `json:"verifiedAt"`
}

Domain is the response from Domains.Get.

type DomainListItem

type DomainListItem struct {
	Id        string `json:"id"`
	Name      string `json:"name"`
	Status    string `json:"status"`
	CreatedAt string `json:"createdAt"`
}

DomainListItem is a row from Domains.List.

type DomainsSvc

type DomainsSvc interface {
	Create(params *CreateDomainRequest) (*CreateDomainResponse, error)
	CreateWithContext(ctx context.Context, params *CreateDomainRequest) (*CreateDomainResponse, error)
	List() ([]DomainListItem, error)
	ListWithContext(ctx context.Context) ([]DomainListItem, error)
	Get(domainId string) (*Domain, error)
	GetWithContext(ctx context.Context, domainId string) (*Domain, error)
	Verify(domainId string) (*GenericResponse, error)
	VerifyWithContext(ctx context.Context, domainId string) (*GenericResponse, error)
	Remove(domainId string) (*GenericResponse, error)
	RemoveWithContext(ctx context.Context, domainId string) (*GenericResponse, error)
}

DomainsSvc is the /domains API.

type DomainsSvcImpl

type DomainsSvcImpl struct {
	// contains filtered or unexported fields
}

func (*DomainsSvcImpl) Create

func (*DomainsSvcImpl) CreateWithContext

func (s *DomainsSvcImpl) CreateWithContext(ctx context.Context, params *CreateDomainRequest) (*CreateDomainResponse, error)

func (*DomainsSvcImpl) Get

func (s *DomainsSvcImpl) Get(domainId string) (*Domain, error)

func (*DomainsSvcImpl) GetWithContext

func (s *DomainsSvcImpl) GetWithContext(ctx context.Context, domainId string) (*Domain, error)

func (*DomainsSvcImpl) List

func (s *DomainsSvcImpl) List() ([]DomainListItem, error)

func (*DomainsSvcImpl) ListWithContext

func (s *DomainsSvcImpl) ListWithContext(ctx context.Context) ([]DomainListItem, error)

func (*DomainsSvcImpl) Remove

func (s *DomainsSvcImpl) Remove(domainId string) (*GenericResponse, error)

func (*DomainsSvcImpl) RemoveWithContext

func (s *DomainsSvcImpl) RemoveWithContext(ctx context.Context, domainId string) (*GenericResponse, error)

func (*DomainsSvcImpl) Verify

func (s *DomainsSvcImpl) Verify(domainId string) (*GenericResponse, error)

func (*DomainsSvcImpl) VerifyWithContext

func (s *DomainsSvcImpl) VerifyWithContext(ctx context.Context, domainId string) (*GenericResponse, error)

type Email

type Email struct {
	Id          string       `json:"id"`
	From        string       `json:"from"`
	To          []string     `json:"to"`
	Cc          []string     `json:"cc"`
	Bcc         []string     `json:"bcc"`
	ReplyTo     []string     `json:"replyTo"`
	Subject     string       `json:"subject"`
	Html        string       `json:"html"`
	Text        string       `json:"text"`
	Status      string       `json:"status"`
	TestMode    bool         `json:"testMode"`
	TemplateId  string       `json:"templateId"`
	ScheduledAt string       `json:"scheduledAt"`
	CreatedAt   string       `json:"createdAt"`
	Events      []EmailEvent `json:"events"`
}

Email is the response from Emails.Get.

type EmailEvent

type EmailEvent struct {
	Id        string         `json:"id"`
	Type      string         `json:"type"`
	Metadata  map[string]any `json:"metadata"`
	CreatedAt string         `json:"createdAt"`
}

EmailEvent is one entry in an email's delivery timeline.

type EmailListItem

type EmailListItem struct {
	Id        string   `json:"id"`
	From      string   `json:"from"`
	To        []string `json:"to"`
	Subject   string   `json:"subject"`
	Status    string   `json:"status"`
	TestMode  bool     `json:"testMode"`
	CreatedAt string   `json:"createdAt"`
}

EmailListItem is a row from Emails.List.

type EmailsSvc

type EmailsSvc interface {
	Send(params *SendEmailRequest) (*SendEmailResponse, error)
	SendWithContext(ctx context.Context, params *SendEmailRequest) (*SendEmailResponse, error)
	SendWithOptions(ctx context.Context, params *SendEmailRequest, options *SendEmailOptions) (*SendEmailResponse, error)
	Get(emailId string) (*Email, error)
	GetWithContext(ctx context.Context, emailId string) (*Email, error)
	List(options *ListEmailsOptions) (*ListEmailsResponse, error)
	ListWithContext(ctx context.Context, options *ListEmailsOptions) (*ListEmailsResponse, error)
	Update(params *UpdateEmailRequest) (*UpdateEmailResponse, error)
	UpdateWithContext(ctx context.Context, params *UpdateEmailRequest) (*UpdateEmailResponse, error)
	Cancel(emailId string) (*CancelScheduledEmailResponse, error)
	CancelWithContext(ctx context.Context, emailId string) (*CancelScheduledEmailResponse, error)
}

EmailsSvc is the /emails API.

type EmailsSvcImpl

type EmailsSvcImpl struct {
	// contains filtered or unexported fields
}

func (*EmailsSvcImpl) Cancel

func (s *EmailsSvcImpl) Cancel(emailId string) (*CancelScheduledEmailResponse, error)

Cancel cancels a scheduled email. It fails once the email has started sending.

func (*EmailsSvcImpl) CancelWithContext

func (s *EmailsSvcImpl) CancelWithContext(ctx context.Context, emailId string) (*CancelScheduledEmailResponse, error)

func (*EmailsSvcImpl) Get

func (s *EmailsSvcImpl) Get(emailId string) (*Email, error)

Get retrieves an email by ID, including its delivery events.

func (*EmailsSvcImpl) GetWithContext

func (s *EmailsSvcImpl) GetWithContext(ctx context.Context, emailId string) (*Email, error)

func (*EmailsSvcImpl) List

List returns a page of emails, most recent first.

func (*EmailsSvcImpl) ListWithContext

func (s *EmailsSvcImpl) ListWithContext(ctx context.Context, options *ListEmailsOptions) (*ListEmailsResponse, error)

func (*EmailsSvcImpl) Send

Send sends a single email.

func (*EmailsSvcImpl) SendWithContext

func (s *EmailsSvcImpl) SendWithContext(ctx context.Context, params *SendEmailRequest) (*SendEmailResponse, error)

SendWithContext is Send with a caller-supplied context.

func (*EmailsSvcImpl) SendWithOptions

func (s *EmailsSvcImpl) SendWithOptions(ctx context.Context, params *SendEmailRequest, options *SendEmailOptions) (*SendEmailResponse, error)

SendWithOptions is Send with a context and per-call options (e.g. an idempotency key).

func (*EmailsSvcImpl) Update

Update reschedules a scheduled email. It fails once the email has started sending.

func (*EmailsSvcImpl) UpdateWithContext

func (s *EmailsSvcImpl) UpdateWithContext(ctx context.Context, params *UpdateEmailRequest) (*UpdateEmailResponse, error)

type Error

type Error struct {
	// Message is a human-readable description (the API's `error` field).
	Message string `json:"error"`
	// Code is a stable machine-readable code (the API's `code` field); see the
	// Code* constants. Branch on this rather than on Message.
	Code string `json:"code"`
	// StatusCode is the HTTP status, or 0 for a network-level failure
	// (Code == CodeApplicationError).
	StatusCode int `json:"-"`

	// RateLimit* are populated from response headers on a 429.
	RateLimitReset     string `json:"-"`
	RateLimitRemaining string `json:"-"`
	RetryAfter         string `json:"-"`
}

Error is returned when the API responds with a non-2xx status, or when the request never reaches the server. Inspect it with errors.As:

var apiErr *eusend.Error
if errors.As(err, &apiErr) && apiErr.Code == eusend.CodeMonthlyLimitExceeded {
    // back off and retry later
}

func (*Error) Error

func (e *Error) Error() string

type GenericResponse

type GenericResponse struct {
	Message string `json:"message"`
}

GenericResponse is a simple {"message": "..."} acknowledgement.

type ListContactsOptions

type ListContactsOptions struct {
	Limit      int
	Cursor     string
	Search     string
	Subscribed *bool
}

ListContactsOptions filters Audiences.ListContacts. Zero-valued fields are omitted.

type ListContactsResponse

type ListContactsResponse struct {
	Data       []Contact `json:"data"`
	NextCursor string    `json:"next_cursor"`
}

ListContactsResponse is a page of contacts.

type ListEmailsOptions

type ListEmailsOptions struct {
	Limit  int
	Cursor string
	Status string
	From   string
	To     string
}

ListEmailsOptions filters Emails.List. Zero-valued fields are omitted.

type ListEmailsResponse

type ListEmailsResponse struct {
	Data       []EmailListItem `json:"data"`
	NextCursor string          `json:"next_cursor"`
}

ListEmailsResponse is the response from Emails.List.

type Options

type Options interface {
	GetIdempotencyKey() string
}

Options is implemented by per-call option structs (e.g. SendEmailOptions).

type SendBroadcastRequest

type SendBroadcastRequest struct {
	// ScheduledAt, when set, schedules the broadcast instead of sending immediately.
	ScheduledAt string `json:"scheduled_at,omitempty"`
}

SendBroadcastRequest sends or schedules a broadcast.

type SendBroadcastResponse

type SendBroadcastResponse struct {
	Id          string `json:"id"`
	Status      string `json:"status"`
	ScheduledAt string `json:"scheduled_at"`
}

SendBroadcastResponse is the response from Broadcasts.Send.

type SendEmailOptions

type SendEmailOptions struct {
	// IdempotencyKey makes a send safe to retry: retrying with the same key
	// never sends a duplicate and returns the original email's ID.
	IdempotencyKey string `json:"-"`
}

SendEmailOptions carries per-call options for Emails.SendWithOptions.

func (SendEmailOptions) GetIdempotencyKey

func (o SendEmailOptions) GetIdempotencyKey() string

GetIdempotencyKey implements the Options interface.

type SendEmailRequest

type SendEmailRequest struct {
	// From accepts a bare email ("you@yourdomain.com") or a display-name form
	// ("Acme <you@yourdomain.com>"). The domain must be verified on your account.
	From        string            `json:"from"`
	To          []string          `json:"to"`
	Subject     string            `json:"subject,omitempty"`
	Bcc         []string          `json:"bcc,omitempty"`
	Cc          []string          `json:"cc,omitempty"`
	ReplyTo     []string          `json:"reply_to,omitempty"`
	Html        string            `json:"html,omitempty"`
	Text        string            `json:"text,omitempty"`
	TemplateId  string            `json:"template_id,omitempty"`
	Variables   map[string]any    `json:"variables,omitempty"`
	Headers     map[string]string `json:"headers,omitempty"`
	TrackOpens  *bool             `json:"track_opens,omitempty"`
	TrackClicks *bool             `json:"track_clicks,omitempty"`
	Attachments []*Attachment     `json:"attachments,omitempty"`
	// ScheduledAt schedules the send for a future time, at most 30 days out.
	// Accepts an ISO 8601 string or natural language ("in 1 hour", "tomorrow at
	// 9am"), parsed server-side in UTC. Not supported by Batch.Send.
	ScheduledAt string `json:"scheduled_at,omitempty"`
}

SendEmailRequest is the request object for Emails.Send. From and To are required; provide at least one of Html, Text, or TemplateId.

type SendEmailResponse

type SendEmailResponse struct {
	Id string `json:"id"`
}

SendEmailResponse is the response from Emails.Send.

type Template

type Template struct {
	Id          string `json:"id"`
	Name        string `json:"name"`
	Subject     string `json:"subject"`
	Html        string `json:"html"`
	ReactSource string `json:"reactSource"`
	CreatedAt   string `json:"createdAt"`
	UpdatedAt   string `json:"updatedAt"`
}

Template is a saved email template.

type TemplateListItem

type TemplateListItem struct {
	Id        string `json:"id"`
	Name      string `json:"name"`
	Subject   string `json:"subject"`
	CreatedAt string `json:"createdAt"`
	UpdatedAt string `json:"updatedAt"`
}

TemplateListItem is a row from Templates.List.

type TemplatesSvc

type TemplatesSvc interface {
	Create(params *CreateTemplateRequest) (*Template, error)
	CreateWithContext(ctx context.Context, params *CreateTemplateRequest) (*Template, error)
	List() ([]TemplateListItem, error)
	ListWithContext(ctx context.Context) ([]TemplateListItem, error)
	Get(templateId string) (*Template, error)
	GetWithContext(ctx context.Context, templateId string) (*Template, error)
	Update(templateId string, params *UpdateTemplateRequest) (*Template, error)
	UpdateWithContext(ctx context.Context, templateId string, params *UpdateTemplateRequest) (*Template, error)
	Remove(templateId string) (*GenericResponse, error)
	RemoveWithContext(ctx context.Context, templateId string) (*GenericResponse, error)
}

TemplatesSvc is the /templates API.

type TemplatesSvcImpl

type TemplatesSvcImpl struct {
	// contains filtered or unexported fields
}

func (*TemplatesSvcImpl) Create

func (s *TemplatesSvcImpl) Create(params *CreateTemplateRequest) (*Template, error)

func (*TemplatesSvcImpl) CreateWithContext

func (s *TemplatesSvcImpl) CreateWithContext(ctx context.Context, params *CreateTemplateRequest) (*Template, error)

func (*TemplatesSvcImpl) Get

func (s *TemplatesSvcImpl) Get(templateId string) (*Template, error)

func (*TemplatesSvcImpl) GetWithContext

func (s *TemplatesSvcImpl) GetWithContext(ctx context.Context, templateId string) (*Template, error)

func (*TemplatesSvcImpl) List

func (s *TemplatesSvcImpl) List() ([]TemplateListItem, error)

func (*TemplatesSvcImpl) ListWithContext

func (s *TemplatesSvcImpl) ListWithContext(ctx context.Context) ([]TemplateListItem, error)

func (*TemplatesSvcImpl) Remove

func (s *TemplatesSvcImpl) Remove(templateId string) (*GenericResponse, error)

func (*TemplatesSvcImpl) RemoveWithContext

func (s *TemplatesSvcImpl) RemoveWithContext(ctx context.Context, templateId string) (*GenericResponse, error)

func (*TemplatesSvcImpl) Update

func (s *TemplatesSvcImpl) Update(templateId string, params *UpdateTemplateRequest) (*Template, error)

func (*TemplatesSvcImpl) UpdateWithContext

func (s *TemplatesSvcImpl) UpdateWithContext(ctx context.Context, templateId string, params *UpdateTemplateRequest) (*Template, error)

type UpdateBroadcastRequest

type UpdateBroadcastRequest struct {
	Name              *string           `json:"name,omitempty"`
	AudienceId        *string           `json:"audience_id,omitempty"`
	From              *string           `json:"from,omitempty"`
	Subject           *string           `json:"subject,omitempty"`
	Html              *string           `json:"html,omitempty"`
	TemplateId        *string           `json:"template_id,omitempty"`
	TemplateVariables map[string]string `json:"template_variables,omitempty"`
	ScheduledAt       *string           `json:"scheduled_at,omitempty"`
}

UpdateBroadcastRequest updates a broadcast. Empty/nil fields are left unchanged.

type UpdateContactRequest

type UpdateContactRequest struct {
	FirstName    *string `json:"first_name,omitempty"`
	LastName     *string `json:"last_name,omitempty"`
	Unsubscribed *bool   `json:"unsubscribed,omitempty"`
}

UpdateContactRequest updates a contact. Nil fields are left unchanged.

type UpdateEmailRequest

type UpdateEmailRequest struct {
	Id          string `json:"-"`
	ScheduledAt string `json:"scheduled_at"`
}

UpdateEmailRequest reschedules a scheduled email.

type UpdateEmailResponse

type UpdateEmailResponse struct {
	Id          string `json:"id"`
	Status      string `json:"status"`
	ScheduledAt string `json:"scheduled_at"`
}

UpdateEmailResponse is the response from Emails.Update.

type UpdateTemplateRequest

type UpdateTemplateRequest struct {
	Name    *string `json:"name,omitempty"`
	Subject *string `json:"subject,omitempty"`
	Html    *string `json:"html,omitempty"`
}

UpdateTemplateRequest updates a template. Nil fields are left unchanged.

type UpdateWebhookRequest

type UpdateWebhookRequest struct {
	Url    *string  `json:"url,omitempty"`
	Events []string `json:"events,omitempty"`
}

UpdateWebhookRequest updates a webhook. Nil/empty fields are left unchanged.

type Webhook

type Webhook struct {
	Id         string            `json:"id"`
	Url        string            `json:"url"`
	Events     []string          `json:"events"`
	Secret     string            `json:"secret,omitempty"`
	CreatedAt  string            `json:"createdAt"`
	Deliveries []WebhookDelivery `json:"deliveries,omitempty"`
}

Webhook is a webhook subscription. Secret is populated only by Create; Deliveries only by Get.

type WebhookDelivery

type WebhookDelivery struct {
	Id             string         `json:"id"`
	WebhookId      string         `json:"webhookId"`
	EmailId        string         `json:"emailId"`
	EventType      string         `json:"eventType"`
	Payload        map[string]any `json:"payload"`
	Status         string         `json:"status"`
	ResponseStatus int            `json:"responseStatus"`
	Attempts       int            `json:"attempts"`
	CreatedAt      string         `json:"createdAt"`
	LastAttemptAt  string         `json:"lastAttemptAt"`
}

WebhookDelivery is one delivery attempt of a webhook event.

type WebhooksSvc

type WebhooksSvc interface {
	Create(params *CreateWebhookRequest) (*Webhook, error)
	CreateWithContext(ctx context.Context, params *CreateWebhookRequest) (*Webhook, error)
	List() ([]Webhook, error)
	ListWithContext(ctx context.Context) ([]Webhook, error)
	Get(webhookId string) (*Webhook, error)
	GetWithContext(ctx context.Context, webhookId string) (*Webhook, error)
	Update(webhookId string, params *UpdateWebhookRequest) (*Webhook, error)
	UpdateWithContext(ctx context.Context, webhookId string, params *UpdateWebhookRequest) (*Webhook, error)
	Remove(webhookId string) (*GenericResponse, error)
	RemoveWithContext(ctx context.Context, webhookId string) (*GenericResponse, error)
}

WebhooksSvc is the /webhooks API.

type WebhooksSvcImpl

type WebhooksSvcImpl struct {
	// contains filtered or unexported fields
}

func (*WebhooksSvcImpl) Create

func (s *WebhooksSvcImpl) Create(params *CreateWebhookRequest) (*Webhook, error)

func (*WebhooksSvcImpl) CreateWithContext

func (s *WebhooksSvcImpl) CreateWithContext(ctx context.Context, params *CreateWebhookRequest) (*Webhook, error)

func (*WebhooksSvcImpl) Get

func (s *WebhooksSvcImpl) Get(webhookId string) (*Webhook, error)

func (*WebhooksSvcImpl) GetWithContext

func (s *WebhooksSvcImpl) GetWithContext(ctx context.Context, webhookId string) (*Webhook, error)

func (*WebhooksSvcImpl) List

func (s *WebhooksSvcImpl) List() ([]Webhook, error)

func (*WebhooksSvcImpl) ListWithContext

func (s *WebhooksSvcImpl) ListWithContext(ctx context.Context) ([]Webhook, error)

func (*WebhooksSvcImpl) Remove

func (s *WebhooksSvcImpl) Remove(webhookId string) (*GenericResponse, error)

func (*WebhooksSvcImpl) RemoveWithContext

func (s *WebhooksSvcImpl) RemoveWithContext(ctx context.Context, webhookId string) (*GenericResponse, error)

func (*WebhooksSvcImpl) Update

func (s *WebhooksSvcImpl) Update(webhookId string, params *UpdateWebhookRequest) (*Webhook, error)

func (*WebhooksSvcImpl) UpdateWithContext

func (s *WebhooksSvcImpl) UpdateWithContext(ctx context.Context, webhookId string, params *UpdateWebhookRequest) (*Webhook, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL