Self-hosted email delivery platform that enables applications to send emails via HTTP APIs while handling SMTP delivery, templates, storage, security, and analytics. Fully self-hostable alternative to services like SendGrid or Mailgun.
Go email-relayemail-routinghttp-to-smtpmail-deliverymailchimp-alternativemailgun-alternativemailsendermailservermailtemplatemailtestpostmark-alternativesend-emailsendgrid-alternativesendmailtransactional-emailtransactional-outbox
// Copyright (c) 2026 Jonas Kaninda.
//
// This file is part of Posta.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//
// SPDX-License-Identifier: AGPL-3.0-or-later
package routes
import (
"net/http"
"github.com/goposta/posta/internal/dto"
"github.com/goposta/posta/internal/handlers"
"github.com/goposta/posta/internal/models"
"github.com/goposta/posta/internal/services/email"
"github.com/jkaninda/okapi"
)
func (r *Router) workspaceResourceRoutes() []okapi.RouteDefinition {
opsGroup := r.v1.Group("/workspaces/current", r.mw.auth, r.mw.workspace).WithTagInfo(okapi.GroupTag{
Name: tagWorkspaceResources,
Description: "Operational resources scoped to the active workspace: sending, templates, stylesheets, languages, API keys, contacts, subscribers, campaigns, domains, SMTP servers, webhooks, suppressions, and workspace analytics. Authenticated with a dashboard session or an API key bound to the workspace.",
})
opsGroup.WithBearerAuth()
routes := []okapi.RouteDefinition{
{
Method: http.MethodGet,
Path: "/dashboard/stats",
Handler: r.h.dashboard.Stats,
Group: opsGroup,
Summary: "Get dashboard statistics",
Description: "Returns email sending statistics for the authenticated user",
Response: &dto.Response[handlers.DashboardStats]{},
},
{
Method: http.MethodGet,
Path: "/analytics",
Handler: okapi.H(r.h.analytics.UserAnalytics),
Group: opsGroup,
Summary: "Email analytics",
Description: "Returns daily email counts and status breakdown for the authenticated user",
Request: &handlers.AnalyticsRequest{},
Response: &dto.Response[handlers.AnalyticsResponse]{},
},
{
Method: http.MethodGet,
Path: "/analytics/dashboard",
Handler: okapi.H(r.h.analytics.UserDashboardAnalytics),
Group: opsGroup,
Summary: "Dashboard analytics",
Description: "Returns delivery rate trends, bounce rate graphs, and latency percentiles",
Request: &handlers.DashboardAnalyticsRequest{},
Response: &dto.Response[handlers.DashboardAnalyticsResponse]{},
},
{
Method: http.MethodGet,
Path: "/analytics/providers",
Handler: okapi.H(r.h.analytics.UserProviderBreakdown),
Group: opsGroup,
Summary: "Deliverability by provider",
Description: "Returns sent/failed counts and delivery rate grouped by recipient mailbox provider (Gmail, Outlook, Yahoo, ...)",
Request: &handlers.ProviderBreakdownRequest{},
Response: &dto.Response[handlers.ProviderBreakdownResponse]{},
},
{
Method: http.MethodGet,
Path: "/emails",
Handler: okapi.H(r.h.email.List),
Group: opsGroup,
OperationId: "workspace-list-emails",
Summary: "List emails",
Description: "List sent emails with pagination",
Request: &handlers.ListRequest{},
Response: &dto.PageableResponse[models.Email]{},
},
{
Method: http.MethodGet,
Path: "/emails/{id}",
Handler: okapi.H(r.h.email.Get),
Group: opsGroup,
OperationId: "workspace-get-email-details",
Summary: "Get email details",
Response: &dto.Response[models.Email]{},
Options: []okapi.RouteOption{
okapi.DocPathParam("id", "string", "Email UUID"),
okapi.DocResponse(404, &dto.ErrorResponseBody{}),
},
},
{
Method: http.MethodGet,
Path: "/emails/{id}/status",
Handler: okapi.H(r.h.email.GetStatus),
Group: opsGroup,
OperationId: "workspace-get-email-delivery-status",
Summary: "Get email delivery status",
Description: "Returns a lightweight status view for polling email delivery progress. Only the email owner can access this.",
Response: &dto.Response[handlers.EmailStatusResponse]{},
Options: []okapi.RouteOption{
okapi.DocPathParam("id", "string", "Email UUID"),
okapi.DocResponse(404, &dto.ErrorResponseBody{}),
},
},
{
Method: http.MethodPost,
Path: "/emails/{id}/retry",
Handler: okapi.H(r.h.email.Retry),
Group: opsGroup,
OperationId: "workspace-retry-failed-email",
Summary: "Retry failed email",
Description: "Re-enqueue a failed email for another delivery attempt",
Response: &dto.Response[email.SendResponse]{},
Options: []okapi.RouteOption{
okapi.DocPathParam("id", "string", "Email UUID"),
okapi.DocResponse(400, &dto.ErrorResponseBody{}),
okapi.DocResponse(404, &dto.ErrorResponseBody{}),
},
},
{
Method: http.MethodPost,
Path: "/emails/preview",
Handler: okapi.H(r.h.email.Preview),
Group: opsGroup,
OperationId: "workspace-preview-email-from-template",
Summary: "Preview email from template",
Description: "Render a template with variables and return the HTML, text, and subject without sending.",
Request: &handlers.PreviewEmailRequest{},
Response: &dto.Response[handlers.PreviewEmailResponse]{},
Options: []okapi.RouteOption{
okapi.DocResponse(400, &dto.ErrorResponseBody{}),
},
},
{
Method: http.MethodPost,
Path: "/api-keys",
Handler: okapi.H(r.h.apiKey.Create),
Group: opsGroup,
Middlewares: []okapi.Middleware{r.mw.verifiedEmail},
Summary: "Create API key",
Description: "Generate a new API key. The raw key is only shown once in the response.",
Request: &handlers.CreateAPIKeyRequest{},
Options: []okapi.RouteOption{
okapi.DocResponse(201, &dto.Response[dto.APIKeyCreatedData]{}),
okapi.DocResponse(403, &dto.ErrorResponseBody{}),
},
},
{
Method: http.MethodGet,
Path: "/api-keys",
Handler: okapi.H(r.h.apiKey.List),
Group: opsGroup,
Summary: "List API keys",
Request: &handlers.ListRequest{},
Response: &dto.PageableResponse[models.APIKey]{},
},
{
Method: http.MethodGet,
Path: "/api-keys/{id}",
Handler: okapi.H(r.h.apiKey.Get),
Group: opsGroup,
Summary: "Get API key",
Request: &handlers.GetAPIKeyRequest{},
Response: &dto.Response[models.APIKey]{},
Options: []okapi.RouteOption{
okapi.DocResponse(404, &dto.ErrorResponseBody{}),
},
},
{
Method: http.MethodPut,
Path: "/api-keys/{id:int}/revoke",
Handler: okapi.H(r.h.apiKey.Revoke),
Group: opsGroup,
Summary: "Revoke API key",
Response: &dto.Response[dto.MessageData]{},
Options: []okapi.RouteOption{
okapi.DocPathParam("id", "integer", "API key ID"),
okapi.DocResponse(404, &dto.ErrorResponseBody{}),
},
},
{
Method: http.MethodDelete,
Path: "/api-keys/{id:int}",
Handler: okapi.H(r.h.apiKey.Delete),
Group: opsGroup,
Summary: "Delete API key",
Response: &dto.Response[dto.MessageData]{},
Options: []okapi.RouteOption{
okapi.DocPathParam("id", "integer", "API key ID"),
okapi.DocResponse(404, &dto.ErrorResponseBody{}),
},
},
}
if r.cfg.SMTPRelayEnabled {
routes = append(routes,
okapi.RouteDefinition{
Method: http.MethodPost,
Path: "/smtp-credentials",
Handler: okapi.H(r.h.smtpCredential.Create),
Group: opsGroup,
Summary: "Create an SMTP Relay credential",
Description: "Generate a new SMTP username/password credential for this workspace. " +
"The raw password is only shown once in the response.",
Request: &handlers.CreateSMTPCredentialRequest{},
Options: []okapi.RouteOption{
okapi.DocResponse(201, &dto.Response[dto.SMTPCredentialCreatedData]{}),
okapi.DocResponse(403, &dto.ErrorResponseBody{}),
},
},
okapi.RouteDefinition{
Method: http.MethodGet,
Path: "/smtp-credentials",
Handler: okapi.H(r.h.smtpCredential.List),
Group: opsGroup,
Summary: "List SMTP Relay credentials",
Request: &handlers.ListRequest{},
Response: &dto.PageableResponse[models.SMTPCredential]{},
},
okapi.RouteDefinition{
Method: http.MethodGet,
Path: "/smtp-credentials/{id:int}",
Handler: okapi.H(r.h.smtpCredential.Get),
Group: opsGroup,
Summary: "Get an SMTP Relay credential",
Request: &handlers.GetSMTPCredentialRequest{},
Response: &dto.Response[models.SMTPCredential]{},
Options: []okapi.RouteOption{
okapi.DocResponse(404, &dto.ErrorResponseBody{}),
},
},
okapi.RouteDefinition{
Method: http.MethodPost,
Path: "/smtp-credentials/{id:int}/revoke",
Handler: okapi.H(r.h.smtpCredential.Revoke),
Group: opsGroup,
Summary: "Revoke an SMTP Relay credential",
Request: &handlers.RevokeSMTPCredentialRequest{},
Response: &dto.Response[dto.MessageData]{},
Options: []okapi.RouteOption{
okapi.DocPathParam("id", "integer", "SMTP credential ID"),
okapi.DocResponse(404, &dto.ErrorResponseBody{}),
},
},
okapi.RouteDefinition{
Method: http.MethodDelete,
Path: "/smtp-credentials/{id:int}",
Handler: okapi.H(r.h.smtpCredential.Delete),
Group: opsGroup,
Summary: "Delete an SMTP Relay credential",
Request: &handlers.DeleteSMTPCredentialRequest{},
Response: &dto.Response[dto.MessageData]{},
Options: []okapi.RouteOption{
okapi.DocPathParam("id", "integer", "SMTP credential ID"),
okapi.DocResponse(404, &dto.ErrorResponseBody{}),
},
},
)
}
routes = append(routes, []okapi.RouteDefinition{
{
Method: http.MethodPost,
Path: "/templates",
Handler: okapi.H(r.h.template.Create),
Group: opsGroup,
Tags: []string{tagUser},
Summary: "Create template",
Request: &handlers.CreateTemplateRequest{},
Options: []okapi.RouteOption{
okapi.DocResponse(201, &dto.Response[models.Template]{}),
okapi.DocResponse(409, &dto.ErrorResponseBody{}),
},
},
{
Method: http.MethodGet,
Path: "/templates",
Handler: okapi.H(r.h.template.List),
Group: opsGroup,
Summary: "List templates",
Request: &handlers.ListTemplatesRequest{},
Response: &dto.PageableResponse[handlers.TemplateListItem]{},
},
{
Method: http.MethodGet,
Path: "/templates/{id}",
Handler: okapi.H(r.h.template.Get),
Group: opsGroup,
Summary: "Get template",
Request: &handlers.GetTemplateRequest{},
Response: &dto.Response[models.Template]{},
Options: []okapi.RouteOption{
okapi.DocPathParam("id", "integer", "Template ID"),
okapi.DocResponse(404, &dto.ErrorResponseBody{}),
},
},
{
Method: http.MethodPut,
Path: "/templates/{id}",
Handler: okapi.H(r.h.template.Update),
Group: opsGroup,
Summary: "Update template",
Request: &handlers.UpdateTemplateRequest{},
Response: &dto.Response[models.Template]{},
Options: []okapi.RouteOption{
okapi.DocPathParam("id", "integer", "Template ID"),
okapi.DocResponse(404, &dto.ErrorResponseBody{}),
},
},
{
Method: http.MethodDelete,
Path: "/templates/{id:int}",
Handler: okapi.H(r.h.template.Delete),
Group: opsGroup,
Tags: []string{tagUser},
Summary: "Delete template",
Options: []okapi.RouteOption{
okapi.DocPathParam("id", "integer", "Template ID"),
okapi.DocResponse(204, nil),
okapi.DocResponse(404, &dto.ErrorResponseBody{}),
},
},
{
Method: http.MethodPost,
Path: "/templates/preview",
Handler: okapi.H(r.h.template.Preview),
Group: opsGroup,
Summary: "Preview template",
Description: "Render a template with sample data and return the result",
Request: &handlers.PreviewTemplateRequest{},
Response: &dto.Response[handlers.PreviewResult]{},
},
{
Method: http.MethodPost,
Path: "/templates/{id:int}/send-test",
Handler: okapi.H(r.h.template.SendTest),
Group: opsGroup,
Summary: "Send test email",
Description: "Send a test email using a template with sample data",
Request: &handlers.SendTestRequest{},
Response: &dto.Response[email.SendResponse]{},
Options: []okapi.RouteOption{
okapi.DocPathParam("id", "integer", "Template ID"),
okapi.DocResponse(404, &dto.ErrorResponseBody{}),
},
},
{
Method: http.MethodGet,
Path: "/templates/{id:int}/export",
Handler: okapi.H(r.h.template.Export),
Group: opsGroup,
Summary: "Export template",
Description: "Export a template with all versions and localizations as JSON",
Response: &dto.Response[handlers.TemplateExport]{},
Options: []okapi.RouteOption{
okapi.DocPathParam("id", "integer", "Template ID"),
okapi.DocResponse(404, &dto.ErrorResponseBody{}),
},
},
{
Method: http.MethodPost,
Path: "/templates/import",
Handler: okapi.H(r.h.template.Import),
Group: opsGroup,
Summary: "Import template",
Description: "Import a template from a previously exported JSON payload",
Request: &handlers.ImportTemplateRequest{},
Options: []okapi.RouteOption{
okapi.DocResponse(201, &dto.Response[models.Template]{}),
okapi.DocResponse(409, &dto.ErrorResponseBody{}),
},
},
{
Method: http.MethodPost,
Path: "/templates/import-html",
Handler: r.h.template.ImportHTML,
Group: opsGroup,
Tags: []string{"Templates"},
Summary: "Import HTML template",
Description: "Upload an .html file as multipart/form-data under \"file\" to create a template. CSS from <style> blocks is extracted into a separate stylesheet. Optional form fields: name and display_name (default: from the filename), subject (default: the document's <title>), language (default: the workspace's default language) and description.",
Options: []okapi.RouteOption{
okapi.DocResponse(201, &dto.Response[models.Template]{}),
okapi.DocResponse(409, &dto.ErrorResponseBody{}),
},
},
{
Method: http.MethodGet,
Path: "/templates/{id:int}/versions",
Handler: okapi.H(r.h.version.List),
Group: opsGroup,
Tags: []string{tagTemplateVersions},
Summary: "List template versions",
Response: &dto.Response[[]models.TemplateVersion]{},
Options: []okapi.RouteOption{
okapi.DocPathParam("id", "integer", "Template ID"),
okapi.DocResponse(404, &dto.ErrorResponseBody{}),
},
},
{
Method: http.MethodPost,
Path: "/templates/{id:int}/versions",
Handler: okapi.H(r.h.version.Create),
Group: opsGroup,
Tags: []string{tagTemplateVersions},
Summary: "Create template version",
Request: &handlers.CreateVersionRequest{},
Options: []okapi.RouteOption{
okapi.DocPathParam("id", "integer", "Template ID"),
okapi.DocResponse(201, &dto.Response[models.TemplateVersion]{}),
okapi.DocResponse(404, &dto.ErrorResponseBody{}),
},
},
{
Method: http.MethodPut,
Path: "/templates/{id:int}/versions/{versionId:int}",
Handler: okapi.H(r.h.version.Update),
Group: opsGroup,
Tags: []string{tagTemplateVersions},
Summary: "Update template version",
Request: &handlers.UpdateVersionRequest{},
Response: &dto.Response[models.TemplateVersion]{},
Options: []okapi.RouteOption{
okapi.DocPathParam("id", "integer", "Template ID"),
okapi.DocPathParam("versionId", "integer", "Version ID"),
okapi.DocResponse(404, &dto.ErrorResponseBody{}),
},
},
{
Method: http.MethodPost,
Path: "/templates/{id:int}/activate/{versionId:int}",
Handler: okapi.H(r.h.version.Activate),
Group: opsGroup,
Tags: []string{tagTemplateVersions},
Summary: "Activate template version",
Response: &dto.Response[models.Template]{},
Options: []okapi.RouteOption{
okapi.DocPathParam("id", "integer", "Template ID"),
okapi.DocPathParam("versionId", "integer", "Version ID"),
okapi.DocResponse(404, &dto.ErrorResponseBody{}),
},
},
{
Method: http.MethodDelete,
Path: "/templates/{id:int}/versions/{versionId:int}",
Handler: okapi.H(r.h.version.Delete),
Group: opsGroup,
Tags: []string{tagTemplateVersions},
Summary: "Delete template version",
Options: []okapi.RouteOption{
okapi.DocPathParam("id", "integer", "Template ID"),
okapi.DocPathParam("versionId", "integer", "Version ID"),
okapi.DocResponse(204, nil),
okapi.DocResponse(404, &dto.ErrorResponseBody{}),
},
},
{
Method: http.MethodGet,
Path: "/templates/{id:int}/versions/{versionId:int}/localizations",
Handler: okapi.H(r.h.localization.List),
Group: opsGroup,
Tags: []string{tagTemplateLocalizations},
Summary: "List localizations for a version",
Response: &dto.Response[[]models.TemplateLocalization]{},
Options: []okapi.RouteOption{
okapi.DocPathParam("id", "integer", "Template ID"),
okapi.DocPathParam("versionId", "integer", "Version ID"),
okapi.DocResponse(404, &dto.ErrorResponseBody{}),
},
},
{
Method: http.MethodPost,
Path: "/templates/{id:int}/versions/{versionId:int}/localizations",
Handler: okapi.H(r.h.localization.Create),
Group: opsGroup,
Tags: []string{tagTemplateLocalizations},
Summary: "Create localization",
Request: &handlers.CreateLocalizationRequest{},
Options: []okapi.RouteOption{
okapi.DocPathParam("id", "integer", "Template ID"),
okapi.DocPathParam("versionId", "integer", "Version ID"),
okapi.DocResponse(201, &dto.Response[models.TemplateLocalization]{}),
okapi.DocResponse(404, &dto.ErrorResponseBody{}),
okapi.DocResponse(409, &dto.ErrorResponseBody{}),
},
},
{
Method: http.MethodPut,
Path: "/localizations/{localizationId:int}",
Handler: okapi.H(r.h.localization.Update),
Group: opsGroup,
Tags: []string{tagTemplateLocalizations},
Summary: "Update localization",
Request: &handlers.UpdateLocalizationRequest{},
Response: &dto.Response[models.TemplateLocalization]{},
Options: []okapi.RouteOption{
okapi.DocPathParam("localizationId", "integer", "Localization ID"),
okapi.DocResponse(404, &dto.ErrorResponseBody{}),
},
},
{
Method: http.MethodDelete,
Path: "/localizations/{localizationId:int}",
Handler: okapi.H(r.h.localization.Delete),
Group: opsGroup,
Tags: []string{tagTemplateLocalizations},
Summary: "Delete localization",
Options: []okapi.RouteOption{
okapi.DocPathParam("localizationId", "integer", "Localization ID"),
okapi.DocResponse(204, nil),
okapi.DocResponse(404, &dto.ErrorResponseBody{}),
},
},
{
Method: http.MethodPost,
Path: "/templates/{id:int}/versions/{versionId:int}/preview",
Handler: okapi.H(r.h.localization.Preview),
Group: opsGroup,
Tags: []string{tagTemplateLocalizations},
Summary: "Preview localized template",
Description: "Render a specific language version of a template with sample data",
Request: &handlers.PreviewLocalizationRequest{},
Response: &dto.Response[handlers.PreviewResult]{},
Options: []okapi.RouteOption{
okapi.DocPathParam("id", "integer", "Template ID"),
okapi.DocPathParam("versionId", "integer", "Version ID"),
okapi.DocResponse(404, &dto.ErrorResponseBody{}),
},
},
{
Method: http.MethodPost,
Path: "/languages",
Handler: okapi.H(r.h.language.Create),
Group: opsGroup,
Tags: []string{tagLanguages},
Summary: "Create language",
Request: &handlers.CreateLanguageRequest{},
Options: []okapi.RouteOption{
okapi.DocResponse(201, &dto.Response[models.Language]{}),
okapi.DocResponse(409, &dto.ErrorResponseBody{}),
},
},
{
Method: http.MethodGet,
Path: "/languages",
Handler: okapi.H(r.h.language.List),
Group: opsGroup,
Tags: []string{tagLanguages},
Summary: "List languages",
Request: &handlers.ListRequest{},
Response: &dto.PageableResponse[models.Language]{},
},
{
Method: http.MethodPut,
Path: "/languages/{id:int}",
Handler: okapi.H(r.h.language.Update),
Group: opsGroup,
Tags: []string{tagLanguages},
Summary: "Update language",
Request: &handlers.UpdateLanguageRequest{},
Response: &dto.Response[models.Language]{},
Options: []okapi.RouteOption{
okapi.DocPathParam("id", "integer", "Language ID"),
okapi.DocResponse(404, &dto.ErrorResponseBody{}),
},
},
{
Method: http.MethodDelete,
Path: "/languages/{id:int}",
Handler: okapi.H(r.h.language.Delete),
Group: opsGroup,
Tags: []string{tagLanguages},
Summary: "Delete language",
Options: []okapi.RouteOption{
okapi.DocPathParam("id", "integer", "Language ID"),
okapi.DocResponse(204, nil),
okapi.DocResponse(404, &dto.ErrorResponseBody{}),
},
},
{
Method: http.MethodPost,
Path: "/stylesheets",
Handler: okapi.H(r.h.stylesheet.Create),
Group: opsGroup,
Tags: []string{tagUser},
Summary: "Create stylesheet",
Request: &handlers.CreateStyleSheetRequest{},
Options: []okapi.RouteOption{
okapi.DocResponse(201, &dto.Response[models.StyleSheet]{}),
okapi.DocResponse(409, &dto.ErrorResponseBody{}),
},
},
{
Method: http.MethodGet,
Path: "/stylesheets",
Handler: okapi.H(r.h.stylesheet.List),
Group: opsGroup,
Summary: "List stylesheets",
Request: &handlers.ListRequest{},
Response: &dto.PageableResponse[models.StyleSheet]{},
},
{
Method: http.MethodPut,
Path: "/stylesheets/{id:int}",
Handler: okapi.H(r.h.stylesheet.Update),
Group: opsGroup,
Summary: "Update stylesheet",
Request: &handlers.UpdateStyleSheetRequest{},
Response: &dto.Response[models.StyleSheet]{},
Options: []okapi.RouteOption{
okapi.DocPathParam("id", "integer", "StyleSheet ID"),
okapi.DocResponse(404, &dto.ErrorResponseBody{}),
},
},
{
Method: http.MethodDelete,
Path: "/stylesheets/{id:int}",
Handler: okapi.H(r.h.stylesheet.Delete),
Group: opsGroup,
Tags: []string{tagUser},
Summary: "Delete stylesheet",
Options: []okapi.RouteOption{
okapi.DocPathParam("id", "integer", "StyleSheet ID"),
okapi.DocResponse(204, nil),
okapi.DocResponse(404, &dto.ErrorResponseBody{}),
},
},
{
Method: http.MethodPost,
Path: "/smtp-servers",
Handler: okapi.H(r.h.smtp.Create),
Group: opsGroup,
Tags: []string{tagUser},
Summary: "Add SMTP server",
Request: &handlers.CreateSMTPRequest{},
Options: []okapi.RouteOption{
okapi.DocResponse(201, &dto.Response[models.SMTPServer]{}),
},
},
{
Method: http.MethodGet,
Path: "/smtp-servers",
Handler: okapi.H(r.h.smtp.List),
Group: opsGroup,
Summary: "List SMTP servers",
Request: &handlers.ListRequest{},
Response: &dto.PageableResponse[models.SMTPServer]{},
},
{
Method: http.MethodGet,
Path: pathSMTPServerByID,
Handler: okapi.H(r.h.smtp.Get),
Group: opsGroup,
Summary: "Get SMTP server",
Request: &handlers.GetSMTPRequest{},
Response: &dto.Response[models.SMTPServer]{},
Options: []okapi.RouteOption{
okapi.DocPathParam("id", "integer", "SMTP server ID"),
okapi.DocResponse(404, &dto.ErrorResponseBody{}),
},
},
{
Method: http.MethodPut,
Path: pathSMTPServerByID,
Handler: okapi.H(r.h.smtp.Update),
Group: opsGroup,
Summary: "Update SMTP server",
Request: &handlers.UpdateSMTPRequest{},
Response: &dto.Response[models.SMTPServer]{},
Options: []okapi.RouteOption{
okapi.DocPathParam("id", "integer", "SMTP server ID"),
okapi.DocResponse(404, &dto.ErrorResponseBody{}),
},
},
{
Method: http.MethodDelete,
Path: pathSMTPServerByID,
Handler: okapi.H(r.h.smtp.Delete),
Group: opsGroup,
Tags: []string{tagUser},
Summary: "Delete SMTP server",
Options: []okapi.RouteOption{
okapi.DocPathParam("id", "integer", "SMTP server ID"),
okapi.DocResponse(204, nil),
okapi.DocResponse(404, &dto.ErrorResponseBody{}),
},
},
{
Method: http.MethodPost,
Path: "/smtp-servers/{id:int}/test",
Handler: okapi.H(r.h.smtp.Test),
Group: opsGroup,
Summary: "Test SMTP server connection",
Response: &dto.Response[dto.MessageData]{},
Options: []okapi.RouteOption{
okapi.DocPathParam("id", "integer", "SMTP server ID"),
okapi.DocResponse(404, &dto.ErrorResponseBody{}),
},
},
{
Method: http.MethodPost,
Path: pathWebhooks,
Handler: okapi.H(r.h.webhook.Create),
Group: opsGroup,
Tags: []string{tagUser},
OperationId: "workspace-create-webhook",
Summary: "Create webhook",
Request: &handlers.CreateWebhookRequest{},
Options: []okapi.RouteOption{
okapi.DocResponse(201, &dto.Response[models.Webhook]{}),
},
},
{
Method: http.MethodGet,
Path: pathWebhooks,
Handler: okapi.H(r.h.webhook.List),
Group: opsGroup,
OperationId: "workspace-list-webhooks",
Summary: "List webhooks",
Request: &handlers.ListRequest{},
Response: &dto.PageableResponse[models.Webhook]{},
},
{
Method: http.MethodDelete,
Path: "/webhooks/{id:int}",
Handler: okapi.H(r.h.webhook.Delete),
Group: opsGroup,
Tags: []string{tagUser},
OperationId: "workspace-delete-webhook",
Summary: "Delete webhook",
Options: []okapi.RouteOption{
okapi.DocPathParam("id", "integer", "Webhook ID"),
okapi.DocResponse(204, nil),
okapi.DocResponse(404, &dto.ErrorResponseBody{}),
},
},
{
Method: http.MethodGet,
Path: "/webhook-deliveries",
Handler: okapi.H(r.h.webhookDelivery.List),
Group: opsGroup,
OperationId: "workspace-list-webhook-deliveries",
Summary: "List webhook deliveries",
Request: &handlers.ListRequest{},
Response: &dto.PageableResponse[models.WebhookDelivery]{},
},
{
Method: http.MethodPost,
Path: pathDomains,
Handler: okapi.H(r.h.domain.Create),
Group: opsGroup,
Summary: "Add domain",
Description: "Register a domain for verification. Returns the DNS records that must be configured.",
Request: &handlers.CreateDomainRequest{},
Options: []okapi.RouteOption{
okapi.DocResponse(201, &dto.Response[handlers.DomainWithRecords]{}),
okapi.DocResponse(409, &dto.ErrorResponseBody{}),
},
},
{
Method: http.MethodGet,
Path: pathDomains,
Handler: okapi.H(r.h.domain.List),
Group: opsGroup,
Summary: "List domains",
Request: &handlers.ListRequest{},
Response: &dto.PageableResponse[models.Domain]{},
},
{
Method: http.MethodGet,
Path: pathDomainByID,
Handler: okapi.H(r.h.domain.Get),
Group: opsGroup,
Summary: "Get domain details",
Response: &dto.Response[handlers.DomainWithRecords]{},
Options: []okapi.RouteOption{
okapi.DocPathParam("id", "integer", "Domain ID"),
okapi.DocResponse(404, &dto.ErrorResponseBody{}),
},
},
{
Method: http.MethodDelete,
Path: pathDomainByID,
Handler: okapi.H(r.h.domain.Delete),
Group: opsGroup,
Tags: []string{tagUser},
Summary: "Delete domain",
Options: []okapi.RouteOption{
okapi.DocPathParam("id", "integer", "Domain ID"),
okapi.DocResponse(204, nil),
okapi.DocResponse(404, &dto.ErrorResponseBody{}),
},
},
{
Method: http.MethodPost,
Path: pathDomainByID + "/verify",
Handler: okapi.H(r.h.domain.Verify),
Group: opsGroup,
Summary: "Verify domain DNS records",
Description: "Check DNS records (SPF, DKIM, DMARC) for the domain",
Response: &dto.Response[any]{},
Options: []okapi.RouteOption{
okapi.DocPathParam("id", "integer", "Domain ID"),
okapi.DocResponse(404, &dto.ErrorResponseBody{}),
},
},
{
Method: http.MethodPost,
Path: pathBounces,
Handler: okapi.H(r.h.bounce.Record),
Group: opsGroup,
Summary: "Record a bounce",
Description: "Record a bounce or complaint. Hard bounces and complaints auto-suppress the recipient.",
Request: &handlers.RecordBounceRequest{},
Options: []okapi.RouteOption{
okapi.DocResponse(201, &dto.Response[models.Bounce]{}),
},
},
{
Method: http.MethodGet,
Path: pathBounces,
Handler: okapi.H(r.h.bounce.List),
Group: opsGroup,
OperationId: "workspace-list-bounces",
Summary: "List bounces",
Request: &handlers.ListRequest{},
Response: &dto.PageableResponse[models.Bounce]{},
},
{
Method: http.MethodPost,
Path: pathSuppressions,
Handler: okapi.H(r.h.suppression.Create),
Group: opsGroup,
Tags: []string{tagUser},
Summary: "Add to suppression list",
Request: &handlers.CreateSuppressionRequest{},
Options: []okapi.RouteOption{
okapi.DocResponse(201, &dto.Response[models.Suppression]{}),
okapi.DocResponse(409, &dto.ErrorResponseBody{}),
},
},
{
Method: http.MethodGet,
Path: pathSuppressions,
Handler: okapi.H(r.h.suppression.List),
Group: opsGroup,
Summary: "List suppressed emails",
Request: &handlers.ListSuppressionsRequest{},
Response: &dto.PageableResponse[models.Suppression]{},
},
{
Method: http.MethodDelete,
Path: pathSuppressions,
Handler: okapi.H(r.h.suppression.Delete),
Group: opsGroup,
Tags: []string{tagUser},
Summary: "Remove from suppression list",
Request: &handlers.DeleteSuppressionRequest{},
Options: []okapi.RouteOption{
okapi.DocResponse(204, nil),
},
},
{
Method: http.MethodPost,
Path: "/unsubscribe-lists",
Handler: okapi.H(r.h.unsubscribeList.Create),
Group: opsGroup,
Tags: []string{tagUnsubscribeLists},
Summary: "Create unsubscribe list",
Request: &handlers.CreateUnsubscribeListRequest{},
Options: []okapi.RouteOption{
okapi.DocResponse(201, &dto.Response[models.UnsubscribeList]{}),
okapi.DocResponse(409, &dto.ErrorResponseBody{}),
},
},
{
Method: http.MethodGet,
Path: "/unsubscribe-lists",
Handler: okapi.H(r.h.unsubscribeList.List),
Group: opsGroup,
Tags: []string{tagUnsubscribeLists},
Summary: "List unsubscribe lists",
Request: &handlers.ListRequest{},
Response: &dto.PageableResponse[models.UnsubscribeList]{},
},
{
Method: http.MethodGet,
Path: pathUnsubscribeListByID,
Handler: okapi.H(r.h.unsubscribeList.Get),
Group: opsGroup,
Tags: []string{tagUnsubscribeLists},
Summary: "Get unsubscribe list",
Response: &dto.Response[models.UnsubscribeList]{},
Options: []okapi.RouteOption{okapi.DocPathParam("id", "integer", "List ID")},
},
{
Method: http.MethodPut,
Path: pathUnsubscribeListByID,
Handler: okapi.H(r.h.unsubscribeList.Update),
Group: opsGroup,
Tags: []string{tagUnsubscribeLists},
Summary: "Update unsubscribe list",
Request: &handlers.UpdateUnsubscribeListRequest{},
Response: &dto.Response[models.UnsubscribeList]{},
Options: []okapi.RouteOption{okapi.DocPathParam("id", "integer", "List ID")},
},
{
Method: http.MethodDelete,
Path: pathUnsubscribeListByID,
Handler: okapi.H(r.h.unsubscribeList.Delete),
Group: opsGroup,
Tags: []string{tagUnsubscribeLists},
Summary: "Delete unsubscribe list",
Options: []okapi.RouteOption{okapi.DocPathParam("id", "integer", "List ID"), okapi.DocResponse(204, nil)},
},
{
Method: http.MethodGet,
Path: "/contacts",
Handler: okapi.H(r.h.contact.List),
Group: opsGroup,
Summary: "List contacts",
Description: "List all recipient email addresses with sent/failed counts. Use the search query parameter to filter by email or name.",
Request: &handlers.ListContactsRequest{},
Response: &dto.PageableResponse[models.Contact]{},
},
{
Method: http.MethodGet,
Path: "/contacts/{id:int}",
Handler: okapi.H(r.h.contact.Get),
Group: opsGroup,
Summary: "Get contact details",
Description: "Get a single contact by ID with suppression status",
Request: &handlers.GetByIDRequest{},
Response: &dto.Response[models.Contact]{},
},
{
Method: http.MethodPost,
Path: "/subscribers",
Handler: okapi.H(r.h.subscriber.Create),
Group: opsGroup,
Tags: []string{tagSubscribers},
Summary: "Create subscriber",
Request: &handlers.CreateSubscriberRequest{},
Options: []okapi.RouteOption{okapi.DocResponse(201, &dto.Response[models.Subscriber]{})},
},
{
Method: http.MethodGet,
Path: "/subscribers",
Handler: okapi.H(r.h.subscriber.List),
Group: opsGroup,
Tags: []string{tagSubscribers},
Summary: "List subscribers",
Request: &handlers.ListSubscribersRequest{},
Response: &dto.PageableResponse[models.Subscriber]{},
},
{
Method: http.MethodGet,
Path: pathSubscriberByID,
Handler: okapi.H(r.h.subscriber.Get),
Group: opsGroup,
Tags: []string{tagSubscribers},
Summary: "Get subscriber",
Response: &dto.Response[models.Subscriber]{},
Options: []okapi.RouteOption{okapi.DocPathParam("id", "integer", "Subscriber ID")},
},
{
Method: http.MethodPut,
Path: pathSubscriberByID,
Handler: okapi.H(r.h.subscriber.Update),
Group: opsGroup,
Tags: []string{tagSubscribers},
Summary: "Update subscriber",
Request: &handlers.UpdateSubscriberRequest{},
Response: &dto.Response[models.Subscriber]{},
Options: []okapi.RouteOption{okapi.DocPathParam("id", "integer", "Subscriber ID")},
},
{
Method: http.MethodDelete,
Path: pathSubscriberByID,
Handler: okapi.H(r.h.subscriber.Delete),
Group: opsGroup,
Tags: []string{tagSubscribers},
Summary: "Delete subscriber",
Options: []okapi.RouteOption{okapi.DocPathParam("id", "integer", "Subscriber ID"), okapi.DocResponse(204, nil)},
},
{
Method: http.MethodPost,
Path: "/subscribers/import/json",
Handler: okapi.H(r.h.subscriber.BulkImportJSON),
Group: opsGroup,
Tags: []string{tagSubscribers},
Summary: "Bulk import subscribers (JSON)",
Request: &handlers.BulkImportSubscribersRequest{},
Response: &dto.Response[handlers.BulkImportResult]{},
},
{
Method: http.MethodPost,
Path: "/subscribers/import/csv",
Handler: r.h.subscriber.BulkImportCSV,
Group: opsGroup,
Tags: []string{tagSubscribers},
Summary: "Bulk import subscribers (CSV)",
Description: "Upload a CSV file with optional column_mapping JSON field",
Response: &dto.Response[handlers.BulkImportResult]{},
},
{
Method: http.MethodPost,
Path: "/subscriber-lists",
Handler: okapi.H(r.h.subscriberList.Create),
Group: opsGroup,
Tags: []string{tagSubscriberLists},
Summary: "Create subscriber list",
Request: &handlers.CreateSubscriberListRequest{},
Options: []okapi.RouteOption{okapi.DocResponse(201, &dto.Response[models.SubscriberList]{})},
},
{
Method: http.MethodGet,
Path: "/subscriber-lists",
Handler: okapi.H(r.h.subscriberList.List),
Group: opsGroup,
Tags: []string{tagSubscriberLists},
Summary: "List subscriber lists",
Request: &handlers.ListRequest{},
Response: &dto.PageableResponse[handlers.SubscriberListWithCount]{},
},
{
Method: http.MethodGet,
Path: pathSubscriberListByID,
Handler: okapi.H(r.h.subscriberList.Get),
Group: opsGroup,
Tags: []string{tagSubscriberLists},
Summary: "Get subscriber list",
Response: &dto.Response[handlers.SubscriberListWithCount]{},
Options: []okapi.RouteOption{okapi.DocPathParam("id", "integer", "List ID")},
},
{
Method: http.MethodPut,
Path: pathSubscriberListByID,
Handler: okapi.H(r.h.subscriberList.Update),
Group: opsGroup,
Tags: []string{tagSubscriberLists},
Summary: "Update subscriber list",
Request: &handlers.UpdateSubscriberListRequest{},
Response: &dto.Response[models.SubscriberList]{},
Options: []okapi.RouteOption{okapi.DocPathParam("id", "integer", "List ID")},
},
{
Method: http.MethodDelete,
Path: pathSubscriberListByID,
Handler: okapi.H(r.h.subscriberList.Delete),
Group: opsGroup,
Tags: []string{tagSubscriberLists},
Summary: "Delete subscriber list",
Options: []okapi.RouteOption{okapi.DocPathParam("id", "integer", "List ID"), okapi.DocResponse(204, nil)},
},
{
Method: http.MethodPost,
Path: pathSubscriberListMembers,
Handler: okapi.H(r.h.subscriberList.AddMember),
Group: opsGroup,
Tags: []string{tagSubscriberLists},
Summary: "Add subscriber to list",
Request: &handlers.AddSubscriberToListRequest{},
Response: &dto.Response[okapi.M]{},
Options: []okapi.RouteOption{okapi.DocPathParam("id", "integer", "List ID")},
},
{
Method: http.MethodDelete,
Path: pathSubscriberListMembers,
Handler: okapi.H(r.h.subscriberList.RemoveMember),
Group: opsGroup,
Tags: []string{tagSubscriberLists},
Summary: "Remove subscriber from list",
Request: &handlers.RemoveSubscriberFromListRequest{},
Response: &dto.Response[okapi.M]{},
Options: []okapi.RouteOption{okapi.DocPathParam("id", "integer", "List ID")},
},
{
Method: http.MethodGet,
Path: pathSubscriberListMembers,
Handler: okapi.H(r.h.subscriberList.ListMembers),
Group: opsGroup,
Tags: []string{tagSubscriberLists},
Summary: "List members of subscriber list",
Request: &handlers.ListSubscriberListMembersRequest{},
Response: &dto.PageableResponse[models.Subscriber]{},
Options: []okapi.RouteOption{okapi.DocPathParam("id", "integer", "List ID")},
},
{
Method: http.MethodPost,
Path: "/subscriber-lists/preview-segment",
Handler: okapi.H(r.h.subscriberList.PreviewSegment),
Group: opsGroup,
Tags: []string{tagSubscriberLists},
Summary: "Preview segment count",
Description: "Evaluate filter rules and return the number of matching subscribers",
Request: &handlers.PreviewSegmentRequest{},
Response: &dto.Response[okapi.M]{},
},
{
Method: http.MethodPost,
Path: "/subscriber-lists/{id:int}/unsubscribe",
Handler: okapi.H(r.h.subscriberList.UnsubscribeByEmail),
Group: opsGroup,
Tags: []string{tagSubscriberLists},
OperationId: "workspace-unsubscribe-an-email-from-a-list",
Summary: "Unsubscribe an email from a list",
Description: "API-key-accessible list opt-out. Idempotent. Does not change global subscriber status.",
Request: &handlers.ListUnsubscribeByEmailRequest{},
Response: &dto.Response[handlers.ListSubscribeResponse]{},
Options: []okapi.RouteOption{okapi.DocPathParam("id", "integer", "List ID")},
},
{
Method: http.MethodPost,
Path: "/subscriber-lists/{id:int}/resubscribe",
Handler: okapi.H(r.h.subscriberList.ResubscribeByEmail),
Group: opsGroup,
Tags: []string{tagSubscriberLists},
OperationId: "workspace-re-subscribe-an-email-to-a-list",
Summary: "Re-subscribe an email to a list",
Description: "Reverses a list-scoped opt-out and re-adds to the list (static lists). Idempotent.",
Request: &handlers.ListResubscribeByEmailRequest{},
Response: &dto.Response[handlers.ListSubscribeResponse]{},
Options: []okapi.RouteOption{okapi.DocPathParam("id", "integer", "List ID")},
},
{
Method: http.MethodPost,
Path: "/campaigns",
Handler: okapi.H(r.h.campaign.Create),
Group: opsGroup,
Tags: []string{tagCampaigns},
Summary: "Create campaign",
Request: &handlers.CreateCampaignRequest{},
Options: []okapi.RouteOption{okapi.DocResponse(201, &dto.Response[models.Campaign]{})},
},
{
Method: http.MethodGet,
Path: "/campaigns",
Handler: okapi.H(r.h.campaign.List),
Group: opsGroup,
Tags: []string{tagCampaigns},
Summary: "List campaigns",
Request: &handlers.ListCampaignsRequest{},
Response: &dto.PageableResponse[handlers.CampaignWithStats]{},
},
{
Method: http.MethodGet,
Path: pathCampaignByID,
Handler: okapi.H(r.h.campaign.Get),
Group: opsGroup,
Tags: []string{tagCampaigns},
Summary: "Get campaign",
Response: &dto.Response[handlers.CampaignWithStats]{},
Options: []okapi.RouteOption{okapi.DocPathParam("id", "integer", "Campaign ID")},
},
{
Method: http.MethodPut,
Path: pathCampaignByID,
Handler: okapi.H(r.h.campaign.Update),
Group: opsGroup,
Tags: []string{tagCampaigns},
Summary: "Update campaign",
Request: &handlers.UpdateCampaignRequest{},
Response: &dto.Response[models.Campaign]{},
Options: []okapi.RouteOption{okapi.DocPathParam("id", "integer", "Campaign ID")},
},
{
Method: http.MethodDelete,
Path: pathCampaignByID,
Handler: okapi.H(r.h.campaign.Delete),
Group: opsGroup,
Tags: []string{tagCampaigns},
Summary: "Delete campaign",
Options: []okapi.RouteOption{okapi.DocPathParam("id", "integer", "Campaign ID"), okapi.DocResponse(204, nil)},
},
{
Method: http.MethodPost,
Path: "/campaigns/{id:int}/send",
Handler: okapi.H(r.h.campaign.Send),
Group: opsGroup,
Tags: []string{tagCampaigns},
Summary: "Send campaign",
Response: &dto.Response[models.Campaign]{},
Options: []okapi.RouteOption{okapi.DocPathParam("id", "integer", "Campaign ID")},
},
{
Method: http.MethodPost,
Path: "/campaigns/{id:int}/pause",
Handler: okapi.H(r.h.campaign.Pause),
Group: opsGroup,
Tags: []string{tagCampaigns},
Summary: "Pause campaign",
Response: &dto.Response[models.Campaign]{},
Options: []okapi.RouteOption{okapi.DocPathParam("id", "integer", "Campaign ID")},
},
{
Method: http.MethodPost,
Path: "/campaigns/{id:int}/resume",
Handler: okapi.H(r.h.campaign.Resume),
Group: opsGroup,
Tags: []string{tagCampaigns},
Summary: "Resume campaign",
Response: &dto.Response[models.Campaign]{},
Options: []okapi.RouteOption{okapi.DocPathParam("id", "integer", "Campaign ID")},
},
{
Method: http.MethodPost,
Path: "/campaigns/{id:int}/cancel",
Handler: okapi.H(r.h.campaign.Cancel),
Group: opsGroup,
Tags: []string{tagCampaigns},
Summary: "Cancel campaign",
Response: &dto.Response[models.Campaign]{},
Options: []okapi.RouteOption{okapi.DocPathParam("id", "integer", "Campaign ID")},
},
{
Method: http.MethodPost,
Path: "/campaigns/{id:int}/duplicate",
Handler: okapi.H(r.h.campaign.Duplicate),
Group: opsGroup,
Tags: []string{tagCampaigns},
Summary: "Duplicate campaign",
Response: &dto.Response[models.Campaign]{},
Options: []okapi.RouteOption{okapi.DocPathParam("id", "integer", "Campaign ID")},
},
{
Method: http.MethodGet,
Path: "/campaigns/{id:int}/messages",
Handler: okapi.H(r.h.campaign.ListMessages),
Group: opsGroup,
Tags: []string{tagCampaigns},
Summary: "List campaign messages",
Request: &handlers.ListCampaignMessagesRequest{},
Response: &dto.PageableResponse[models.CampaignMessage]{},
Options: []okapi.RouteOption{okapi.DocPathParam("id", "integer", "Campaign ID")},
},
}...)
return routes
}