### Install SendPulse SDK for Go Source: https://github.com/dimuska139/sendpulse-sdk-go/blob/master/README.md Use this command to install the SendPulse SDK for Go. Ensure you are using the correct version. ```shell go get -u github.com/dimuska139/sendpulse-sdk-go/v8 ``` -------------------------------- ### SendPulse SDK Usage Example Source: https://github.com/dimuska139/sendpulse-sdk-go/blob/master/README.md Example demonstrating how to initialize the SendPulse client and add an email to a mailing list with single opt-in. Requires user ID and secret for configuration. ```go package main import ( "context" "fmt" sendpulse "github.com/dimuska139/sendpulse-sdk-go/v8" "net/http" ) func main() { config := &sendpulse.Config{ UserID: "", Secret: "", } client := sendpulse.NewClient(http.DefaultClient, config) emails := []*sendpulse.EmailToAdd { &sendpulse.EmailToAdd{ Email: "test@test.com", Variables: map[string]any{"age": 21, "weight": 99}, }, } ctx := context.Background() if err := client.Emails.MailingLists.SingleOptIn(ctx, 1266208, emails); err != nil { fmt.Println(err) } fmt.Println(*emails[0]) } ``` -------------------------------- ### Create Web Push Notification Campaign Source: https://context7.com/dimuska139/sendpulse-sdk-go/llms.txt Send a web push notification campaign with specified parameters. Includes examples for retrieving statistics, managing subscribers, and activating/deactivating subscriptions. ```go ctx := context.Background() taskID, err := client.Push.CreatePushCampaign(ctx, sendpulse.PushMessageParams{ Title: "Flash Sale!", Body: "50% off for the next 2 hours", WebsiteID: 42, TtlSec: 7200, Link: "https://myshop.com/sale", FilterLang: "en", }) if err != nil { log.Fatal(err) } fmt.Printf("Push campaign created, task ID: %d\n", taskID) // Statistics stats, _ := client.Push.GetPushMessagesStatistics(ctx, taskID) fmt.Printf("Sent=%d Delivered=%d Redirect=%d\n", stats.Send, stats.Delivered, stats.Redirect) // Subscribers count, _ := client.Push.CountWebsiteSubscriptions(ctx, 42) fmt.Printf("Total subscribers: %d\n", count) subs, _ := client.Push.GetWebsiteSubscriptions(ctx, 42, sendpulse.WebsiteSubscriptionsParams{Limit: 50}) for _, s := range subs { fmt.Printf("ID=%d Browser=%s OS=%s\n", s.ID, s.Browser, s.Os) } // Activate/deactivate a subscriber _ = client.Push.ActivateSubscription(ctx, 12345) _ = client.Push.DeactivateSubscription(ctx, 12345) ``` -------------------------------- ### Create and Manage Email Campaigns in Go Source: https://context7.com/dimuska139/sendpulse-sdk-go/llms.txt Schedule or immediately send email campaigns, retrieve campaign lists, cancel scheduled campaigns, and get country-specific statistics. HTML bodies are Base64-encoded automatically. ```go ctx := context.Background() campaign, err := client.Emails.Campaigns.CreateCampaign(ctx, sendpulse.CampaignParams{ SenderName: "My Company", SenderEmail: "newsletter@mycompany.com", Subject: "Monthly Update", Body: "

Hello!

Check out our news.

