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

delete customer 401 Unauthorized #213

Open
lrkwz opened this issue Feb 29, 2024 · 1 comment
Open

delete customer 401 Unauthorized #213

lrkwz opened this issue Feb 29, 2024 · 1 comment

Comments

@lrkwz
Copy link

lrkwz commented Feb 29, 2024

When I perform a delete customer I always receive a 401 code.

The client is initialized the "standard" way:

final ClientOptions options = ClientOptions.builder()
                .apiKey(apiKey)
                .apiSecretKey(apiSecretKey)
                .build();
        final MailjetClient client = new MailjetClient(options);

Example given a function that returns the customer ID (assuring he/she exists)

    @Test
    public void removeContact() throws MailjetException {
        final MailjetRequest request = new MailjetRequest(Contact.resource, getContactIdByEmail("[email protected]"));
        final MailjetResponse response = client.delete(request);
        assertThat(response.getStatus()).isEqualTo(200);
    }

output is:

com.mailjet.client.errors.MailjetUnauthorizedException: Unauthorized. Please,verify your access key and access secret key or token for the given account

	at com.mailjet.client.MailjetResponseUtil.validateMailjetResponse(MailjetResponseUtil.java:32)
	at com.mailjet.client.MailjetClient.parseResponse(MailjetClient.java:297)
	at com.mailjet.client.MailjetClient.delete(MailjetClient.java:240)
	at learning.MailJetApiTest.removeContact(MailJetApiTest.java:145)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)

Same if I use a filter such as:

    @Test
    public void removeContactByMail() throws MailjetException {
        final MailjetRequest request = new MailjetRequest(Contact.resource)
                .filter(Contact.EMAIL, "[email protected]");
        final MailjetResponse response = client.delete(request);
        assertThat(response.getStatus()).isEqualTo(200);
    }
@lrkwz
Copy link
Author

lrkwz commented Mar 2, 2024

As a workaround I used the GDPR delete feature as described in the user guide :

   @Test
    public void removeContactByID() throws IOException {
        final String randomName = generateRandomUsername();
        final int contactID = addContact(randomName, randomName + "@example.com");

        final String base64Credentials = Base64.getEncoder().encodeToString((API_KEY + ":" + API_SECRET_KEY).getBytes());

        final Request request = new Request.Builder()
                .url("https://api.mailjet.com/v4/contacts/" + contactID)
                .addHeader("authorization", "Basic " + base64Credentials)
                .addHeader("user-agent", "curl/7.54.1") // !!!!
                .delete()
                .build();
        final OkHttpClient httpClient = new OkHttpClient();
        try (final Response response = httpClient.newCall(request).execute()) {
            assertThat(response.isSuccessful()).isTrue();
        }
    }

Contact details are immediately anonymized and all records will be deleted after 30 days. (...) The anonymized contact will retain its contact ID and general configuration settings until it is removed when the 30-day period ends.

So it is useless to test if the deletion has really run after the call.

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

No branches or pull requests

1 participant