2 Replies Latest reply on Apr 10, 2017 10:55 AM by mboyle RSS
    mboyle Newbie

    NEWBIE::Why does this service return a INFOTable within the test in Thingworx, but any external calls to return an empty object or string?

    try {

        var devices = Things['ATS.Org'].ListDevices();

        var device;

        result = null;

        //logger.warn(devices)

        for each(device in devices.rows) {

            device = Things[device.EntityName];

     

            if (device.GetLastModifiedDate() > lastDTSCheck) {

               if (result == null) {

                   logger.warn("Result is null");

                   result = Things[device.name].GetPropertyValues();

                   result.name = device.name;

               } else {

                   logger.warn("Got a Result");

                   result.AddRow(Things[device.name].GetPropertyValues().rows[0]);

                   result.rows[result.getRowCount() - 1].name = device.name;

               }

            }

        }

        // I have tried each of these conversions as a means for returning the result object

        //    for an external request ( HTTPie, Postman, Curl, etc) and always get

        //

        //    b'{"dataShape":{"fieldDefinitions":{}},"rows":[]}'

        //

        //logger.warn("debugging the output? ..... " + result);

        //logger.warn("debugging the output 2 as json string" + result.ToJSON() );

        //logger.warn("debugging the output 3 as stringify: " + JSON.stringify(result) );

        //logger.warn("debugging the output 4 as toString: " + result.toString() );

        //result = result.toJSON();

        result

       

    } catch (err) {

      logger.warn(me.name + ".MEB() [err]: " + err + ", " + err.lineNumber);

    }   

      • Re: NEWBIE::Why does this service return a INFOTable within the test in Thingworx, but any external calls to return an empty object or string?
        Ankit Gupta Ninja

        Hi Michael Boyle,

         

        I hope by external call; you mean REST calls. So, you must be using an ThingWorx Appkey for Authentication which is associated to a user.

        Does that user have access to Things['ATS.Org'].ListDevices()? If No; please provide the requisite Permissions to the user.

        What is the result of the Service when we login using this service? Is the result same when we make the REST calls.

        Are there any errors/info in the Application/Script logs when REST call is made?

          • Re: NEWBIE::Why does this service return a INFOTable within the test in Thingworx, but any external calls to return an empty object or string?
            mboyle Newbie

            Thanks for getting back to me. And yes, it is a REST call using the AppKey ( using HTTPie ):

             

             

            http -v -f POST http://xxx.yyyy.com/Thingworx/Things/ATS.Org/Services/DateFilteredDevices appKey=4637bf60-7e1a-42e5-8315-8551ac04ee08 lastDTSCheck=1491322113000

             

            (I also tried using a full timestamp string -- still no data returned).

            Here is an example of the output when I run the service using an EntityList as the data shape:

             

                            b'{"dataShape":{"fieldDefinitions":{}},"rows":[]}'

             

             

            When I create a custom data shape (OrgDateCheck is the name I gave it) I get the definition of the dataShape, but no rows -- again via a REST call. In the Thingworx UI, it always shows my data rows.

             

            As for permissions, the parent object (ATS.Org), under the Run Time tab shows GREEN for Service execute. I also set Visibility to be ALL for my top level object. For my API key, I set Visibility to Allow for everyone. It is my understanding that this is sufficient. Have I missed something with respect to permissions for a service and/or access via an appKey?

            As for logging -- I am getting the correct data from the script log -- details each object and the value-set properly. I do not see any error messages in the Application log. I do see this in the security logs:

            No authType or appKey parameter has been specified for Authentication Scheme: AUTH_THINGWORX_APPKEY

            And thanks again for reaching out: just getting started and there isn't much corporate knowledge at present. I found a good pdf on InfoTables, but have yet to find anything related to permissions on the Thingworx message boards.