Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X
Hello,
Is there a service to return the defined subscriptions for a template and for a Thing? I'm looking to list all alert subscriptions in a mashup, by both Template, and unique device.
Thank you,
Jenna
There is no built in service for extracting this information. All aspects of an entity can be retrieved via a rest call from the service code. This is not ideal but from service script it is a way to access the values needed...
var params = {
url: "http://localhost/Thingworx/Things/MyThingName?Accept=application/json",
password: "admin",
username: "Administrator"
};
var jsonVal = Resources["ContentLoaderFunctions"].GetJSON(params);
for (var subs in jsonVal.effectiveShape.subscriptions) {
var subscription = jsonVal.effectiveShape.subscriptions[subs];
if (subscription.eventName == "Alert") {
//Found an alert subscription!!!
YourCodeHere - Add to infotable, take action on subscription, etc...
}
}
Thank you. This is very helpful. How can I find out what else is returned? Like if I were to create the infotable here and add to it, what columns could I have? subsription.eventName, subscription.whatelsehere?
Not sure if I'm making sense here.
Could you tell me the syntax if I wanted to use the application key vs the username and password?
Hi Jenna,
Do do it through AppKey:
var params = {
url: "http://localhost/Thingworx/Things/MyThingName",
headers: {
"Content-Type": "application/json",
"appKey": "yourAppKey",
"Accept": "application/json"
}
}