", MailingListID: 1266208, Name: "June 2024 Newsletter", // SendDate: sendpulse.DateTime(time.Now().Add(1*time.Hour)), // schedule }) if err != nil { log.Fatal(err) } fmt.Printf("Campaign ID=%d Status=%d\n", campaign.ID, campaign.Status) // Get campaign list campaigns, _ := client.Emails.Campaigns.GetCampaigns(ctx, 10, 0) for _, c := range campaigns { fmt.Printf("ID=%d Name=%s Sent=%d\n", c.ID, c.Name, c.AllEmailQty) } // Cancel a scheduled campaign _ = client.Emails.Campaigns.CancelCampaign(ctx, campaign.ID) // Country statistics countries, _ := client.Emails.Campaigns.GetCampaignCountriesStatistics(ctx, campaign.ID) for country, count := range countries { fmt.Printf("%s: %d\n", country, count) } ``` -------------------------------- ### Get Account Balance Source: https://context7.com/dimuska139/sendpulse-sdk-go/llms.txt Retrieve your account balance for a specific currency or get detailed balance information including tariff and quota data. ```go ctx := context.Background() // Get balance in EUR balance, err := client.Balance.GetBalance(ctx, "EUR") if err != nil { log.Fatal(err) } fmt.Printf("%.2f %s\n", balance.BalanceCurrency, balance.Currency) // Get detailed balance (tariff info, email/SMS/push quotas) detailed, err := client.Balance.GetDetailedBalance(ctx) if err != nil { log.Fatal(err) } fmt.Printf("Main: %v, Bonus: %v, Currency: %s\n", detailed.Balance.Main, detailed.Balance.Bonus, detailed.Balance.Currency) fmt.Printf("Emails left: %d, Subscribers: %d/%d\n", detailed.Email.EmailsLeft, detailed.Email.CurrentSubscribers, detailed.Email.MaximumSubscribers) ``` -------------------------------- ### Create Viber Message Campaign Source: https://context7.com/dimuska139/sendpulse-sdk-go/llms.txt Send a Viber message campaign with various options including buttons, images, and SMS fallback. Includes examples for retrieving campaign statistics and listing available senders. ```go ctx := context.Background() taskID, err := client.Viber.CreateCampaign(ctx, sendpulse.CreateViberCampaignParams{ TaskName: "Summer Promo", SenderID: 7, MessageLiveTime: 86400, MailingListID: 1266208, Message: "Check our summer sale!", Additional: &struct { Button *struct { Text string `json:"text"` Link string `json:"link"` } `json:"button,omitempty"` Image *struct { Link string `json:"link"` } `json:"image,omitempty"` ResendSms *struct { Status bool `json:"status"` SmsText string `json:"sms_text"` SmsSenderName string `json:"sms_sender_name"` } `json:"resend_sms,omitempty"` }{ Button: &struct { Text string `json:"text"` Link string `json:"link"` }{Text: "Shop Now", Link: "https://myshop.com"}, }, }) if err != nil { log.Fatal(err) } fmt.Printf("Viber campaign task ID: %d\n", taskID) // Statistics stats, _ := client.Viber.GetStatistics(ctx, taskID) fmt.Printf("Sent=%d Delivered=%d Read=%d\n", stats.Statistics.Sent, stats.Statistics.Delivered, stats.Statistics.Read) // List senders senders, _ := client.Viber.GetSenders(ctx) for _, s := range senders { fmt.Printf("ID=%d Name=%s Status=%s\n", s.ID, s.Name, s.Status) } ``` -------------------------------- ### Initialize SendPulse Client Source: https://context7.com/dimuska139/sendpulse-sdk-go/llms.txt Create a new client instance with your API credentials and desired request rate. Access various services like Balance through the client. ```go package main import ( "context" "fmt" "log" "net/http" sendpulse "github.com/dimuska139/sendpulse-sdk-go/v8" ) func main() { config := &sendpulse.Config{ UserID: "your_user_id", Secret: "your_secret", Rps: 10, } client := sendpulse.NewClient(http.DefaultClient, config) ctx := context.Background() // Access any service through the client balance, err := client.Balance.GetBalance(ctx, "USD") if err != nil { log.Fatal(err) } fmt.Printf("Balance: %.2f %s\n", balance.BalanceCurrency, balance.Currency) // Output: Balance: 42.50 USD } ``` -------------------------------- ### Trigger and Monitor Automation Flows with SendPulse Go SDK Source: https://context7.com/dimuska139/sendpulse-sdk-go/llms.txt Use `StartEvent` to trigger automation flows and `GetAutoresponderStatistics` to monitor their performance. Includes fetching block-level and conversion statistics, as well as contact details. ```go ctx := context.Background() // Fire a named event to trigger an automation flow err := client.Automation360.StartEvent(ctx, "purchase_completed", map[string]any{ "email": "alice@example.com", "order_id": "ORD-9001", "amount": 99.99, }) if err != nil { log.Fatal(err) } // Get autoresponder overview autoresponder, _ := client.Automation360.GetAutoresponderStatistics(ctx, 5678) fmt.Printf("Name=%s Starts=%d InQueue=%d Conversions=%d\n", autoresponder.Autoresponder.Name, autoresponder.Starts, autoresponder.InQueue, autoresponder.Conversions) // Block-level statistics emailStat, _ := client.Automation360.GetEmailBlockStatistics(ctx, 111) fmt.Printf("Sent=%d Opened=%d Clicked=%d Unsubscribed=%d\n", emailStat.Sent, emailStat.Opened, emailStat.Clicked, emailStat.Unsubscribed) pushStat, _ := client.Automation360.GetPushBlockStatistics(ctx, 222) fmt.Printf("Push Sent=%d Delivered=%d Clicked=%d\n", pushStat.Sent, pushStat.Delivered, pushStat.Clicked) // Conversion tracking conversions, _ := client.Automation360.GetAutoresponderConversions(ctx, 5678) fmt.Printf("Total conversions: %d\n", conversions.TotalConversions) contacts, _ := client.Automation360.GetAutoresponderContacts(ctx, 5678) for _, c := range contacts { fmt.Printf("Email=%s Phone=%s Date=%v\n", c.Email, c.Phone, c.ConversionDate) } ``` -------------------------------- ### Manage Mailing Lists Source: https://context7.com/dimuska139/sendpulse-sdk-go/llms.txt Create, rename, and list mailing lists. Use `CreateMailingList` to make a new address book, `ChangeName` to update its name, and `GetMailingLists` to retrieve a list of existing ones. ```go ctx := context.Background() id, err := client.Emails.MailingLists.CreateMailingList(ctx, "My Newsletter") if err != nil { log.Fatal(err) } fmt.Printf("Created mailing list ID: %d\n", id) // Rename it if err := client.Emails.MailingLists.ChangeName(ctx, id, "My Newsletter v2"); err != nil { log.Fatal(err) } // List all mailing lists (limit=10, offset=0) lists, err := client.Emails.MailingLists.GetMailingLists(ctx, 10, 0) if err != nil { log.Fatal(err) } for _, l := range lists { fmt.Printf("ID=%d Name=%s Active=%d\n", l.ID, l.Name, l.ActiveEmailQty) } ``` -------------------------------- ### Manage Email Templates in Go Source: https://context7.com/dimuska139/sendpulse-sdk-go/llms.txt Create, update, fetch, and list reusable email templates. The HTML body is Base64-encoded automatically. ```go ctx := context.Background() templateID, err := client.Emails.Templates.CreateTemplate( ctx, "Welcome Email", "

