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);
}
I tried with OkHttpClient, no 404 error, no body but still no luck, my contact is still there and the following test fails as well
@Test
public void removeContactByID() throws IOException, MailjetException {
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 OkHttpClient httpClient = new OkHttpClient();
final Request request = new Request.Builder()
.url("https://api.mailjet.com/v4/contacts/" + contactID)
.addHeader("authorization", "Basic " + base64Credentials)
.delete()
.build();
try (final Response response = httpClient.newCall(request).execute()) {
assertThat(response.isSuccessful()).isTrue();
}
final Integer id = getContactIdByEmail(randomName + "@example.com");
assertThat(id).isNull();
}
Using curl seems to work ... what am I doing wrong?