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

Get Subscriptions for Template and Thing

Highlighted
Regular Member

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

Re: Get Subscriptions for Template and Thing

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

    }

}

Re: Get Subscriptions for Template and Thing

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.

Re: Get Subscriptions for Template and Thing

Could you tell me the syntax if I wanted to use the application key vs the username and password?

Re: Get Subscriptions for Template and Thing

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"

  }

}