Welcome {{name}}!

", "en", ) if err != nil { log.Fatal(err) } fmt.Printf("Created template ID: %d\n", templateID) // Update it _ = client.Emails.Templates.UpdateTemplate( ctx, templateID, "

Hello {{name}}!

", "en", ) // Fetch it tmpl, _ := client.Emails.Templates.GetTemplate(ctx, templateID) fmt.Printf("Name: %s, Owner: %s\n", tmpl.Name, tmpl.Owner) // List templates (limit, offset, owner filter) templates, _ := client.Emails.Templates.GetTemplates(ctx, 10, 0, "me") for _, t := range templates { fmt.Printf("ID=%s Name=%s\n", t.ID, t.Name) } ``` -------------------------------- ### Manage Email Blacklist in Go Source: https://context7.com/dimuska139/sendpulse-sdk-go/llms.txt Add emails to the blacklist with a reason, retrieve all blacklisted emails, or remove emails from the blacklist. The SDK handles Base64 encoding internally. ```go ctx := context.Background() // Add to blacklist with a note err := client.Emails.Blacklist.AddToBlacklist( ctx, []string{"spam@example.com", "bounce@example.com"}, "Hard bounce", ) if err != nil { log.Fatal(err) } // List all blacklisted emails blacklisted, _ := client.Emails.Blacklist.GetEmails(ctx) fmt.Printf("Blacklisted count: %d\n", len(blacklisted)) // Remove from blacklist _ = client.Emails.Blacklist.RemoveFromBlacklist(ctx, []string{"spam@example.com"}) ``` -------------------------------- ### Client Initialization Source: https://context7.com/dimuska139/sendpulse-sdk-go/llms.txt Initializes the SendPulse client with user credentials and configuration. The client provides access to various SendPulse services. ```APIDOC ## Client Initialization **`NewClient(client *http.Client, config *Config) *Client`** — creates the root client that holds all service references. `Config` fields: `UserID` (API user ID), `Secret` (API secret), `Rps` (max requests per second, default 10). ```go package main import ( "context" "fmt" "log" "net/http" sendpulse "github.com/dimuska139/sendpulse-sdk-go/v8" ) func main() { config := &sendpulse.Config{ UserID: "your_user_id", Secret: "your_secret", Rps: 10, } client := sendpulse.NewClient(http.DefaultClient, config) ctx := context.Background() // Access any service through the client balance, err := client.Balance.GetBalance(ctx, "USD") if err != nil { log.Fatal(err) } fmt.Printf("Balance: %.2f %s\n", balance.BalanceCurrency, balance.Currency) // Output: Balance: 42.50 USD } ``` ``` -------------------------------- ### Send Campaigns to VK/OK Audiences with SendPulse Go SDK Source: https://context7.com/dimuska139/sendpulse-sdk-go/llms.txt Manage sender profiles and message templates for VKontakte and Odnoklassniki. Use the `Send` function to dispatch campaigns to specified address books and routes. ```go ctx := context.Background() // Create a sender profile senderID, _ := client.VkOk.CreateSender(ctx, sendpulse.CreateVkOkSenderParams{ Name: "My Brand", VkUrl: "https://vk.com/mybrand", OkUrl: "https://ok.ru/mybrand", }) // Create a message template templateID, _ := client.VkOk.CreateTemplate(ctx, sendpulse.CreateVkOkTemplateParams{ Name: "Promo Template", VkMessage: "Check our VK promo!", OkMessage: "Check our OK promo!", SenderID: senderID, }) // Send campaign campaignID, _ := client.VkOk.Send(ctx, sendpulse.SendVkOkTemplateParams{ AddressBooks: []int{1266208}, TemplateID: templateID, Name: "Summer VK/OK Campaign", Routes: map[string]bool{"vk": true, "ok": true}, }) fmt.Printf("Campaign ID: %d\n", campaignID) // Statistics stats, _ := client.VkOk.GetCampaignStatistics(ctx, campaignID) for _, g := range stats.GroupStat { fmt.Printf("Sent=%d Delivered=%d Opened=%d\n", g.Sent, g.Delivered, g.Opened) } ``` -------------------------------- ### Manage Email Event Webhooks Source: https://context7.com/dimuska139/sendpulse-sdk-go/llms.txt Create, retrieve, update, and delete webhooks to receive event notifications. Ensure the provided URL is accessible for receiving POST requests. ```go ctx := context.Background() // Create webhook for multiple events hooks, err := client.Emails.Webhooks.CreateWebhook( ctx, []string{"open", "click", "unsubscribe", "spam"}, "https://myapp.com/webhooks/sendpulse", ) if err != nil { log.Fatal(err) } for _, h := range hooks { fmt.Printf("Webhook ID=%d Action=%s URL=%s\n", h.ID, h.Action, h.Url) } // List all webhooks all, _ := client.Emails.Webhooks.GetWebhooks(ctx) fmt.Printf("Total webhooks: %d\n", len(all)) // Update URL _ = client.Emails.Webhooks.UpdateWebhook(ctx, hooks[0].ID, "https://myapp.com/v2/webhooks") // Delete _ = client.Emails.Webhooks.DeleteWebhook(ctx, hooks[0].ID) ``` -------------------------------- ### Manage Verified Sender Addresses in Go Source: https://context7.com/dimuska139/sendpulse-sdk-go/llms.txt Register, activate, list, and delete verified sender email addresses. Activation requires a code sent to the address. ```go ctx := context.Background() // Register sender _ = client.Emails.Senders.CreateSender(ctx, "My Company", "noreply@mycompany.com") // Request activation code _ = client.Emails.Senders.GetSenderActivationCode(ctx, "noreply@mycompany.com") // Activate with received code _ = client.Emails.Senders.ActivateSender(ctx, "noreply@mycompany.com", "123456") // List senders senders, _ := client.Emails.Senders.GetSenders(ctx) for _, s := range senders { fmt.Printf("Name=%s Email=%s Status=%s\n", s.Name, s.Email, s.Status) } // Delete a sender _ = client.Emails.Senders.DeleteSender(ctx, "noreply@mycompany.com") ``` -------------------------------- ### Manage Webhooks Source: https://context7.com/dimuska139/sendpulse-sdk-go/llms.txt Create, update, delete, and retrieve event webhooks for email events like open, click, unsubscribe, and spam. ```APIDOC ## Webhooks API ### CreateWebhook **Description**: Creates a new webhook to receive event notifications. **Method**: POST (assumed, based on SDK usage) **Endpoint**: `/webhooks` (assumed) **Parameters**: * **events** (array of strings) - Required - The list of events to subscribe to (e.g., "open", "click", "unsubscribe", "spam"). * **url** (string) - Required - The URL to send webhook notifications to. ### UpdateWebhook **Description**: Updates the URL for an existing webhook. **Method**: PUT (assumed, based on SDK usage) **Endpoint**: `/webhooks/{id}` (assumed) **Parameters**: * **id** (integer) - Required - The ID of the webhook to update. * **url** (string) - Required - The new URL for the webhook. ### DeleteWebhook **Description**: Deletes a webhook. **Method**: DELETE (assumed, based on SDK usage) **Endpoint**: `/webhooks/{id}` (assumed) **Parameters**: * **id** (integer) - Required - The ID of the webhook to delete. ### GetWebhooks **Description**: Retrieves a list of all configured webhooks. **Method**: GET (assumed, based on SDK usage) **Endpoint**: `/webhooks` (assumed) ### Request Example (CreateWebhook) ```go ctx := context.Background() hooks, err := client.Emails.Webhooks.CreateWebhook(ctx, []string{"open", "click", "unsubscribe", "spam"}, "https://myapp.com/webhooks/sendpulse") if err != nil { log.Fatal(err) } for _, h := range hooks { fmt.Printf("Webhook ID=%d Action=%s URL=%s\n", h.ID, h.Action, h.Url) } ``` ### Response Example (CreateWebhook) ```json [ { "ID": 123, "Action": "open", "Url": "https://myapp.com/webhooks/sendpulse" } ] ``` ``` -------------------------------- ### Balance Service Source: https://context7.com/dimuska139/sendpulse-sdk-go/llms.txt Provides methods to retrieve account balance information. ```APIDOC ## Balance Service (`client.Balance`) ### `GetBalance` — retrieve account balance for a currency Returns the main balance for the given currency code (pass `""` for default). ```go ctx := context.Background() // Get balance in EUR balance, err := client.Balance.GetBalance(ctx, "EUR") if err != nil { log.Fatal(err) } fmt.Printf("%.2f %s\n", balance.BalanceCurrency, balance.Currency) // Get detailed balance (tariff info, email/SMS/push quotas) detailed, err := client.Balance.GetDetailedBalance(ctx) if err != nil { log.Fatal(err) } fmt.Printf("Main: %v, Bonus: %v, Currency: %s\n", detailed.Balance.Main, detailed.Balance.Bonus, detailed.Balance.Currency) fmt.Printf("Emails left: %d, Subscribers: %d/%d\n", detailed.Email.EmailsLeft, detailed.Email.CurrentSubscribers, detailed.Email.MaximumSubscribers) ``` ``` -------------------------------- ### Validate Email Deliverability Source: https://context7.com/dimuska139/sendpulse-sdk-go/llms.txt Verify the deliverability of single email addresses or entire mailing lists. Asynchronous validation requires fetching results separately. ```go ctx := context.Background() // Validate a single email (async — result fetched later) _ = client.Emails.Validator.ValidateEmail(ctx, "test@example.com") result, err := client.Emails.Validator.GetEmailValidationResult(ctx, "test@example.com") if err != nil { log.Fatal(err) } fmt.Printf("Status=%d ValidFormat=%d Disposable=%d Webmail=%d\n", result.Checks.Status, result.Checks.ValidFormat, result.Checks.Disposable, result.Checks.Webmail, ) // Validate an entire mailing list _ = client.Emails.Validator.ValidateMailingList(ctx, 1266208) progress, _ := client.Emails.Validator.GetMailingListValidationProgress(ctx, 1266208) fmt.Printf("Processed %d / %d\n", progress.Processed, progress.Total) detailed, _ := client.Emails.Validator.GetMailingListValidationResult(ctx, 1266208) fmt.Printf("Valid=%d Invalid=%d Unconfirmed=%d\n", detailed.Data.Valid, detailed.Data.Invalid, detailed.Data.Unconfirmed) ``` -------------------------------- ### Add Contacts to Mailing List Source: https://context7.com/dimuska139/sendpulse-sdk-go/llms.txt Add contacts to a mailing list using either single opt-in (immediate addition) or double opt-in (sends a confirmation email). Supports custom variables for each contact. ```go ctx := context.Background() mailingListID := 1266208 emails := []*sendpulse.EmailToAdd{ { Email: "alice@example.com", Variables: map[string]any{"first_name": "Alice", "age": 30}, }, { Email: "bob@example.com", Variables: map[string]any{"first_name": "Bob", "age": 25}, }, } // Single opt-in (immediate) if err := client.Emails.MailingLists.SingleOptIn(ctx, mailingListID, emails); err != nil { log.Fatal(err) } // Double opt-in (sends confirmation email) err := client.Emails.MailingLists.DoubleOptIn( ctx, mailingListID, emails, "sender@yourdomain.com", // sender email "en", // message language "", // optional template ID ) if err != nil { log.Fatal(err) } ``` -------------------------------- ### Email Templates Source: https://context7.com/dimuska139/sendpulse-sdk-go/llms.txt Operations for creating, updating, retrieving, and listing email templates. ```APIDOC ## Email Templates (`client.Emails.Templates`) ### Create Template Creates a new reusable email template. HTML body is Base64-encoded automatically. ### Method `client.Emails.Templates.CreateTemplate(ctx context.Context, name string, html string, lang string) (int, error)` ### Update Template Updates an existing email template. HTML body is Base64-encoded automatically. ### Method `client.Emails.Templates.UpdateTemplate(ctx context.Context, templateID int, html string, lang string) error` ### Get Template Fetches a specific email template by its ID. ### Method `client.Emails.Templates.GetTemplate(ctx context.Context, templateID int) (*sendpulse.Template, error)` ### Get Templates Lists available email templates with optional filtering by owner. ### Method `client.Emails.Templates.GetTemplates(ctx context.Context, limit int, offset int, owner string) ([]*sendpulse.Template, error)` ``` -------------------------------- ### Engage WhatsApp Bot Contacts Source: https://context7.com/dimuska139/sendpulse-sdk-go/llms.txt This section demonstrates sending various message types, including free-form text and pre-approved templates with or without variables, to WhatsApp contacts. It also covers creating contacts, sending messages directly via phone number, and retrieving approved templates. ```go ctx := context.Background() bots, _ := client.Bots.WhatsApp.GetBots(ctx) botID := bots[0].ID // Create a contact contact, _ := client.Bots.WhatsApp.CreateContact(ctx, botID, "+12025550100", "Alice") // Send a free-form text message _ = client.Bots.WhatsApp.SendByContact(ctx, contact.ID, &sendpulse.WhatsAppMessage{ Type: "text", Text: &struct { Body string `json:"body"` }{Body: "Your appointment is confirmed!"}, }) // Send a pre-approved template _ = client.Bots.WhatsApp.SendTemplate(ctx, contact.ID, "order_confirmation", "en") // Template with variables _ = client.Bots.WhatsApp.SendTemplateWithVariables( ctx, contact.ID, "order_shipped", "en", []string{"Order #1234", "FedEx", "ABC123"}, ) // Send by phone directly (no contact ID needed) _ = client.Bots.WhatsApp.SendByPhone(ctx, botID, "+12025550101", &sendpulse.WhatsAppMessage{ Type: "text", Text: &struct { Body string `json:"body"` }{Body: "Hello from WhatsApp!"}, }) // Get approved templates templates, _ := client.Bots.WhatsApp.GetTemplates(ctx) for _, t := range templates { fmt.Printf("Name=%s Language=%s Status=%s\n", t.Name, t.Language, t.Status) } ``` -------------------------------- ### Manage Mailing List Contacts in Go Source: https://context7.com/dimuska139/sendpulse-sdk-go/llms.txt Use these functions to retrieve, count, delete, or unsubscribe contacts from a mailing list. Custom variables for a contact can also be updated. ```go ctx := context.Background() mailingListID := 1266208 // Paginated contacts contacts, err := client.Emails.MailingLists.GetMailingListEmails(ctx, mailingListID, 50, 0) if err != nil { log.Fatal(err) } for _, c := range contacts { fmt.Printf("%s status=%d\n", c.Email, c.Status) } // Total count total, _ := client.Emails.MailingLists.CountMailingListEmails(ctx, mailingListID) fmt.Printf("Total: %d\n", total) // Delete contacts _ = client.Emails.MailingLists.DeleteMailingListEmails(ctx, mailingListID, []string{"bob@example.com"}) // Unsubscribe contacts _ = client.Emails.MailingLists.UnsubscribeEmails(ctx, mailingListID, []string{"alice@example.com"}) // Update a contact's custom variables vars := []*sendpulse.Variable{{Name: "age", Value: 31}} _ = client.Emails.MailingLists.UpdateEmailVariables(ctx, mailingListID, "alice@example.com", vars) ``` -------------------------------- ### Send Transactional Emails via SMTP API Source: https://context7.com/dimuska139/sendpulse-sdk-go/llms.txt Send transactional emails with support for HTML, plain text, templates, and attachments. The API also allows listing sent messages, retrieving bounce reports, and managing unsubscribes. ```go ctx := context.Background() msgID, err := client.SMTP.SendMessage(ctx, sendpulse.SendEmailParams{ Subject: "Your order confirmation", From: sendpulse.User{Name: "My Shop", Email: "orders@myshop.com"}, To: []sendpulse.User{ {Name: "Alice", Email: "alice@example.com"}, }, Html: "

