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

Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X

How to give permission to a particular thingtemplate in Thingworx using API

MM_9023322
15-Moonstone

How to give permission to a particular thingtemplate in Thingworx using API

Hi all,

I want to give permission to ThingTemplate to say "Template1" through API. What is the snippet used for it?

 

 

Thank you!

ACCEPTED SOLUTION

Accepted Solutions
PaiChung
22-Sapphire I
(To:MM_9023322)

Here is an example

ThingTemplates[Entity].AddInstanceRunTimePermission({
principal: GroupName /* STRING */,
allow: true /* BOOLEAN */,
resource: ServiceName /* STRING */,
type: "ServiceInvoke" /* STRING */,
principalType: "Group" /* STRING */
});

 

or for a collection:

Resources["CollectionFunctions"].AddCollectionRunTimePermission({
principal: "System" /* STRING */,
allow: true /* BOOLEAN */,
resource: "*" /* STRING */,
type: "ServiceInvoke" /* STRING */,
principalType: "User" /* STRING */,
collectionName: "Things" /* STRING */
});

 

So you can call something like this with an API call using <server>/Thingworx/ThingTemplates/Services/AddInstanceRunTimePermission

For design time you would do AddInstanceDesignTimePermission

Also for the Template itself vs. instance, just remove the word instance.

 

 

!!Caution: If you are looking to do this through API calls, set proper security so that you don't open things up to allow the application key user to set permissions where they shouldn't or do other things. I recommend you create a specific service that does things within a defined context and scope and give permission to the appkey user to run that service only. Then from within that service you can validate and secure and use the system user to invoke the add permission services.

View solution in original post

2 REPLIES 2
PaiChung
22-Sapphire I
(To:MM_9023322)

Here is an example

ThingTemplates[Entity].AddInstanceRunTimePermission({
principal: GroupName /* STRING */,
allow: true /* BOOLEAN */,
resource: ServiceName /* STRING */,
type: "ServiceInvoke" /* STRING */,
principalType: "Group" /* STRING */
});

 

or for a collection:

Resources["CollectionFunctions"].AddCollectionRunTimePermission({
principal: "System" /* STRING */,
allow: true /* BOOLEAN */,
resource: "*" /* STRING */,
type: "ServiceInvoke" /* STRING */,
principalType: "User" /* STRING */,
collectionName: "Things" /* STRING */
});

 

So you can call something like this with an API call using <server>/Thingworx/ThingTemplates/Services/AddInstanceRunTimePermission

For design time you would do AddInstanceDesignTimePermission

Also for the Template itself vs. instance, just remove the word instance.

 

 

!!Caution: If you are looking to do this through API calls, set proper security so that you don't open things up to allow the application key user to set permissions where they shouldn't or do other things. I recommend you create a specific service that does things within a defined context and scope and give permission to the appkey user to run that service only. Then from within that service you can validate and secure and use the system user to invoke the add permission services.

MM_9023322
15-Moonstone
(To:PaiChung)

@PaiChung , thank you so much for sharing the information, it worked for me.

 

 

Thank you!!

Announcements


Top Tags