Skip to main content
1-Visitor
Jan 19, 2018 9:15 AM UTC
Solved

connect to https REST API

Hello,

I have a thing which has multiple services that call REST API's.

Script is:

var url = 'https://url_to_api/api/controller/Action?param1=' + INPUT1 + '&userName='  + User;

var params = {

  url: url /* STRING */,

};

var result = Resources["ContentLoaderFunctions"].GetText(params);

the url used to be HTTP and everything worked great.

Now the url is https and when I test my service I get the following error:

Wrapped javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target Cause: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

Does anybody know what I have to do to get this working.

jrajeshAnswer
10-Marble
Apr 5, 2018 1:54 PM UTC

Hi,

 

I had to give the following to tomcat configuration Java options and only then it worked:

-Djavax.net.ssl.trustStore=C:\Program Files\Java\jre1.8.0_161\lib\security\cacerts

 

Thanks and Regards,

Jyothi

9 replies

1-Visitor
Jan 22, 2018 3:53 PM UTC

Hi Sven

Your rest request is using https, which will suggest you will need to enable ignoreSSLError to true.

var params = {

proxyScheme: undefined /* STRING */,

headers: undefined /* JSON */,

ignoreSSLErrors: true/* BOOLEAN */,

useNTLM: undefined /* BOOLEAN */,

workstation: undefined /* STRING */,

useProxy: undefined /* BOOLEAN */,

withCookies: undefined /* BOOLEAN */,

proxyHost: undefined /* STRING */,

url: undefined /* STRING */,

timeout: undefined /* NUMBER */,

proxyPort: undefined /* INTEGER */,

password: undefined /* STRING */,

domain: undefined /* STRING */,

username: undefined /* STRING */

};

var result = Resources["ContentLoaderFunctions"].GetText(params);

Translate
1-Visitor
Jan 23, 2018 2:17 PM UTC

I still get the error

Translate
1-Visitor
Jan 23, 2018 3:05 PM UTC

Have you successfully tried using Postman with this https request?

This could tell us if it is a Thingworx problem or this could be an API certificate issue.

Translate
1-Visitor
Feb 1, 2018 3:16 PM UTC

Found the error. I was adding the certificates to the wrong keystore.

Translate
10-Marble
Apr 3, 2018 12:36 PM UTC

Hi,

 

Which keystore should be used to import the certificate? I used the Java cacerts that ThingWorx tomcat is using. It still does not work for me.

 

Thanks and Regards,

Jyothi

Translate
5-Regular Member
Apr 5, 2018 1:50 PM UTC

Hello.

 

Has this issue been resolved by importing to the correct keystore? If so, can you tell us which keystore was correct, and mark that as an Accepted Solution?

 

If there are still any problems, let us know that as well.

 

Thanks!

 

-- Craig A.

Translate
jrajesh10-MarbleAnswer
10-Marble
Apr 5, 2018 1:54 PM UTC

Hi,

 

I had to give the following to tomcat configuration Java options and only then it worked:

-Djavax.net.ssl.trustStore=C:\Program Files\Java\jre1.8.0_161\lib\security\cacerts

 

Thanks and Regards,

Jyothi

Translate