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

Consume REST API services in Thingworx

SOLVED
Highlighted
Level 3

Consume REST API services in Thingworx

Hi Team,

I am new to Thingworx and still learning basic stuff. Can anyone help me with how to consume third party web services(REST API) in Thingworx?

May be this topic is already discussed but i am not able to find it. . Do i need to do it using extension or EDGE will help me achieve this.

My requirement is: I have to call http://......axeda.com/services/v1/rest/ services in Thingworx to read response and display it in Mashup.

Please share any sample or tutorials or guides to do it. Anything related to above topic will be very helpful.

Thanks everyone in advance.

Ravi

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Consume REST API services in Thingworx

Hi Ravi,

The ability to call webservices is one of the most used features that we have Out-Of-The-Box in ThingWorx.

Presuming you're already familiar with the platform, you'll just need to use the Snippets from the section "ContentLoaderFunctions".

They offer wrappers for all the HTTP verbs: POST, PUT, GET, DELETE.

If you hover the mouse over each snippet you'll see the documentation in a popup on the screen.

Best regards,

Vladi

9 REPLIES 9

Re: Consume REST API services in Thingworx

Hi Ravi,

The ability to call webservices is one of the most used features that we have Out-Of-The-Box in ThingWorx.

Presuming you're already familiar with the platform, you'll just need to use the Snippets from the section "ContentLoaderFunctions".

They offer wrappers for all the HTTP verbs: POST, PUT, GET, DELETE.

If you hover the mouse over each snippet you'll see the documentation in a popup on the screen.

Best regards,

Vladi

Re: Consume REST API services in Thingworx

Thanks Vladi for your response.

I am new to this framework and going to take training from PTC next week but i have some idea and was able to find ContentLoaderFunctions in Things->Services->Snippet.

Still lot to explore. Can you please recommend some samples on ContentLoaderFunctions. I have PTC(PrecisionLMS account).

Thanks

Ravi

Re: Consume REST API services in Thingworx

Hi Ravi,

So, the best way to do this would be to first take the training, then go to explore the snippets, as lots of things will make more sense in this way.

Regarding an usage example, it's really simple:

1. Put the url that you want to call in the URL parameter of the GetText function (as an example, of course you can run any of the other functions)

2. Run the service where you put this snippet.

3. If you want to see the result of this service, set the output as STRING as well.

Again, I think it makes more sense to go through the training first, then use the snippets.

Hope it helps

Vladi

Re: Consume REST API services in Thingworx

Hi Vladimir Rosu,

I  need to pass multiple body parameters say 5 parameters in body section. Not sure where to add those details in the GetText of ContenLoader fucntions?

var params = {

  proxyScheme: undefined /* STRING */,

  headers: undefined /* JSON */,

  ignoreSSLErrors: undefined /* 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 */

};

// result: STRING

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

Given above is the GetText service code. Please let me know where to add the five parameters of the body section which usually we pass in a REST API call based on the need.

Re: Consume REST API services in Thingworx

Hi Ravi,

The GET verb doesn't have a body in which you can send the data. With GET you can only pass the data in the URL, with URL parameters.

If you want to pass data which doesn't fit in an URL parameter you can use the Post verb.

BR

Re: Consume REST API services in Thingworx

NeedToConsumeRestAPIFromThingworx.png

Hi Vladimir,

I need to make the above rest call from Thingworx code. I am not sure where to add the above mentioned body parameter details in posttext service.

Let me know if there are other suitable content loader functions.

var params = {

  proxyScheme: undefined /* STRING */,

  headers: undefined /* JSON */,

  ignoreSSLErrors: undefined /* BOOLEAN */,

  useNTLM: undefined /* BOOLEAN */,

  workstation: undefined /* STRING */,

  useProxy: undefined /* BOOLEAN */,

  withCookies: undefined /* BOOLEAN */,

  proxyHost: undefined /* STRING */,

  url: undefined /* STRING */,

  content: undefined /* STRING */,

  timeout: undefined /* NUMBER */,

  proxyPort: undefined /* INTEGER */,

  password: undefined /* STRING */,

  domain: undefined /* STRING */,

  contentType: undefined /* STRING */,

  username: undefined /* STRING */

};

// result: STRING

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

Note: you can give any examples for passing these kind of parameters , please let me know.

Re: Consume REST API services in Thingworx

Hi,

There are 2 choices: either as url parameters in the URL or in the content variable.

I don't use postman so I can't really advise on which of the above to choose. The REST client that I use is SoapUI, which has the option of showing you the raw HTTP request that was sent so you can see the format in which the data was sent if you send it in the body of the post.

Re: Consume REST API services in Thingworx

could you provide an example making REST API callusing the content variable for passing multiple parameters?

Re: Consume REST API services in Thingworx

Anybody is consuming REST API calls inside thingworx and passing multiple parameters to the same call?

If yes, please post an example of how to achieve the same inside thingworx service code.