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

Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X

Consume REST API that needs token

Saitoisonfire
12-Amethyst

Consume REST API that needs token

Hi All,

 

I need to use a web service that needs authorization and consumes a token for it.
I know that I need to use some of the snippets function (ContentLoaderFunctions),
but I need someone to provide me some kind of example 'cause none of them has a field that uses my token.

 

Thanks,

Anselmo.

1 ACCEPTED SOLUTION

Accepted Solutions

Looks like we cant use a webservice that consumes a token...

And that's the answer.

View solution in original post

8 REPLIES 8

You will most likely need to declare that token through the header.

Something like "token:laksjdflksdajfladsjfjdsk"

Something like this?

var token = {token:"abcdef"};
var params = {
headers: token /* JSON */,
ignoreSSLErrors: true /* BOOLEAN */,
url: "http://mymachine:8080/myapi" /* STRING */,
timeout: 30 /* NUMBER */,
};

 

Well, it didnt work out.

See the error mesage below:

Error executing service MyService. Message :: Connect to 192.168.229.139:8080 [/192.168.229.139] failed: connect timed out - See Script Error Log for more details.

Nobody?

Hello?

When you tried that call what was the response? Check application log.

Can you list the actual documentation of the API call?

The only response I received was this error mesage:
Error executing service MyService. Message :: Connect to 192.168.229.139:8080 [/192.168.229.139] failed: connect timed out - See Script Error Log for more details.

 

Documentation (my command is described in the page 26):
http://help.geautomation.com/Historian55/Subsystems/iHistGS/content/restapi.pdf

The Manual you linked states the following example:

curl -i -H "Accept: application/json" -H "Authorization: Bearer <TOKEN>” https://<nodename>:8443/
SAMPLE cURL COMMAND:historian-rest-api/v1/tags?nameMask=*&maxNumber=<Number_Of_Tags>

 

That seems to say that you can define it in the header not as token: token value but looks like

Authorization: Bearer tokenValue

Looks like we cant use a webservice that consumes a token...

And that's the answer.

Top Tags