'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;
    }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source