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

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

RestApi from ThingWorx to external Platform

Giuseppe_Fiore
15-Moonstone

RestApi from ThingWorx to external Platform

I need to send some property related to a Thing to an external platform, using RESTAps using the PUT method. Can you have an example of how to use the parameter function that you need to use in the PUTJSON snippet?

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 /* JSON */,

  timeout: undefined /* NUMBER */,

  proxyPort: undefined /* INTEGER */,

  password: undefined /* STRING */,       

  domain: undefined /* STRING */,

  username: undefined /* STRING */       

};

// result: JSON

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

example of data :

Temperature : 10

Pression :       25

Nome Thing P1

What are the parameters required for data transfer and how should they be configured?


thanx

Giuseppe Fiore

5 REPLIES 5

You have it a sample on previous params set variable.

Hi, Carles

These are properties with the values ​​to be transferred.

Thing Name : P1

Property :  Temperature       Value :10

Property :  Pression           Value : 25

Do you mean these parameters?

thnx

Giuseppe

No I mean this variable:

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 /* JSON */,

  timeout: undefined /* NUMBER */,

  proxyPort: undefined /* INTEGER */,

  password: undefined /* STRING */,      

  domain: undefined /* STRING */,

  username: undefined /* STRING */      

};

Your JSON properties should be set on previous params content property, something like ( of course you must fill more parameters in order to make it work ):

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: {

                Temperature: 10,

                 Pression: 25,

                 ThingName: "P1"

               }

   ,

  timeout: undefined /* NUMBER */,

  proxyPort: undefined /* INTEGER */,

  password: undefined /* STRING */,      

  domain: undefined /* STRING */,

  username: undefined /* STRING */      

};

I try this , but the property not change on the other pc with Thinworxs installed.

Where am I wrong? :-(

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:"http://xx.xx.xx.xx/ThingWorx/Things/P1/Properties" /* STRING */,

  content: {

                NomePub: "Test",

                Birra1: "Test",

                ThingName: "P1"

                 }  /* JSON */,

   

  password: "admin" /* STRING */,

  username: "Administrator" /* STRING */

};

// result: JSON

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

On the monitoring of thingworx receiving is :

[message: Invalid API Request: url [/Things/P1/Properties/] method [PUT]]



Thnx

Giuseppe

You have two TW Instances? if that's the case, maybe you want to federate them, this way you will have a tunnel between booths and then you can call services on remote things and alike.

Top Tags