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

How to create things via remote sdk

Highlighted
Newbie

How to create things via remote sdk

I want my new remote thing (which uses the tw-c-sdk) to appear on the Thingworx server automatically.

     The device has a (non-admin) customer key- and it should appear in the appropriate account.

These are the steps

1-The device connects to Thingworx

2-It attempts twApi_PushProperties

     twApi_PushProperties fails and returns an TW_INTERNAL_SERVER_ERROR result   

(Question # 1 is there a more specific way to respond to the Thing doesn't exist error - The trace reason explains that the Thing entity is unbound - but all I get is a simple number?)

I have a Thing (HEDCommissionThing) created with a Service call CreateHEDEntity I pass it a name, and it calls Resources["EntityServices"].CreateThing(params)

- I know this works, because it creates the Thing on the server if I execute it from within Thingworx Composer

3-When I receive the TW_INTERNAL_SERVER_ERROR from above I call the service using :

twApi_InvokeService(TW_THING, "HEDCommissionThing", "CreateHEDEntity", it, &result, -1, FALSE);

It fails with the following (From the TRACE):

Reason: Unable to dispatch [ uri = /Things/HEDCommissionThing/Services/CreateHEDEntity/]: Unable to Invoke Service CreateHEDEntity on HEDCommissionThing : Execution error in service script [HEDCommissionThing CreateHEDEntity] : Wrapped com.thingworx.common.exceptions.InvalidRequestException: Not authorized for ServiceInvoke on CreateThing in EntityServices Cause: Not authorized for ServiceInvoke on CreateThing in EntityServices

I have added the user with full run-time and design permission to HEDCommissionThing and to its Template   There isn't a way to add it to EntityServices (not that I have found anyways).

(Question # 2 What am I doing wrong, or is there a better approach?)


I really want the newly created object to be assigned to the correct Customer



3 REPLIES 3
Highlighted

Re: How to create things via remote sdk

One way is to create a service that creates the required remote thing and your device (appkey) will need to have access to run this service. Please refer this Java SDK example - Creating a Thing from a Virtual Thing Service (Java SDK)

The service may be invoked every time the SDK starts and connects. The example service may be modified to do nothing, if the thing already exists.

Highlighted

Re: How to create things via remote sdk

I essentially tried that and I got the following error, any suggestions?

Reason: Unable to dispatch [ uri = /Things/HEDCommissionThing/Services/CreateHEDEntity/]: Unable to Invoke Service CreateHEDEntity on HEDCommissionThing : Execution error in service script [HEDCommissionThing CreateHEDEntity] : Wrapped com.thingworx.common.exceptions.InvalidRequestException: Not authorized for ServiceInvoke on CreateThing in EntityServices Cause: Not authorized for ServiceInvoke on CreateThing in EntityServices

Highlighted

Re: How to create things via remote sdk

Ensure that your user (appkey) has execute access for CreateHEDEntity service. You can add permission from Run time tab of HEDCommissionThing.

Announcements

Thingworx Navigate content has a new home! Click here to access the new Thingworx Navigate forum!