Skip to main content
12-Amethyst
June 21, 2021
Question

Call external Rest API from thingworx application

  • June 21, 2021
  • 1 reply
  • 1213 views

Hi,

 

I need to call a REST API from my thingworx application. To achieve that, i try to use the ContentLoaderFunctions resources.

1- Is it the right way ?

2- If yes, i try to call a test Rest API, but it doens't work:

 

var result = Resources["ContentLoaderFunctions"].GetJSON({
	url: "https://jsonplaceholder.typicode.com/todos/1" /* STRING */,
	timeout: 30000 /* NUMBER */,
 headers:undefined,
	ignoreSSLErrors: false /* BOOLEAN */,
	useProxy: false /* BOOLEAN */,
	proxyHost: undefined /* STRING */,
	proxyPort: undefined /* INTEGER */,
	proxyScheme: undefined /* STRING */
});

 

or

 

var result = Resources["ContentLoaderFunctions"].GetJSON({
	url: "https://jsonplaceholder.typicode.com/todos/1" /* STRING */,
	timeout: 30000 /* NUMBER */,
 headers: {'Host': 'jsonplaceholder.typicode.com', 'Accept':'application/json', 'Content-Type':'application/json'},
	ignoreSSLErrors: false /* BOOLEAN */,
	useProxy: false /* BOOLEAN */,
	proxyHost: undefined /* STRING */,
	proxyPort: undefined /* INTEGER */,
	proxyScheme: undefined /* STRING */
});

 

 

In both cas, i receive

" Error executing service testRTestApiCall. Message :: Received fatal alert: handshake_failure"

 

Any idea ?

 

Thanks for your help.

 

 

1 reply

17-Peridot
June 21, 2021

Did you use a self-signed certificate for "jsonplaceholder.typicode.com"? Is the SSL port 443? How about set "ignoreSSLErrors = true" in the params?

cbaurand12-AmethystAuthor
12-Amethyst
June 21, 2021

Thanks for your response.

"jsonplaceholder.typicode.com" is a well known test site you can use for testing api Call. I can call it with postman and it works. Changing "ignoreSSLErrors " to false or true doesn't change anything.

But, i have 2 instances of my Thingworx application:

one running on my local pc, inside docker container. This one leads to the issue.

one running on PTC server. This one works fine. So, it seems there is a problem with my docker image. I need to investigate but any idea would be appreciate.

Thanks.