Order #1234 confirmed!

", AutoPlainText: true, Attachments: map[string]string{ "invoice.pdf": "BASE64_ENCODED_PDF_CONTENT", }, }) if err != nil { log.Fatal(err) } fmt.Printf("Message sent, ID: %s\n", msgID) // List sent messages messages, _ := client.SMTP.GetMessages(ctx, sendpulse.SmtpListParams{ Limit: 20, Offset: 0, Recipient: "alice@example.com", }) for _, m := range messages { fmt.Printf("ID=%s Subject=%s Opens=%d\n", m.ID, m.Subject, m.Tracking.Open) } // Bounce report bounces, _ := client.SMTP.GetDailyBounces(ctx, 20, 0, time.Now()) fmt.Printf("Bounces today: %d\n", bounces.Total) // Unsubscribe management _ = client.SMTP.UnsubscribeEmails(ctx, []*sendpulse.SmtpUnsubscribeEmail{ {Email: "optout@example.com", Comment: "User request"}, }) ``` -------------------------------- ### Email Campaigns Source: https://context7.com/dimuska139/sendpulse-sdk-go/llms.txt Functions for creating, retrieving, canceling, and analyzing email campaigns. ```APIDOC ## Email Campaigns (`client.Emails.Campaigns`) ### Create Campaign Schedules or immediately sends an email campaign. HTML body is Base64-encoded automatically; attach files as `filename → base64-content` pairs. ### Method `client.Emails.Campaigns.CreateCampaign(ctx context.Context, params sendpulse.CampaignParams) (*sendpulse.Campaign, error)` ### Get Campaigns Retrieves a list of campaigns. ### Method `client.Emails.Campaigns.GetCampaigns(ctx context.Context, limit int, offset int) ([]*sendpulse.Campaign, error)` ### Cancel Campaign Cancels a scheduled campaign. ### Method `client.Emails.Campaigns.CancelCampaign(ctx context.Context, campaignID int) error` ### Get Campaign Countries Statistics Retrieves statistics for a campaign broken down by country. ### Method `client.Emails.Campaigns.GetCampaignCountriesStatistics(ctx context.Context, campaignID int) (map[string]int, error)` ``` -------------------------------- ### Push Notifications Source: https://context7.com/dimuska139/sendpulse-sdk-go/llms.txt Manage and send web push notification campaigns using the SendPulse SDK. ```APIDOC ## CreatePushCampaign ### Description Creates a web push notification campaign. ### Method `client.Push.CreatePushCampaign` ### Parameters - `ctx` (context.Context) - The context for the request. - `params` (sendpulse.PushMessageParams) - Parameters for the push message. - `Title` (string) - Required - The title of the push notification. - `Body` (string) - Required - The body text of the push notification. - `WebsiteID` (int) - Required - The ID of the website to send the notification to. - `TtlSec` (int) - Optional - Time-to-live in seconds for the notification. - `Link` (string) - Optional - The URL to open when the notification is clicked. - `FilterLang` (string) - Optional - Language filter for the notification. ### Request Example ```go ctx := context.Background() taskID, err := client.Push.CreatePushCampaign(ctx, sendpulse.PushMessageParams{ Title: "Flash Sale!", Body: "50% off for the next 2 hours", WebsiteID: 42, TtlSec: 7200, Link: "https://myshop.com/sale", FilterLang: "en", }) ``` ### Response #### Success Response - `taskID` (int64) - The ID of the created push campaign task. - `err` (error) - An error if the campaign creation failed. ### Related Operations - `GetPushMessagesStatistics`: Retrieves statistics for a push campaign. - `CountWebsiteSubscriptions`: Counts the number of website subscribers. - `GetWebsiteSubscriptions`: Retrieves a list of website subscribers. - `ActivateSubscription`: Activates a subscriber. - `DeactivateSubscription`: Deactivates a subscriber. ``` -------------------------------- ### Email Address Information Source: https://context7.com/dimuska139/sendpulse-sdk-go/llms.txt Inspect and manage individual email addresses, including their mailing list status, campaign statistics, and custom variables. ```APIDOC ## Email Address API (`client.Emails.Address`) ### GetEmailInfo **Description**: Retrieves information about a single email address, including the mailing lists it belongs to and its status. **Method**: GET (assumed) **Endpoint**: `/emails/info` (assumed) **Parameters**: * **email** (string) - Required - The email address to query. ### GetEmailsInfo **Description**: Retrieves information for multiple email addresses in bulk. **Method**: POST (assumed) **Endpoint**: `/emails/info/bulk` (assumed) **Parameters**: * **emails** (array of strings) - Required - A list of email addresses to query. ### GetStatisticsByCampaign **Description**: Retrieves campaign statistics for a specific email address. **Method**: GET (assumed) **Endpoint**: `/emails/statistics/campaign/{campaign_id}` (assumed) **Parameters**: * **campaign_id** (integer) - Required - The ID of the campaign. * **email** (string) - Required - The email address to get statistics for. ### ChangeVariables **Description**: Updates custom variables for a specific email address within a mailing list. **Method**: PUT (assumed) **Endpoint**: `/lists/{list_id}/emails/{email}/variables` (assumed) **Parameters**: * **list_id** (integer) - Required - The ID of the mailing list. * **email** (string) - Required - The email address. * **variables** (array of objects) - Required - A list of variables to update. Each object should have `Name` (string) and `Value` (string). ### DeleteFromAllAddressBooks **Description**: Removes an email address from all mailing lists it is subscribed to. **Method**: DELETE (assumed) **Endpoint**: `/emails/{email}` (assumed) **Parameters**: * **email** (string) - Required - The email address to remove. ### Request Example (GetEmailInfo) ```go ctx := context.Background() info, err := client.Emails.Address.GetEmailInfo(ctx, "alice@example.com") if err != nil { log.Fatal(err) } for _, i := range info { fmt.Printf("BookID=%d Status=%d\n", i.BookID, i.Status) } ``` ### Response Example (GetEmailInfo) ```json [ { "BookID": 1, "Status": 1 } ] ``` ``` -------------------------------- ### Inspect and Manage Individual Email Addresses Source: https://context7.com/dimuska139/sendpulse-sdk-go/llms.txt Retrieve information about an email address, including its mailing list memberships and campaign statistics. Variables can be updated, and addresses can be removed from all lists. ```go ctx := context.Background() // Which mailing lists is this email in? info, err := client.Emails.Address.GetEmailInfo(ctx, "alice@example.com") if err != nil { log.Fatal(err) } for _, i := range info { fmt.Printf("BookID=%d Status=%d\n", i.BookID, i.Status) } // Bulk lookup bulk, _ := client.Emails.Address.GetEmailsInfo(ctx, []string{"alice@example.com", "bob@example.com"}) for email, infos := range bulk { fmt.Printf("%s is in %d lists\n", email, len(infos)) } // Campaign statistics for one address stat, _ := client.Emails.Address.GetStatisticsByCampaign(ctx, 9001, "alice@example.com") fmt.Printf("Sent=%v Opened=%v\n", stat.GlobalStatus, stat.DetailStatus) // Update contact variables _ = client.Emails.Address.ChangeVariables(ctx, 1266208, "alice@example.com", []*sendpulse.Variable{ {Name: "loyalty_tier", Value: "gold"}, }) // Remove from all lists _ = client.Emails.Address.DeleteFromAllAddressBooks(ctx, "alice@example.com") ``` -------------------------------- ### SMTP Service Source: https://context7.com/dimuska139/sendpulse-sdk-go/llms.txt Send transactional emails, manage sent messages, and handle bounces and unsubscribes. ```APIDOC ## SMTP Service API (`client.SMTP`) ### SendMessage **Description**: Sends a transactional email. Supports HTML, plain text, template IDs, and file attachments. **Method**: POST (assumed) **Endpoint**: `/smtp/send` (assumed) **Parameters**: * **params** (object) - Required - Parameters for sending the email. * **Subject** (string) - Required - The subject of the email. * **From** (object) - Required - Sender information. Contains `Name` (string) and `Email` (string). * **To** (array of objects) - Required - Recipients. Each object contains `Name` (string) and `Email` (string). * **Html** (string) - Optional - The HTML content of the email. * **Text** (string) - Optional - The plain text content of the email. * **TemplateID** (integer) - Optional - The ID of a pre-defined template. * **AutoPlainText** (boolean) - Optional - Automatically generate plain text version from HTML. * **Attachments** (object) - Optional - A map where keys are filenames and values are Base64-encoded file contents. ### GetMessages **Description**: Retrieves a list of sent SMTP messages with optional filtering. **Method**: GET (assumed) **Endpoint**: `/smtp/messages` (assumed) **Parameters**: * **params** (object) - Optional - Parameters for filtering messages. * **Limit** (integer) - Optional - Maximum number of messages to retrieve. * **Offset** (integer) - Optional - Number of messages to skip. * **Recipient** (string) - Optional - Filter by recipient email address. ### GetDailyBounces **Description**: Retrieves a report of daily email bounces. **Method**: GET (assumed) **Endpoint**: `/smtp/bounces/daily` (assumed) **Parameters**: * **limit** (integer) - Optional - Maximum number of bounce records. * **offset** (integer) - Optional - Number of bounce records to skip. * **date** (string) - Optional - The date for which to retrieve bounces (YYYY-MM-DD format). ### UnsubscribeEmails **Description**: Manages email unsubscribes. **Method**: POST (assumed) **Endpoint**: `/smtp/unsubscribe` (assumed) **Parameters**: * **emails** (array of objects) - Required - A list of emails to unsubscribe. Each object contains `Email` (string) and `Comment` (string). ### Request Example (SendMessage) ```go ctx := context.Background() msgID, err := client.SMTP.SendMessage(ctx, sendpulse.SendEmailParams{ Subject: "Your order confirmation", From: sendpulse.User{Name: "My Shop", Email: "orders@myshop.com"}, To: []sendpulse.User{ {Name: "Alice", Email: "alice@example.com"}, }, Html: "

