Skip to content
Advertisement

SendGrid “invalid_email” DELETE api is not deleting the data

So my code looks like this. This is copied from SendGrid’s docs. I have a similar function for deletion of spam emails and bounce emails. But this function throws an error whenever “Response response = sg.api(request);” is executed. Please help.

  public boolean deleteInvalidByEmail(String email, String apiKey) throws Exception{
        
         com.sendgrid.SendGrid sg = new SendGrid(apiKey);
        
         Request request = new Request();
         try {

            if(email!=null){
            request.setMethod(Method.DELETE);
            request.setEndpoint("suppression/invalid_emails/"+email);
            request.addQueryParam("email", email);
            
            Response response = sg.api(request);
            logger.debug(response.getStatusCode());
            logger.debug(response.getBody());
            logger.debug("Mapped Output =========================");
            logger.debug(response.getHeaders());
            }
        } catch (Exception ex) {
            logger.error(ex.getMessage());
            ex.printStackTrace();
            throw new Exception("Unable to get Delete Bounce Email Address");
        }
        return true;
    }

Advertisement

Answer

From your comments, it seems that you are getting a 404 error, which tells you that the data you are trying to delete is not present. The error message says “resource not found”.

So, the email address you are trying to delete is not an invalid email that is available to delete. Note that invalid emails are described in the docs as:

An invalid email occurs when you attempt to send email to an address that is formatted in a manner that does not meet internet email format standards or the email does not exist at the recipient’s mail server. Examples include addresses without the “@” sign or addresses that include certain special characters and/or spaces. This response can come from our own server or the recipient mail server.

Are you trying to delete an email that isn’t invalid?

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement