Skip to main content
6-Contributor
Mar 1, 2024 7:30 AM UTC
Solved

Some question about AddDynamicSubscription

 I have added a dynamic subscription  by rest api and i check it out by call 

IsDynamicSubscriptionCreated ,it is yes ;but when i click save in the thingworx  thing page and then i recalled IsDynamicSubscriptionCreated  the answer is no ?
 

YC_10946483_1-1709277868506.png

 

YC_10946483_0-1709277831418.png

YC_10946483_2-1709278192332.png

 

 

19-Tanzanite
Mar 1, 2024 7:40 AM UTC

Hi @YC_10946483,

The Dynamic Subscriptions are created in-memory and are not persisted like a normal subscription (otherwise you would see them anyway in the Subscription page).

You just need to add AddDynamic.... call in the ThingStart event to make sure it's added to the Thing when it restarts.

This information is also present in the help center as a note in this page: https://support.ptc.com/help/thingworx/platform/r9.5/en/#page/ThingWorx/Help/Composer/Things/ThingSubscriptions/ProgrammaticallyEnablingDisablingSubscriptions.html

3 replies

19-Tanzanite
Mar 1, 2024 7:40 AM UTC

Hi @YC_10946483,

The Dynamic Subscriptions are created in-memory and are not persisted like a normal subscription (otherwise you would see them anyway in the Subscription page).

You just need to add AddDynamic.... call in the ThingStart event to make sure it's added to the Thing when it restarts.

This information is also present in the help center as a note in this page: https://support.ptc.com/help/thingworx/platform/r9.5/en/#page/ThingWorx/Help/Composer/Things/ThingSubscriptions/ProgrammaticallyEnablingDisablingSubscriptions.html

Translate
6-Contributor
Mar 1, 2024 7:55 AM UTC

Ok,thanks! Is there any rest api i can add a persisted subscription just like i added in thingworx thing page ?

Translate
19-Tanzanite
Mar 1, 2024 8:12 AM UTC

A direct API not, because generally speaking everything involving Javascript code (creating a service or a subscription) is done through Composer. However, it's entirely possible due to ThingWorx's fully REST-based architecture.

You need to 1. download the XML (GET) 2. Add the subscription in the XML you got the 3. Write back the entity (PUT, which is exactly what Composer does when saving it).

For step 2, if you want to know where to add that subscription you can compare the XML from an entity before and after you add a normal subscription (I use VS Code and its Compare functionality usually here.). And obviously Step 2 needs some sort of logic to manipulate the XML (locate the node then add the subscription to that node)

Translate