1

I am getting an exception while calling Rest API "PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target"

My Code is :

HttpResponse res = request('https://api.test.com/test');
System.debug(res);

  public HTTPResponse request(String path){
    HttpRequest req = new HttpRequest();
    Http http = new Http(); 
    req.setEndpoint(path);
    req.setMethod('GET');
    req.setClientCertificatename('api_expocad_com');
    req.setHeader('Content-Type', 'text/JSON;charset=UTF-8');
    req.setHeader('User-Agent', 'salesforce-desk-client/0.1.0');
    req.setHeader('Accept', 'application/json');
    req = basicAuthentication(req);
    HttpResponse res2 = http.send(req);
    return res2;
  }

  private HTTPRequest basicAuthentication(HTTPRequest req1){
    Blob headerValue = Blob.valueOf('Test1:Test2');
    req1.setHeader('Authorization', 'Basic ' + EncodingUtil.base64Encode(headerValue));
    return req1;
  }
1

The error suggests that the certificate being used by the remote host isn't signed by a certificate authority (CA) that is trusted by Salesforce. If it is a web service that you are hosting you could look at changing the certificate.

See SSL certificates Salesforce supports and Outbound Messaging SSL CA Certificates

With the actual URL of the web service you could use https://www.digicert.com/help/ the get the SSL certificate details.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.