From 81f1205c0948495ca516f5c262059996475ed572 Mon Sep 17 00:00:00 2001 From: Vilen Topchii <32271530+vtopc@users.noreply.github.com> Date: Thu, 2 Jan 2025 20:06:06 +0200 Subject: [PATCH] Moved the API version out of the base URL --- README.md | 4 ++-- analytics.go | 2 +- bounces.go | 12 ++++++------ domains.go | 32 ++++++++++++++++---------------- events.go | 2 +- exports.go | 8 ++++---- ips.go | 10 +++++----- limits.go | 2 +- mailgun.go | 38 ++++++++++++++++++++++---------------- mailing_lists.go | 10 +++++----- messages.go | 2 +- messages_v5.go | 2 +- routes.go | 10 +++++----- spam_complaints.go | 10 +++++----- tags.go | 6 +++--- template.go | 10 +++++----- template_versions.go | 10 +++++----- unsubscribes.go | 12 ++++++------ 18 files changed, 94 insertions(+), 88 deletions(-) diff --git a/README.md b/README.md index beb7485..4ef61c7 100644 --- a/README.md +++ b/README.md @@ -38,8 +38,8 @@ func main() { // Create an instance of the Mailgun Client mg := mailgun.NewMailgun(privateAPIKey) - //When you have an EU-domain, you must specify the endpoint: - //mg.SetAPIBase("https://api.eu.mailgun.net/v3") + // When you have an EU-domain, you must specify the endpoint: + // mg.SetAPIBase("https://api.eu.mailgun.net") sender := "sender@example.com" subject := "Fancy subject!" diff --git a/analytics.go b/analytics.go index 7a421cf..bbdc4ff 100644 --- a/analytics.go +++ b/analytics.go @@ -43,7 +43,7 @@ func (mg *MailgunImpl) ListMetrics(opts MetricsOptions) (*MetricsIterator, error opts.Pagination.Limit = 10 } - req := newHTTPRequest(generateApiUrl(mg, metricsEndpoint)) + req := newHTTPRequest(generateApiUrl(mg, 1, metricsEndpoint)) req.setClient(mg.HTTPClient()) req.setBasicAuth(basicAuthUser, mg.APIKey()) diff --git a/bounces.go b/bounces.go index 405d861..cba6713 100644 --- a/bounces.go +++ b/bounces.go @@ -35,7 +35,7 @@ type bouncesListResponse struct { // and the slice of bounces specified, if successful. // Note that the length of the slice may be smaller than the total number of bounces. func (mg *MailgunImpl) ListBounces(domain string, opts *ListOptions) *BouncesIterator { - r := newHTTPRequest(generateApiUrlWithDomain(mg, bouncesEndpoint, domain)) + r := newHTTPRequest(generateApiV3UrlWithDomain(mg, bouncesEndpoint, domain)) r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) if opts != nil { @@ -147,7 +147,7 @@ func (ci *BouncesIterator) fetch(ctx context.Context, url string) error { // GetBounce retrieves a single bounce record, if any exist, for the given recipient address. func (mg *MailgunImpl) GetBounce(ctx context.Context, domain, address string) (Bounce, error) { - r := newHTTPRequest(generateApiUrlWithDomain(mg, bouncesEndpoint, domain) + "/" + address) + r := newHTTPRequest(generateApiV3UrlWithDomain(mg, bouncesEndpoint, domain) + "/" + address) r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) @@ -173,7 +173,7 @@ func (mg *MailgunImpl) GetBounce(ctx context.Context, domain, address string) (B // Note that both code and error exist as strings, even though // code will report as a number. func (mg *MailgunImpl) AddBounce(ctx context.Context, domain, address, code, bounceError string) error { - r := newHTTPRequest(generateApiUrlWithDomain(mg, bouncesEndpoint, domain)) + r := newHTTPRequest(generateApiV3UrlWithDomain(mg, bouncesEndpoint, domain)) r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) @@ -191,7 +191,7 @@ func (mg *MailgunImpl) AddBounce(ctx context.Context, domain, address, code, bou // Add Bounces adds a list of bounces to the bounce list func (mg *MailgunImpl) AddBounces(ctx context.Context, domain string, bounces []Bounce) error { - r := newHTTPRequest(generateApiUrlWithDomain(mg, bouncesEndpoint, domain)) + r := newHTTPRequest(generateApiV3UrlWithDomain(mg, bouncesEndpoint, domain)) r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) @@ -203,7 +203,7 @@ func (mg *MailgunImpl) AddBounces(ctx context.Context, domain string, bounces [] // DeleteBounce removes all bounces associted with the provided e-mail address. func (mg *MailgunImpl) DeleteBounce(ctx context.Context, domain, address string) error { - r := newHTTPRequest(generateApiUrlWithDomain(mg, bouncesEndpoint, domain) + "/" + address) + r := newHTTPRequest(generateApiV3UrlWithDomain(mg, bouncesEndpoint, domain) + "/" + address) r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) _, err := makeDeleteRequest(ctx, r) @@ -212,7 +212,7 @@ func (mg *MailgunImpl) DeleteBounce(ctx context.Context, domain, address string) // DeleteBounceList removes all bounces in the bounce list func (mg *MailgunImpl) DeleteBounceList(ctx context.Context, domain string) error { - r := newHTTPRequest(generateApiUrlWithDomain(mg, bouncesEndpoint, domain)) + r := newHTTPRequest(generateApiV3UrlWithDomain(mg, bouncesEndpoint, domain)) r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) _, err := makeDeleteRequest(ctx, r) diff --git a/domains.go b/domains.go index cb01562..15acac5 100644 --- a/domains.go +++ b/domains.go @@ -92,7 +92,7 @@ func (mg *MailgunImpl) ListDomains(opts *ListOptions) *DomainsIterator { } return &DomainsIterator{ mg: mg, - url: generateApiUrl(mg, domainsEndpoint), + url: generateApiUrl(mg, 3, domainsEndpoint), domainsListResponse: domainsListResponse{TotalCount: -1}, limit: limit, } @@ -233,7 +233,7 @@ func (ri *DomainsIterator) fetch(ctx context.Context, skip, limit int) error { // GetDomain retrieves detailed information about the named domain. func (mg *MailgunImpl) GetDomain(ctx context.Context, domain string) (DomainResponse, error) { - r := newHTTPRequest(generateApiUrl(mg, domainsEndpoint) + "/" + domain) + r := newHTTPRequest(generateApiUrl(mg, 3, domainsEndpoint) + "/" + domain) r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) var resp DomainResponse @@ -242,7 +242,7 @@ func (mg *MailgunImpl) GetDomain(ctx context.Context, domain string) (DomainResp } func (mg *MailgunImpl) VerifyDomain(ctx context.Context, domain string) (string, error) { - r := newHTTPRequest(generateApiUrl(mg, domainsEndpoint) + "/" + domain + "/verify") + r := newHTTPRequest(generateApiUrl(mg, 3, domainsEndpoint) + "/" + domain + "/verify") r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) @@ -254,7 +254,7 @@ func (mg *MailgunImpl) VerifyDomain(ctx context.Context, domain string) (string, // VerifyAndReturnDomain verifies & retrieves detailed information about the named domain. func (mg *MailgunImpl) VerifyAndReturnDomain(ctx context.Context, domain string) (DomainResponse, error) { - r := newHTTPRequest(generateApiUrl(mg, domainsEndpoint) + "/" + domain + "/verify") + r := newHTTPRequest(generateApiUrl(mg, 3, domainsEndpoint) + "/" + domain + "/verify") r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) @@ -282,7 +282,7 @@ type CreateDomainOptions struct { // The wildcard parameter instructs Mailgun to treat all subdomains of this domain uniformly if true, // and as different domains if false. func (mg *MailgunImpl) CreateDomain(ctx context.Context, name string, opts *CreateDomainOptions) (DomainResponse, error) { - r := newHTTPRequest(generateApiUrl(mg, domainsEndpoint)) + r := newHTTPRequest(generateApiUrl(mg, 3, domainsEndpoint)) r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) @@ -319,7 +319,7 @@ func (mg *MailgunImpl) CreateDomain(ctx context.Context, name string, opts *Crea // GetDomainConnection returns delivery connection settings for the defined domain func (mg *MailgunImpl) GetDomainConnection(ctx context.Context, domain string) (DomainConnection, error) { - r := newHTTPRequest(generateApiUrl(mg, domainsEndpoint) + "/" + domain + "/connection") + r := newHTTPRequest(generateApiUrl(mg, 3, domainsEndpoint) + "/" + domain + "/connection") r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) var resp domainConnectionResponse @@ -327,9 +327,9 @@ func (mg *MailgunImpl) GetDomainConnection(ctx context.Context, domain string) ( return resp.Connection, err } -// Updates the specified delivery connection settings for the defined domain +// UpdateDomainConnection updates the specified delivery connection settings for the defined domain func (mg *MailgunImpl) UpdateDomainConnection(ctx context.Context, domain string, settings DomainConnection) error { - r := newHTTPRequest(generateApiUrl(mg, domainsEndpoint) + "/" + domain + "/connection") + r := newHTTPRequest(generateApiUrl(mg, 3, domainsEndpoint) + "/" + domain + "/connection") r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) @@ -342,7 +342,7 @@ func (mg *MailgunImpl) UpdateDomainConnection(ctx context.Context, domain string // DeleteDomain instructs Mailgun to dispose of the named domain name func (mg *MailgunImpl) DeleteDomain(ctx context.Context, name string) error { - r := newHTTPRequest(generateApiUrl(mg, domainsEndpoint) + "/" + name) + r := newHTTPRequest(generateApiUrl(mg, 3, domainsEndpoint) + "/" + name) r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) _, err := makeDeleteRequest(ctx, r) @@ -351,7 +351,7 @@ func (mg *MailgunImpl) DeleteDomain(ctx context.Context, name string) error { // GetDomainTracking returns tracking settings for a domain func (mg *MailgunImpl) GetDomainTracking(ctx context.Context, domain string) (DomainTracking, error) { - r := newHTTPRequest(generateApiUrl(mg, domainsEndpoint) + "/" + domain + "/tracking") + r := newHTTPRequest(generateApiUrl(mg, 3, domainsEndpoint) + "/" + domain + "/tracking") r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) var resp domainTrackingResponse @@ -360,7 +360,7 @@ func (mg *MailgunImpl) GetDomainTracking(ctx context.Context, domain string) (Do } func (mg *MailgunImpl) UpdateClickTracking(ctx context.Context, domain, active string) error { - r := newHTTPRequest(generateApiUrl(mg, domainsEndpoint) + "/" + domain + "/tracking/click") + r := newHTTPRequest(generateApiUrl(mg, 3, domainsEndpoint) + "/" + domain + "/tracking/click") r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) @@ -371,7 +371,7 @@ func (mg *MailgunImpl) UpdateClickTracking(ctx context.Context, domain, active s } func (mg *MailgunImpl) UpdateUnsubscribeTracking(ctx context.Context, domain, active, htmlFooter, textFooter string) error { - r := newHTTPRequest(generateApiUrl(mg, domainsEndpoint) + "/" + domain + "/tracking/unsubscribe") + r := newHTTPRequest(generateApiUrl(mg, 3, domainsEndpoint) + "/" + domain + "/tracking/unsubscribe") r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) @@ -384,7 +384,7 @@ func (mg *MailgunImpl) UpdateUnsubscribeTracking(ctx context.Context, domain, ac } func (mg *MailgunImpl) UpdateOpenTracking(ctx context.Context, domain, active string) error { - r := newHTTPRequest(generateApiUrl(mg, domainsEndpoint) + "/" + domain + "/tracking/open") + r := newHTTPRequest(generateApiUrl(mg, 3, domainsEndpoint) + "/" + domain + "/tracking/open") r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) @@ -396,7 +396,7 @@ func (mg *MailgunImpl) UpdateOpenTracking(ctx context.Context, domain, active st // Update the DKIM selector for a domain func (mg *MailgunImpl) UpdateDomainDkimSelector(ctx context.Context, domain, dkimSelector string) error { - r := newHTTPRequest(generateApiUrl(mg, domainsEndpoint) + "/" + domain + "/dkim_selector") + r := newHTTPRequest(generateApiUrl(mg, 3, domainsEndpoint) + "/" + domain + "/dkim_selector") r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) @@ -408,7 +408,7 @@ func (mg *MailgunImpl) UpdateDomainDkimSelector(ctx context.Context, domain, dki // Update the CNAME used for tracking opens and clicks func (mg *MailgunImpl) UpdateDomainTrackingWebPrefix(ctx context.Context, domain, webPrefix string) error { - r := newHTTPRequest(generateApiUrl(mg, domainsEndpoint) + "/" + domain + "/web_prefix") + r := newHTTPRequest(generateApiUrl(mg, 3, domainsEndpoint) + "/" + domain + "/web_prefix") r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) @@ -426,7 +426,7 @@ type UpdateDomainOptions struct { // UpdateDomain updates a domain's attributes. // Currently only the web_scheme update is supported, spam_action and wildcard are to be added. func (mg *MailgunImpl) UpdateDomain(ctx context.Context, name string, opts *UpdateDomainOptions) error { - r := newHTTPRequest(generateApiUrl(mg, domainsEndpoint) + "/" + name) + r := newHTTPRequest(generateApiUrl(mg, 3, domainsEndpoint) + "/" + name) r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) diff --git a/events.go b/events.go index d17e63a..ee311d8 100644 --- a/events.go +++ b/events.go @@ -38,7 +38,7 @@ type EventIterator struct { // ListEvents creates a new iterator to fetch a page of events from the events api func (mg *MailgunImpl) ListEvents(domain string, opts *ListEventOptions) *EventIterator { - url := generateApiUrlWithDomain(mg, eventsEndpoint, domain) + url := generateApiV3UrlWithDomain(mg, eventsEndpoint, domain) return mg.listEvents(url, opts) } diff --git a/exports.go b/exports.go index dc0a4db..c222374 100644 --- a/exports.go +++ b/exports.go @@ -19,7 +19,7 @@ type Export struct { // Create an export based on the URL given func (mg *MailgunImpl) CreateExport(ctx context.Context, url string) error { - r := newHTTPRequest(generateApiUrl(mg, exportsEndpoint)) + r := newHTTPRequest(generateApiUrl(mg, 3, exportsEndpoint)) r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) @@ -31,7 +31,7 @@ func (mg *MailgunImpl) CreateExport(ctx context.Context, url string) error { // List all exports created within the past 24 hours func (mg *MailgunImpl) ListExports(ctx context.Context, url string) ([]Export, error) { - r := newHTTPRequest(generateApiUrl(mg, exportsEndpoint)) + r := newHTTPRequest(generateApiUrl(mg, 3, exportsEndpoint)) r.setClient(mg.HTTPClient()) if url != "" { r.addParameter("url", url) @@ -52,7 +52,7 @@ func (mg *MailgunImpl) ListExports(ctx context.Context, url string) ([]Export, e // GetExport gets an export by id func (mg *MailgunImpl) GetExport(ctx context.Context, id string) (Export, error) { - r := newHTTPRequest(generateApiUrl(mg, exportsEndpoint) + "/" + id) + r := newHTTPRequest(generateApiUrl(mg, 3, exportsEndpoint) + "/" + id) r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) var resp Export @@ -63,7 +63,7 @@ func (mg *MailgunImpl) GetExport(ctx context.Context, id string) (Export, error) // Download an export by ID. This will respond with a '302 Moved' // with the Location header of temporary S3 URL if it is available. func (mg *MailgunImpl) GetExportLink(ctx context.Context, id string) (string, error) { - r := newHTTPRequest(generateApiUrl(mg, exportsEndpoint) + "/" + id + "/download_url") + r := newHTTPRequest(generateApiUrl(mg, 3, exportsEndpoint) + "/" + id + "/download_url") c := mg.HTTPClient() // Ensure the client doesn't attempt to retry diff --git a/ips.go b/ips.go index 6cb37fb..7a94457 100644 --- a/ips.go +++ b/ips.go @@ -20,7 +20,7 @@ type okResp struct { // ListIPS returns a list of IPs assigned to your account func (mg *MailgunImpl) ListIPS(ctx context.Context, dedicated bool) ([]IPAddress, error) { - r := newHTTPRequest(generateApiUrl(mg, ipsEndpoint)) + r := newHTTPRequest(generateApiUrl(mg, 3, ipsEndpoint)) r.setClient(mg.HTTPClient()) if dedicated { r.addParameter("dedicated", "true") @@ -40,7 +40,7 @@ func (mg *MailgunImpl) ListIPS(ctx context.Context, dedicated bool) ([]IPAddress // GetIP returns information about the specified IP func (mg *MailgunImpl) GetIP(ctx context.Context, ip string) (IPAddress, error) { - r := newHTTPRequest(generateApiUrl(mg, ipsEndpoint) + "/" + ip) + r := newHTTPRequest(generateApiUrl(mg, 3, ipsEndpoint) + "/" + ip) r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) var resp IPAddress @@ -50,7 +50,7 @@ func (mg *MailgunImpl) GetIP(ctx context.Context, ip string) (IPAddress, error) // ListDomainIPS returns a list of IPs currently assigned to the specified domain. func (mg *MailgunImpl) ListDomainIPS(ctx context.Context, domain string) ([]IPAddress, error) { - r := newHTTPRequest(generateApiUrl(mg, domainsEndpoint) + "/" + domain + "/ips") + r := newHTTPRequest(generateApiUrl(mg, 3, domainsEndpoint) + "/" + domain + "/ips") r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) @@ -67,7 +67,7 @@ func (mg *MailgunImpl) ListDomainIPS(ctx context.Context, domain string) ([]IPAd // Assign a dedicated IP to the domain specified. func (mg *MailgunImpl) AddDomainIP(ctx context.Context, domain, ip string) error { - r := newHTTPRequest(generateApiUrl(mg, domainsEndpoint) + "/" + domain + "/ips") + r := newHTTPRequest(generateApiUrl(mg, 3, domainsEndpoint) + "/" + domain + "/ips") r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) @@ -79,7 +79,7 @@ func (mg *MailgunImpl) AddDomainIP(ctx context.Context, domain, ip string) error // Unassign an IP from the domain specified. func (mg *MailgunImpl) DeleteDomainIP(ctx context.Context, domain, ip string) error { - r := newHTTPRequest(generateApiUrl(mg, domainsEndpoint) + "/" + domain + "/ips/" + ip) + r := newHTTPRequest(generateApiUrl(mg, 3, domainsEndpoint) + "/" + domain + "/ips/" + ip) r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) _, err := makeDeleteRequest(ctx, r) diff --git a/limits.go b/limits.go index 4bff2e2..2e73ead 100644 --- a/limits.go +++ b/limits.go @@ -9,7 +9,7 @@ type TagLimits struct { // GetTagLimits returns tracking settings for a domain func (mg *MailgunImpl) GetTagLimits(ctx context.Context, domain string) (TagLimits, error) { - r := newHTTPRequest(generateApiUrl(mg, domainsEndpoint) + "/" + domain + "/limits/tag") + r := newHTTPRequest(generateApiUrl(mg, 3, domainsEndpoint) + "/" + domain + "/limits/tag") r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) var resp TagLimits diff --git a/mailgun.go b/mailgun.go index 6e8ddfd..427d922 100644 --- a/mailgun.go +++ b/mailgun.go @@ -88,9 +88,10 @@ var Debug = false const ( // APIBase - base URL the library uses to contact mailgun. Use SetAPIBase() to override - APIBase = "https://api.mailgun.net/v3" - APIBaseUS = APIBase - APIBaseEU = "https://api.eu.mailgun.net/v3" + APIBase = "https://api.mailgun.net" + APIBaseUS = APIBase + APIBaseEU = "https://api.eu.mailgun.net" + messagesEndpoint = "messages" mimeMessagesEndpoint = "messages.mime" bouncesEndpoint = "bounces" @@ -108,7 +109,8 @@ const ( templatesEndpoint = "templates" accountsEndpoint = "accounts" subaccountsEndpoint = "subaccounts" - OnBehalfOfHeader = "X-Mailgun-On-Behalf-Of" + + OnBehalfOfHeader = "X-Mailgun-On-Behalf-Of" ) // Mailgun defines the supported subset of the Mailgun API. @@ -339,7 +341,7 @@ func (mg *MailgunImpl) RemoveOnBehalfOfSubaccount() { // mg.SetAPIBase(mailgun.APIBaseUS) // // // Set a custom base API -// mg.SetAPIBase("https://localhost/v3") +// mg.SetAPIBase("https://localhost") func (mg *MailgunImpl) SetAPIBase(address string) { mg.apiBase = address } @@ -358,33 +360,37 @@ type ListOptions struct { Limit int } -// generateApiUrlWithDomain renders a URL for an API endpoint using the domain and endpoint name. -func generateApiUrlWithDomain(m Mailgun, endpoint, domain string) string { - return fmt.Sprintf("%s/%s/%s", m.APIBase(), domain, endpoint) +func generateApiUrlWithDomain(m Mailgun, version int, endpoint, domain string) string { + return fmt.Sprintf("%s/v%d/%s/%s", m.APIBase(), version, domain, endpoint) +} + +// generateApiV3UrlWithDomain renders a URL for an API endpoint using the domain and endpoint name. +func generateApiV3UrlWithDomain(m Mailgun, endpoint, domain string) string { + return generateApiUrlWithDomain(m, 3, endpoint, domain) } // generateMemberApiUrl renders a URL relevant for specifying mailing list members. // The address parameter refers to the mailing list in question. func generateMemberApiUrl(m Mailgun, endpoint, address string) string { - return fmt.Sprintf("%s/%s/%s/members", m.APIBase(), endpoint, address) + return fmt.Sprintf("%s/v3/%s/%s/members", m.APIBase(), endpoint, address) } -// generateApiUrlWithTarget works as generateApiUrl +// generateApiV3UrlWithTarget works as generateApiV3UrlWithDomain // but consumes an additional resource parameter called 'target'. -func generateApiUrlWithTarget(m Mailgun, endpoint, domain, target string) string { +func generateApiV3UrlWithTarget(m Mailgun, endpoint, domain, target string) string { tail := "" if target != "" { tail = fmt.Sprintf("/%s", target) } - return fmt.Sprintf("%s%s", generateApiUrlWithDomain(m, endpoint, domain), tail) + return fmt.Sprintf("%s%s", generateApiV3UrlWithDomain(m, endpoint, domain), tail) } -// generateDomainsApiUrl renders a URL as generateApiUrlWithDomain, but +// generateDomainsApiUrl renders a URL as generateApiV3UrlWithDomain, but // addresses a family of functions which have a non-standard URL structure. // Most URLs consume a domain in the 2nd position, but some endpoints // require the word "domains" to be there instead. func generateDomainsApiUrl(m Mailgun, endpoint, domain string) string { - return fmt.Sprintf("%s/domains/%s/%s", m.APIBase(), domain, endpoint) + return fmt.Sprintf("%s/v3/domains/%s/%s", m.APIBase(), domain, endpoint) } // generateCredentialsUrl renders a URL as generateDomainsApiUrl, @@ -398,8 +404,8 @@ func generateCredentialsUrl(m Mailgun, domain, login string) string { } // generateApiUrl returns domain agnostic URL. -func generateApiUrl(m Mailgun, endpoint string) string { - return fmt.Sprintf("%s/%s", m.APIBase(), endpoint) +func generateApiUrl(m Mailgun, version int, endpoint string) string { + return fmt.Sprintf("%s/v%d/%s", m.APIBase(), version, endpoint) } // formatMailgunTime translates a timestamp into a human-readable form. diff --git a/mailing_lists.go b/mailing_lists.go index ccaa0c3..a1f3613 100644 --- a/mailing_lists.go +++ b/mailing_lists.go @@ -63,7 +63,7 @@ type ListsIterator struct { // ListMailingLists returns the specified set of mailing lists administered by your account. func (mg *MailgunImpl) ListMailingLists(opts *ListOptions) *ListsIterator { - r := newHTTPRequest(generateApiUrl(mg, listsEndpoint) + "/pages") + r := newHTTPRequest(generateApiUrl(mg, 3, listsEndpoint) + "/pages") r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) if opts != nil { @@ -174,7 +174,7 @@ func (li *ListsIterator) fetch(ctx context.Context, url string) error { // while AccessLevel defaults to Everyone // and ReplyPreference defaults to List. func (mg *MailgunImpl) CreateMailingList(ctx context.Context, prototype MailingList) (MailingList, error) { - r := newHTTPRequest(generateApiUrl(mg, listsEndpoint)) + r := newHTTPRequest(generateApiUrl(mg, 3, listsEndpoint)) r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) p := newUrlEncodedPayload() @@ -205,7 +205,7 @@ func (mg *MailgunImpl) CreateMailingList(ctx context.Context, prototype MailingL // DeleteMailingList removes all current members of the list, then removes the list itself. // Attempts to send e-mail to the list will fail subsequent to this call. func (mg *MailgunImpl) DeleteMailingList(ctx context.Context, addr string) error { - r := newHTTPRequest(generateApiUrl(mg, listsEndpoint) + "/" + addr) + r := newHTTPRequest(generateApiUrl(mg, 3, listsEndpoint) + "/" + addr) r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) _, err := makeDeleteRequest(ctx, r) @@ -215,7 +215,7 @@ func (mg *MailgunImpl) DeleteMailingList(ctx context.Context, addr string) error // GetMailingList allows your application to recover the complete List structure // representing a mailing list, so long as you have its e-mail address. func (mg *MailgunImpl) GetMailingList(ctx context.Context, addr string) (MailingList, error) { - r := newHTTPRequest(generateApiUrl(mg, listsEndpoint) + "/" + addr) + r := newHTTPRequest(generateApiUrl(mg, 3, listsEndpoint) + "/" + addr) r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) response, err := makeGetRequest(ctx, r) @@ -236,7 +236,7 @@ func (mg *MailgunImpl) GetMailingList(ctx context.Context, addr string) (Mailing // e-mail sent to the old address will not succeed. // Make sure you account for the change accordingly. func (mg *MailgunImpl) UpdateMailingList(ctx context.Context, addr string, prototype MailingList) (MailingList, error) { - r := newHTTPRequest(generateApiUrl(mg, listsEndpoint) + "/" + addr) + r := newHTTPRequest(generateApiUrl(mg, 3, listsEndpoint) + "/" + addr) r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) p := newUrlEncodedPayload() diff --git a/messages.go b/messages.go index 0acc65c..a6ace90 100644 --- a/messages.go +++ b/messages.go @@ -684,7 +684,7 @@ func (mg *MailgunImpl) Send(ctx context.Context, m SendableMessage) (mes, id str return "", "", err } - r := newHTTPRequest(generateApiUrlWithDomain(mg, m.Endpoint(), m.Domain())) + r := newHTTPRequest(generateApiV3UrlWithDomain(mg, m.Endpoint(), m.Domain())) r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) // Override any HTTP headers if provided diff --git a/messages_v5.go b/messages_v5.go index 1204f44..4a7c313 100644 --- a/messages_v5.go +++ b/messages_v5.go @@ -440,7 +440,7 @@ func (mg *MailgunImpl) sendV5(ctx context.Context, m SendableMessage) (mes, id s return "", "", err } - r := newHTTPRequest(generateApiUrlWithDomain(mg, m.Endpoint(), m.Domain())) + r := newHTTPRequest(generateApiV3UrlWithDomain(mg, m.Endpoint(), m.Domain())) r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) // Override any HTTP headers if provided diff --git a/routes.go b/routes.go index bbf2edd..4693f6e 100644 --- a/routes.go +++ b/routes.go @@ -118,7 +118,7 @@ func (mg *MailgunImpl) ListRoutes(opts *ListOptions) *RoutesIterator { return &RoutesIterator{ mg: mg, - url: generateApiUrl(mg, routesEndpoint), + url: generateApiUrl(mg, 3, routesEndpoint), routesListResponse: routesListResponse{TotalCount: -1}, limit: limit, } @@ -262,7 +262,7 @@ func (ri *RoutesIterator) fetch(ctx context.Context, skip, limit int) error { // only a subset of the fields influence the operation. // See the Route structure definition for more details. func (mg *MailgunImpl) CreateRoute(ctx context.Context, prototype Route) (_ignored Route, err error) { - r := newHTTPRequest(generateApiUrl(mg, routesEndpoint)) + r := newHTTPRequest(generateApiUrl(mg, 3, routesEndpoint)) r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) p := newUrlEncodedPayload() @@ -284,7 +284,7 @@ func (mg *MailgunImpl) CreateRoute(ctx context.Context, prototype Route) (_ignor // To avoid ambiguity, Mailgun identifies the route by unique ID. // See the Route structure definition and the Mailgun API documentation for more details. func (mg *MailgunImpl) DeleteRoute(ctx context.Context, id string) error { - r := newHTTPRequest(generateApiUrl(mg, routesEndpoint) + "/" + id) + r := newHTTPRequest(generateApiUrl(mg, 3, routesEndpoint) + "/" + id) r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) _, err := makeDeleteRequest(ctx, r) @@ -293,7 +293,7 @@ func (mg *MailgunImpl) DeleteRoute(ctx context.Context, id string) error { // GetRoute retrieves the complete route definition associated with the unique route ID. func (mg *MailgunImpl) GetRoute(ctx context.Context, id string) (Route, error) { - r := newHTTPRequest(generateApiUrl(mg, routesEndpoint) + "/" + id) + r := newHTTPRequest(generateApiUrl(mg, 3, routesEndpoint) + "/" + id) r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) var envelope struct { @@ -312,7 +312,7 @@ func (mg *MailgunImpl) GetRoute(ctx context.Context, id string) (Route, error) { // Only those route fields which are non-zero or non-empty are updated. // All other fields remain as-is. func (mg *MailgunImpl) UpdateRoute(ctx context.Context, id string, route Route) (Route, error) { - r := newHTTPRequest(generateApiUrl(mg, routesEndpoint) + "/" + id) + r := newHTTPRequest(generateApiUrl(mg, 3, routesEndpoint) + "/" + id) r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) p := newUrlEncodedPayload() diff --git a/spam_complaints.go b/spam_complaints.go index 4494ace..dcaf50b 100644 --- a/spam_complaints.go +++ b/spam_complaints.go @@ -26,7 +26,7 @@ type complaintsResponse struct { // Recipients of your messages can click on a link which sends feedback to Mailgun // indicating that the message they received is, to them, spam. func (mg *MailgunImpl) ListComplaints(domain string, opts *ListOptions) *ComplaintsIterator { - r := newHTTPRequest(generateApiUrlWithDomain(mg, complaintsEndpoint, domain)) + r := newHTTPRequest(generateApiV3UrlWithDomain(mg, complaintsEndpoint, domain)) r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) if opts != nil { @@ -139,7 +139,7 @@ func (ci *ComplaintsIterator) fetch(ctx context.Context, url string) error { // GetComplaint returns a single complaint record filed by a recipient at the email address provided. // If no complaint exists, the Complaint instance returned will be empty. func (mg *MailgunImpl) GetComplaint(ctx context.Context, domain, address string) (Complaint, error) { - r := newHTTPRequest(generateApiUrlWithDomain(mg, complaintsEndpoint, domain) + "/" + address) + r := newHTTPRequest(generateApiV3UrlWithDomain(mg, complaintsEndpoint, domain) + "/" + address) r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) @@ -151,7 +151,7 @@ func (mg *MailgunImpl) GetComplaint(ctx context.Context, domain, address string) // CreateComplaint registers the specified address as a recipient who has complained of receiving spam // from your domain. func (mg *MailgunImpl) CreateComplaint(ctx context.Context, domain, address string) error { - r := newHTTPRequest(generateApiUrlWithDomain(mg, complaintsEndpoint, domain)) + r := newHTTPRequest(generateApiV3UrlWithDomain(mg, complaintsEndpoint, domain)) r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) p := newUrlEncodedPayload() @@ -161,7 +161,7 @@ func (mg *MailgunImpl) CreateComplaint(ctx context.Context, domain, address stri } func (mg *MailgunImpl) CreateComplaints(ctx context.Context, domain string, addresses []string) error { - r := newHTTPRequest(generateApiUrlWithDomain(mg, complaintsEndpoint, domain)) + r := newHTTPRequest(generateApiV3UrlWithDomain(mg, complaintsEndpoint, domain)) r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) @@ -179,7 +179,7 @@ func (mg *MailgunImpl) CreateComplaints(ctx context.Context, domain string, addr // DeleteComplaint removes a previously registered e-mail address from the list of people who complained // of receiving spam from your domain. func (mg *MailgunImpl) DeleteComplaint(ctx context.Context, domain, address string) error { - r := newHTTPRequest(generateApiUrlWithDomain(mg, complaintsEndpoint, domain) + "/" + address) + r := newHTTPRequest(generateApiV3UrlWithDomain(mg, complaintsEndpoint, domain) + "/" + address) r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) _, err := makeDeleteRequest(ctx, r) diff --git a/tags.go b/tags.go index 72b6c83..f21e922 100644 --- a/tags.go +++ b/tags.go @@ -28,7 +28,7 @@ type ListTagOptions struct { // DeleteTag removes all counters for a particular tag, including the tag itself. func (mg *MailgunImpl) DeleteTag(ctx context.Context, domain, tag string) error { - r := newHTTPRequest(generateApiUrlWithDomain(mg, tagsEndpoint, domain) + "/" + tag) + r := newHTTPRequest(generateApiV3UrlWithDomain(mg, tagsEndpoint, domain) + "/" + tag) r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) _, err := makeDeleteRequest(ctx, r) @@ -37,7 +37,7 @@ func (mg *MailgunImpl) DeleteTag(ctx context.Context, domain, tag string) error // GetTag retrieves metadata about the tag from the api func (mg *MailgunImpl) GetTag(ctx context.Context, domain, tag string) (Tag, error) { - r := newHTTPRequest(generateApiUrlWithDomain(mg, tagsEndpoint, domain) + "/" + tag) + r := newHTTPRequest(generateApiV3UrlWithDomain(mg, tagsEndpoint, domain) + "/" + tag) r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) var tagItem Tag @@ -58,7 +58,7 @@ func (mg *MailgunImpl) GetTag(ctx context.Context, domain, tag string) (Tag, err // log.Fatal(it.Err()) // } func (mg *MailgunImpl) ListTags(domain string, opts *ListTagOptions) *TagIterator { - req := newHTTPRequest(generateApiUrlWithDomain(mg, tagsEndpoint, domain)) + req := newHTTPRequest(generateApiV3UrlWithDomain(mg, tagsEndpoint, domain)) if opts != nil { if opts.Limit != 0 { req.addParameter("limit", strconv.Itoa(opts.Limit)) diff --git a/template.go b/template.go index ce96098..8951bea 100644 --- a/template.go +++ b/template.go @@ -33,7 +33,7 @@ type templateListResp struct { // Create a new template which can be used to attach template versions to func (mg *MailgunImpl) CreateTemplate(ctx context.Context, domain string, template *Template) error { - r := newHTTPRequest(generateApiUrlWithDomain(mg, templatesEndpoint, domain)) + r := newHTTPRequest(generateApiV3UrlWithDomain(mg, templatesEndpoint, domain)) r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) @@ -69,7 +69,7 @@ func (mg *MailgunImpl) CreateTemplate(ctx context.Context, domain string, templa // GetTemplate gets a template given the template name func (mg *MailgunImpl) GetTemplate(ctx context.Context, domain, name string) (Template, error) { - r := newHTTPRequest(generateApiUrlWithDomain(mg, templatesEndpoint, domain) + "/" + name) + r := newHTTPRequest(generateApiV3UrlWithDomain(mg, templatesEndpoint, domain) + "/" + name) r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) r.addParameter("active", "yes") @@ -88,7 +88,7 @@ func (mg *MailgunImpl) UpdateTemplate(ctx context.Context, domain string, templa return errors.New("UpdateTemplate() Template.Name cannot be empty") } - r := newHTTPRequest(generateApiUrlWithDomain(mg, templatesEndpoint, domain) + "/" + template.Name) + r := newHTTPRequest(generateApiV3UrlWithDomain(mg, templatesEndpoint, domain) + "/" + template.Name) r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) p := newUrlEncodedPayload() @@ -111,7 +111,7 @@ func (mg *MailgunImpl) UpdateTemplate(ctx context.Context, domain string, templa // Delete a template given a template name func (mg *MailgunImpl) DeleteTemplate(ctx context.Context, domain, name string) error { - r := newHTTPRequest(generateApiUrlWithDomain(mg, templatesEndpoint, domain) + "/" + name) + r := newHTTPRequest(generateApiV3UrlWithDomain(mg, templatesEndpoint, domain) + "/" + name) r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) _, err := makeDeleteRequest(ctx, r) @@ -131,7 +131,7 @@ type ListTemplateOptions struct { // List all available templates func (mg *MailgunImpl) ListTemplates(domain string, opts *ListTemplateOptions) *TemplatesIterator { - r := newHTTPRequest(generateApiUrlWithDomain(mg, templatesEndpoint, domain)) + r := newHTTPRequest(generateApiV3UrlWithDomain(mg, templatesEndpoint, domain)) r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) if opts != nil { diff --git a/template_versions.go b/template_versions.go index f4e50c5..65b9a0b 100644 --- a/template_versions.go +++ b/template_versions.go @@ -24,7 +24,7 @@ type templateVersionListResp struct { // AddTemplateVersion adds a template version to a template func (mg *MailgunImpl) AddTemplateVersion(ctx context.Context, domain, templateName string, version *TemplateVersion) error { - r := newHTTPRequest(generateApiUrlWithDomain(mg, templatesEndpoint, domain) + "/" + templateName + "/versions") + r := newHTTPRequest(generateApiV3UrlWithDomain(mg, templatesEndpoint, domain) + "/" + templateName + "/versions") r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) @@ -54,7 +54,7 @@ func (mg *MailgunImpl) AddTemplateVersion(ctx context.Context, domain, templateN // GetTemplateVersion gets a specific version of a template func (mg *MailgunImpl) GetTemplateVersion(ctx context.Context, domain, templateName, tag string) (TemplateVersion, error) { - r := newHTTPRequest(generateApiUrlWithDomain(mg, templatesEndpoint, domain) + "/" + templateName + "/versions/" + tag) + r := newHTTPRequest(generateApiV3UrlWithDomain(mg, templatesEndpoint, domain) + "/" + templateName + "/versions/" + tag) r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) @@ -68,7 +68,7 @@ func (mg *MailgunImpl) GetTemplateVersion(ctx context.Context, domain, templateN // Update the comment and mark a version of a template active func (mg *MailgunImpl) UpdateTemplateVersion(ctx context.Context, domain, templateName string, version *TemplateVersion) error { - r := newHTTPRequest(generateApiUrlWithDomain(mg, templatesEndpoint, domain) + "/" + templateName + "/versions/" + version.Tag) + r := newHTTPRequest(generateApiV3UrlWithDomain(mg, templatesEndpoint, domain) + "/" + templateName + "/versions/" + version.Tag) r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) p := newUrlEncodedPayload() @@ -94,7 +94,7 @@ func (mg *MailgunImpl) UpdateTemplateVersion(ctx context.Context, domain, templa // Delete a specific version of a template func (mg *MailgunImpl) DeleteTemplateVersion(ctx context.Context, domain, templateName, tag string) error { - r := newHTTPRequest(generateApiUrlWithDomain(mg, templatesEndpoint, domain) + "/" + templateName + "/versions/" + tag) + r := newHTTPRequest(generateApiV3UrlWithDomain(mg, templatesEndpoint, domain) + "/" + templateName + "/versions/" + tag) r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) _, err := makeDeleteRequest(ctx, r) @@ -109,7 +109,7 @@ type TemplateVersionsIterator struct { // ListTemplateVersions lists all the versions of a specific template func (mg *MailgunImpl) ListTemplateVersions(domain, templateName string, opts *ListOptions) *TemplateVersionsIterator { - r := newHTTPRequest(generateApiUrlWithDomain(mg, templatesEndpoint, domain) + "/" + templateName + "/versions") + r := newHTTPRequest(generateApiV3UrlWithDomain(mg, templatesEndpoint, domain) + "/" + templateName + "/versions") r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) if opts != nil { diff --git a/unsubscribes.go b/unsubscribes.go index 019b5c4..d76b419 100644 --- a/unsubscribes.go +++ b/unsubscribes.go @@ -19,7 +19,7 @@ type unsubscribesResponse struct { // Fetches the list of unsubscribes func (mg *MailgunImpl) ListUnsubscribes(domain string, opts *ListOptions) *UnsubscribesIterator { - r := newHTTPRequest(generateApiUrlWithDomain(mg, unsubscribesEndpoint, domain)) + r := newHTTPRequest(generateApiV3UrlWithDomain(mg, unsubscribesEndpoint, domain)) r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) if opts != nil { @@ -131,7 +131,7 @@ func (ci *UnsubscribesIterator) fetch(ctx context.Context, url string) error { // Retreives a single unsubscribe record. Can be used to check if a given address is present in the list of unsubscribed users. func (mg *MailgunImpl) GetUnsubscribe(ctx context.Context, domain, address string) (Unsubscribe, error) { - r := newHTTPRequest(generateApiUrlWithTarget(mg, unsubscribesEndpoint, domain, address)) + r := newHTTPRequest(generateApiV3UrlWithTarget(mg, unsubscribesEndpoint, domain, address)) r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) @@ -143,7 +143,7 @@ func (mg *MailgunImpl) GetUnsubscribe(ctx context.Context, domain, address strin // Unsubscribe adds an e-mail address to the domain's unsubscription table. func (mg *MailgunImpl) CreateUnsubscribe(ctx context.Context, domain, address, tag string) error { - r := newHTTPRequest(generateApiUrlWithDomain(mg, unsubscribesEndpoint, domain)) + r := newHTTPRequest(generateApiV3UrlWithDomain(mg, unsubscribesEndpoint, domain)) r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) p := newUrlEncodedPayload() @@ -155,7 +155,7 @@ func (mg *MailgunImpl) CreateUnsubscribe(ctx context.Context, domain, address, t // CreateUnsubscribes adds multiple e-mail addresses to the domain's unsubscription table. func (mg *MailgunImpl) CreateUnsubscribes(ctx context.Context, domain string, unsubscribes []Unsubscribe) error { - r := newHTTPRequest(generateApiUrlWithDomain(mg, unsubscribesEndpoint, domain)) + r := newHTTPRequest(generateApiV3UrlWithDomain(mg, unsubscribesEndpoint, domain)) r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) r.addHeader("Content-Type", "application/json") @@ -169,7 +169,7 @@ func (mg *MailgunImpl) CreateUnsubscribes(ctx context.Context, domain string, un // If passing in an ID (discoverable from, e.g., ListUnsubscribes()), the e-mail address associated // with the given ID will be removed. func (mg *MailgunImpl) DeleteUnsubscribe(ctx context.Context, domain, address string) error { - r := newHTTPRequest(generateApiUrlWithTarget(mg, unsubscribesEndpoint, domain, address)) + r := newHTTPRequest(generateApiV3UrlWithTarget(mg, unsubscribesEndpoint, domain, address)) r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) _, err := makeDeleteRequest(ctx, r) @@ -180,7 +180,7 @@ func (mg *MailgunImpl) DeleteUnsubscribe(ctx context.Context, domain, address st // If passing in an ID (discoverable from, e.g., ListUnsubscribes()), the e-mail address associated // with the given ID will be removed. func (mg *MailgunImpl) DeleteUnsubscribeWithTag(ctx context.Context, domain, a, t string) error { - r := newHTTPRequest(generateApiUrlWithTarget(mg, unsubscribesEndpoint, domain, a)) + r := newHTTPRequest(generateApiV3UrlWithTarget(mg, unsubscribesEndpoint, domain, a)) r.setClient(mg.HTTPClient()) r.setBasicAuth(basicAuthUser, mg.APIKey()) r.addParameter("tag", t)