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

Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X

Get Subscriptions for Template and Thing

jmay1
10-Marble

Get Subscriptions for Template and Thing

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

4 REPLIES 4
AdamR
14-Alexandrite
(To:jmay1)

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...

    }

}

jmay1
10-Marble
(To:AdamR)

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.

jmay1
10-Marble
(To:AdamR)

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"

  }

}

Announcements


Top Tags