cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Need help navigating or using the PTC Community? Contact the community team. X

Curl Command inside service

Saitoisonfire
12-Amethyst

Curl Command inside service

Hi All,

Can i use a curl command inside js service?

Also I have an URL as   ~ http://win-hkdrt6do2m5:8080/historian-rest-api/v1/tags?nameMask=* ~
Can I get the json from there by using the content load functions?

Thanks!

Anselmo.

12 REPLIES 12

If it's not a complex petition, you can just use Content Load Snippets.

Actually, I need to pass a token as parameter for authorization...is that too complex?

Shouldn't

Well, I just got this mesage error:

[message: Execution error in service script [LoadRestContent] :: win-hkdrt6do2m5: Name or service not known]

 

where the bolded line is my machine name.

I used one of the Load Content functions and changed
headers -> my JSON answer (acess/token) from curl command,

ignoreSSLErrors -> true,

url -> http://win-hkdrt6do2m5:8080/historian-rest-api/v1/tags?nameMask=*

Did I forget something?

Well the service name should be:

 

LoadText not LoadRestContent

 

 

That's the name of the service I created, not the chosen one.

Can you show the exact code, please.

Here it is

 

var token = {"access_token":"eyJhbGciOiJSUzI1NiJ9.eyJqdGkiOiJmNDJmNTNiNC1mY2YyLTQyNGEtYWM0My0xODUzZGVlMTcwN2UiLCJzdWIiOiJhZG1pbiIsImF1dGhvcml0aWVzIjpbImNsaWVudHMucmVhZCIsImhpc3Rvcmlhbl9yZXN0X2FwaS5yZWFkIiwicGFzc3dvcmQud3JpdGUiLCJjbGllbnRzLnNlY3JldCIsImhpc3Rvcmlhbl9yZXN0X2FwaS5hZG1pbiIsImhpc3Rvcmlhbl9yZXN0X2FwaS53cml0ZSIsImNsaWVudC5hZG1pbiIsImNsaWVudHMud3JpdGUiLCJ1YWEuYWRtaW4iLCJzY2ltLndyaXRlIiwic2NpbS5yZWFkIl0sInNjb3BlIjpbImNsaWVudHMucmVhZCIsImhpc3Rvcmlhbl9yZXN0X2FwaS5yZWFkIiwicGFzc3dvcmQud3JpdGUiLCJjbGllbnRzLnNlY3JldCIsImhpc3Rvcmlhbl9yZXN0X2FwaS5hZG1pbiIsImhpc3Rvcmlhbl9yZXN0X2FwaS53cml0ZSIsImNsaWVudC5hZG1pbiIsImNsaWVudHMud3JpdGUiLCJ1YWEuYWRtaW4iLCJzY2ltLndyaXRlIiwic2NpbS5yZWFkIl0sImNsaWVudF9pZCI6ImFkbWluIiwiY2lkIjoiYWRtaW4iLCJhenAiOiJhZG1pbiIsImdyYW50X3R5cGUiOiJjbGllbnRfY3JlZGVudGlhbHMiLCJyZXZfc2lnIjoiZGVlNGIyZDciLCJpYXQiOjE1MjM5MDM5ODEsImV4cCI6MTUyMzk0NzE4MSwiaXNzIjoiaHR0cDovL2xvY2FsaG9zdDo4MDgwL3VhYS9vYXV0aC90b2tlbiIsInppZCI6InVhYSIsImF1ZCI6WyJhZG1pbiIsImNsaWVudHMiLCJoaXN0b3JpYW5fcmVzdF9hcGkiLCJwYXNzd29yZCIsImNsaWVudCIsInVhYSIsInNjaW0iXX0.DygHHU7yAL-6xyqAbTBg4FdiRIuln9pfZHlqEYnNijyZ2gAGE2tUIP94vZO7iE3q7SUeJcIxg_KWlV4_LHCnZzdbb_NWT7UZpVVPR23cDumjT0-vb8iV3ace3Sr3cLEw5H6blyrHzeIHdEphIS8KEWNvVgZJ6bDYEwqT1mUYHPKNz5_Yot_KKhojN40MqV5gJUy8QhqYjQl8kXD3gJRs7nciaX8CGxc_TuAqvEAd1eZpv478BCsn_bc3H8xT9Qs8ADGewPmF72xIjX1xrG1kudUqQrxgldfzF26Dk0XVCKbBPR7L4VgdQn5-UnNR6MrNMpo3cdrdY9NcYSZZGPfoPw","token_type":"bearer","expires_in":43199,"scope":"clients.read historian_rest_api.read password.write clients.secret historian_rest_api.admin historian_rest_api.write client.admin clients.write uaa.admin scim.write scim.read","jti":"f42f53b4-fcf2-424a-ac43-1853dee1707e"};
var params = {
proxyScheme: undefined /* STRING */,
headers: token /* JSON */,
ignoreSSLErrors: true /* BOOLEAN */,
useNTLM: undefined /* BOOLEAN */,
workstation: undefined /* STRING */,
useProxy: undefined /* BOOLEAN */,
withCookies: undefined /* BOOLEAN */,
proxyHost: undefined /* STRING */,
url: "http://win-hkdrt6do2m5:8080/historian-rest-api/v1/tags?nameMask=*" /* STRING */,
timeout: undefined /* NUMBER */,
appendHeader: undefined /* BOOLEAN */,
proxyPort: undefined /* INTEGER */,
password: undefined /* STRING */,
domain: undefined /* STRING */,
username: undefined /* STRING */
};

// result: STRING
var result = Resources["ContentLoaderFunctions"].LoadText(params);

 

 

LoadText it's a GET operation, you are doing a GET or a PUT/POST?

I'm doing a GET  operation.

Maybe the problem it's on the resolution of server name "win-hkdrt6do2m5" try to set the IP instead in order to test it.

I think we are almost there...
I'm receiving a "connect timed out" error.

That's curious  'cause the same command works for curl.

Top Tags