Skip to main content
6-Contributor
Feb 19, 2024 2:19 AM UTC
Solved

add a subscription to thing via rest api

I need to add a subscription to batch things,how to add subscription to thing via rest api?

VelkumarAnswer
19-Tanzanite
Feb 27, 2024 10:33 AM UTC

Hi @YC_10946483 

 

If you are asking about Dynamic Subscription 

 

You can use the below endpoint

https://<<HOSTNAME>>/Thingworx/Things/<<THINGNAME>>/Services/AddDynamicSubcription

Method : POST
Content-Type : application/json

Body :
{
 propertyName: logicProp,
 eventName: "Alert",
 thingName: undefined,
 serviceName: "SubscriptionActionService" 
}

 

Please refer this article for different input parameters - Article - CS388158 - Working with Dynamic Subscriptions in ThingWorx Platform (ptc.com)

 

/VR

9 replies

19-Tanzanite
Feb 19, 2024 4:28 AM UTC

Hi @YC_10946483 

 

You can add Dynamic Subscription in RunTime or via API

 

Please refer to this article : Article - CS388158 - Working with Dynamic Subscriptions in ThingWorx Platform (ptc.com)

 

/VR

 

 

Translate
6-Contributor
Feb 19, 2024 5:39 AM UTC

This method must  create service before execute AddDynamicSubscription, i need  add a subscription with my javaScript code and deal with some logic,is there any  other method can resolve  this?

Translate
Rocko
19-Tanzanite
Feb 19, 2024 7:47 AM UTC

You could add the service via API before and reference that in AddDynamicSubscription. https://community.ptc.com/t5/IoT-Tips/Create-a-service-dynamically/ta-p/820425

Or you can import a new Thing from XML and you generate the XML to have the code you want.

In any way, when you have code, you will change the Thing Model. Dynamic Subscriptions alone don't change the Thing Model.

Translate