Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X
Hi,
I am trying to update Kepware Tag through API call from IOT Gateway setup.
Refering the document in http://127.0.0.1:39320/iotgateway/
I am using this API
http://127.0.0.1:39320/iotgateway/write |
to update a tag. Based on the example given, I was able to successfully run the API through Postman but unable to run it through Thingworx API.
cURL example given in the doc:
curl -H "Content-Type: application/json" -vX POST -d "[{ \"id\": \"Channel1.Device1.tag1\", \"v\": 42},{ \"id\": \"Channel1.Device1.tag2\", \"v\": 17},{ \"id\": \"Channel1.Device1.tag3\", \"v\": 36}]" http://127.0.0.1:39320/iotgateway/write
In postman which is on same server:
(POST) http://127.0.0.1:39320/iotgateway/write
input in json format :
Thingworx server on the same instance
try{
var Obj = [{'id': 'Channel1.Device1.status','v': 1}];
let params = {
proxyScheme: undefined /* STRING {"defaultValue":"http"} */,
headers: {'Content-Type': 'application/json'} /* JSON */, // also tried keeping it as undefined
ignoreSSLErrors: undefined /* BOOLEAN */,
useNTLM: undefined /* BOOLEAN {"defaultValue":false} */,
workstation: undefined /* STRING {"defaultValue":""} */,
useProxy: undefined /* BOOLEAN {"defaultValue":false} */,
withCookies: undefined /* BOOLEAN {"defaultValue":false} */,
proxyHost: undefined /* STRING {"defaultValue":""} */,
url: "http://127.0.0.1:39320/iotgateway/write" /* STRING */,
content: Obj /* JSON */,
timeout: undefined /* NUMBER {"defaultValue":60} */,
proxyPort: undefined /* INTEGER {"defaultValue":8080} */,
password: undefined /* STRING */,
domain: undefined /* STRING {"defaultValue":""} */,
username: undefined /* STRING */
};
// result: JSON
var result = Resources["ContentLoaderFunctions"].PostJSON(params);
} catch(err){
// result = err;
}
Output (Type Json) : Service execution failed. An input value is required.
I fond a post and also tried to run the cURL in the service, but it didnt work.
let params = {
proxyScheme: undefined /* STRING {"defaultValue":"http"} */,
headers: undefined /* JSON */,
ignoreSSLErrors: undefined /* BOOLEAN */,
useNTLM: undefined /* BOOLEAN {"defaultValue":false} */,
workstation: undefined /* STRING {"defaultValue":""} */,
useProxy: undefined /* BOOLEAN {"defaultValue":false} */,
withCookies: undefined /* BOOLEAN {"defaultValue":false} */,
proxyHost: undefined /* STRING {"defaultValue":""} */,
url: 'curl -H "Content-Type: application/json" -vX POST -d "[{ \"id\": \"Channel1.Device1.status\", \"v\": 1}]" http://127.0.0.1:39320/iotgateway/write' /* STRING */,
timeout: undefined /* NUMBER {"defaultValue":60} */,
appendHeader: undefined /* BOOLEAN {"defaultValue":true} */,
proxyPort: undefined /* INTEGER {"defaultValue":8080} */,
password: undefined /* STRING */,
domain: undefined /* STRING {"defaultValue":""} */,
username: undefined /* STRING */
};
// result: STRING
let result = Resources["ContentLoaderFunctions"].LoadText(params);
So how do i work with this API in service.
Thanks
Solved! Go to Solution.
For the sake of others in the community, the following solution was found after opening a case:
Regards.
--Sharon
Try open a new "Case", here: https://support.ptc.com/apps/case_logger_viewer/cs/auth/ssl/log
Hello,
UPDATE
I did some quick testing with this. I was able to get the REST call to execute properly but not having a IoT Gateway configured I could not get it to complete. I end up with the error below (which is expected):
Error executing service WriteTag. Message :: Connect to 127.0.0.1:39320 [/127.0.0.1] failed: Connection refused: connect - See Script Error Log for more details.
What I believe is happening is that your try/catch is consuming the otherwise helpful error which is resulting in an unset result value. When result is unset you will see "Service execution failed. An input value is required.".
I would recommend removing your try/catch and seeing what error you end up with. It will likely be helpful such as pointing to an SSL issue for instance.
Out of this recommendation you can proceed to open a case. Once we have a Technical Support case we can look further into setting up a test case with an IoT Gateway and reproducing this internally.
Tyler Misner
Senior Technical Support Engineer
For the sake of others in the community, the following solution was found after opening a case:
Regards.
--Sharon