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

Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X

add a subscription to thing via rest api

YC_10946483
6-Contributor

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?

ACCEPTED SOLUTION

Accepted Solutions
Velkumar
19-Tanzanite
(To:YC_10946483)

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

View solution in original post

9 REPLIES 9
Velkumar
19-Tanzanite
(To:YC_10946483)

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

 

 

YC_10946483
6-Contributor
(To:Velkumar)

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?

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.

YC_10946483
6-Contributor
(To:Velkumar)

can  provide a example  show how to add a subscription to thing via API?

Velkumar
19-Tanzanite
(To:YC_10946483)

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

YC_10946483
6-Contributor
(To:Velkumar)

i find that  AddDynamicSubscription only work with local service but cannot call remote edge  service , is it right?

YC_10946483_0-1709172669983.png

 

Velkumar
19-Tanzanite
(To:YC_10946483)

Hi @YC_10946483 

 

You can call another thing service. Please mention the edge thing name in the input parameter "thingName".

Velkumar_0-1709176569525.png

 

/VR

YC_10946483
6-Contributor
(To:Velkumar)

this thingName which i filled is a  edge thing and this serviceName is in this thing 

 

YC_10946483_1-1709177003475.png

YC_10946483_2-1709177113690.png

 

 

Velkumar
19-Tanzanite
(To:YC_10946483)

It should work. Dynamic Subscription won't be visible in composer.

 

You can use "IsDynamicSubscriptionCreated" to check whether the service is created or not

 

/VR

 

 

Announcements


Top Tags