Skip to main content
6-Contributor
February 19, 2024
Solved

add a subscription to thing via rest api

  • February 19, 2024
  • 1 reply
  • 2596 views

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

Best answer by Velkumar

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

1 reply

19-Tanzanite
February 19, 2024

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

 

 

6-Contributor
February 19, 2024

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?

Rocko
19-Tanzanite
February 19, 2024

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.