Order #1234 confirmed!

", AutoPlainText: true, Attachments: map[string]string{ "invoice.pdf": "BASE64_ENCODED_PDF_CONTENT", }, }) if err != nil { log.Fatal(err) } fmt.Printf("Message sent, ID: %s\n", msgID) ``` ### Response Example (SendMessage) ```json { "message_id": "some_unique_message_id" } ``` ``` -------------------------------- ### Mailing Lists Source: https://context7.com/dimuska139/sendpulse-sdk-go/llms.txt Manages mailing lists, including creation, renaming, and adding contacts. ```APIDOC ## Mailing Lists (`client.Emails.MailingLists`) ### `CreateMailingList` — create a new address book / mailing list Returns the numeric ID of the newly created mailing list. ```go ctx := context.Background() id, err := client.Emails.MailingLists.CreateMailingList(ctx, "My Newsletter") if err != nil { log.Fatal(err) } fmt.Printf("Created mailing list ID: %d\n", id) // Rename it if err := client.Emails.MailingLists.ChangeName(ctx, id, "My Newsletter v2"); err != nil { log.Fatal(err) } // List all mailing lists (limit=10, offset=0) lists, err := client.Emails.MailingLists.GetMailingLists(ctx, 10, 0) if err != nil { log.Fatal(err) } for _, l := range lists { fmt.Printf("ID=%d Name=%s Active=%d\n", l.ID, l.Name, l.ActiveEmailQty) } ``` ### `SingleOptIn` / `DoubleOptIn` — add contacts to a mailing list `SingleOptIn` adds emails directly; `DoubleOptIn` triggers a confirmation email first. ```go ctx := context.Background() mailingListID := 1266208 emails := []*sendpulse.EmailToAdd{ { Email: "alice@example.com", Variables: map[string]any{"first_name": "Alice", "age": 30}, }, { Email: "bob@example.com", Variables: map[string]any{"first_name": "Bob", "age": 25}, }, } // Single opt-in (immediate) if err := client.Emails.MailingLists.SingleOptIn(ctx, mailingListID, emails); err != nil { log.Fatal(err) } // Double opt-in (sends confirmation email) err := client.Emails.MailingLists.DoubleOptIn( ctx, mailingListID, emails, "sender@yourdomain.com", // sender email "en", // message language "", // optional template ID ) if err != nil { log.Fatal(err) } ``` ``` -------------------------------- ### VK/OK Service Operations Source: https://context7.com/dimuska139/sendpulse-sdk-go/llms.txt Functions for managing sender profiles, message templates, sending campaigns, and retrieving campaign statistics for VKontakte and Odnoklassniki. ```APIDOC ## VK/OK Service (`client.VkOk`) ### `Send` — send campaigns to VKontakte and Odnoklassniki audiences ### Description Allows creating sender profiles, message templates, sending campaigns to specified address books, and retrieving campaign statistics for VK and OK platforms. ### Methods - `CreateSender(ctx context.Context, params CreateVkOkSenderParams) (int, error)` - `CreateTemplate(ctx context.Context, params CreateVkOkTemplateParams) (int, error)` - `Send(ctx context.Context, params SendVkOkTemplateParams) (int, error)` - `GetCampaignStatistics(ctx context.Context, campaignID int) (*CampaignStatistics, error)` ### Request Example (Send) ```go ctx := context.Background() // Create a sender profile senderID, _ := client.VkOk.CreateSender(ctx, sendpulse.CreateVkOkSenderParams{ Name: "My Brand", VkUrl: "https://vk.com/mybrand", OkUrl: "https://ok.ru/mybrand", }) // Create a message template templateID, _ := client.VkOk.CreateTemplate(ctx, sendpulse.CreateVkOkTemplateParams{ Name: "Promo Template", VkMessage: "Check our VK promo!", OkMessage: "Check our OK promo!", SenderID: senderID, }) // Send campaign campaignID, _ := client.VkOk.Send(ctx, sendpulse.SendVkOkTemplateParams{ AddressBooks: []int{1266208}, TemplateID: templateID, Name: "Summer VK/OK Campaign", Routes: map[string]bool{"vk": true, "ok": true}, }) fmt.Printf("Campaign ID: %d\n", campaignID) ``` ### Response Example (GetCampaignStatistics) ```go stats, _ := client.VkOk.GetCampaignStatistics(ctx, campaignID) for _, g := range stats.GroupStat { fmt.Printf("Sent=%d Delivered=%d Opened=%d\n", g.Sent, g.Delivered, g.Opened) } ``` ```