Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for V4 delete contact endpoint #107

Closed

Conversation

filfreire
Copy link

Hi folks!

There's a case where if folks try to use mailjet-apiv3-go client to delete contacts, e.g. due to GDPR requests, where we get a 401 error.

This is due to the fact that we are sending the DELETE request to /v3 api.

If we use the client's SetURL or SetBaseURL to override the base URL and send it to /v4 instead, the /REST path is still added. This PR adds a workaround to support sending requests like Delete contact to /v4 in a way that won't add the extra /REST path.

Note to the maintainers of mailjet client: this was just a quick "hacky" way/workaround, but I would be happy to help make this PR into a more clean/mergeable state if provided with some guidance.

@@ -209,6 +209,20 @@ func (c *Client) Delete(mr *Request) (err error) {
return err
}

// Special case of Delete for API v4 (e.g. delete contacts in case of GDPR requests)
func (c *Client) DeleteV4(mr *Request) (err error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on https://dev.mailjet.com/email/guides/contact-management/#overview it looks like the v3 delete is not a thing anymore. So better just to update the origin Delete func.

Comment on lines +174 to +175
func buildURLV4(baseURL string, info *Request) string {
tokens := []string{baseURL, info.Resource}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't look DRY to me.

Could you refactor old buildURL and new buildURLV4 into:

func buildURL(baseURL string, info *Request) string {
    buildURLPath([]string{baseURL, apiPath, info})
}
func buildURLV4(baseURL string, info *Request) string {
    buildURLPath([]string{baseURL, info})
}

or something like that?

@filfreire filfreire closed this by deleting the head repository Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants