Skip to main content
1-Visitor
September 10, 2014
Solved

Retriving the list of DataItems for a specific Asset

  • September 10, 2014
  • 2 replies
  • 5962 views

Hi,

 

How can I retrive the list of dataItems for a specific asset using the API?

The <server>/services/v2/rest/dataItem/find only support modelNumber, name and type as criteria.

If there are many assets that are using the same model the query will return all the dataItems from all assets using the model.

 

Thank you,

Catalin Costea

    Best answer by ckaminski

    In my example, the asset I have has 5 "current" data items in the asset dashboard, and the model has 12 configured data items.  Though my request returns *ALL* model data items, only the "current" data items will have a <v2:value> element in the response data.

    POST: https://INSTANCE/services/v2/rest/dataItem/findCurrentValues

    with Query Body:

    <CurrentDataItemValueCriteria xmlns="http://www.axeda.com/services/v2">

    <assetId>24337</assetId>

    </CurrentDataItemValueCriteria>

    Response:

    <Response xmlns="https://INSTANCE/services/v2/rest/dataItem/findCurrentValues">

       <criteria>

         ....

       </criteria>

       <dataItemValues>

          <e>

             <asset/>

             <dataItem/>

             <value>100</value>  

          </e>

       </dataItemValues>


    This API is behaving as expected, and only populated data is being presented to you with your request.

    Value will be null/not-present for any data item that isn't valid on that Asset, but that is present on the Model.

    2 replies

    5-Regular Member
    September 10, 2014

    Hi Catalin

    Please note that data items are model based and that all assets share the list of data items from the model they belong to.

    Now based on the asset, those data items will change based on thresholds and other changes.

    You could query each asset for their specific data item values both current or historical.

    ccostea11-VisitorAuthor
    1-Visitor
    September 10, 2014

    I know I can query each asset for their data item values. I am looking for the list of the dataItems for a specific device/asset. Is there a way to get this?

    5-Regular Member
    September 10, 2014

    Assuming you have the systemId of the asset, might not the following meet your needs?

    POST: /services/v2/rest/dataItem/findCurrentValues

    <CurrentDataItemValueCriteria xmlns="http://www.axeda.com/services/v2">

       <assetId>24337</assetId>

    </CurrentDataItemValueCriteria>

    10-Marble
    September 22, 2014

    Hi,

    I know this is fairly old now, however i had the same problem to solve for automating our verification, and did so using Timestamp field, perhaps this may be useful to you also?


    import com.axeda.common.sdk.id.Identifier


    import com.axeda.drm.sdk.Context


    import com.axeda.drm.sdk.mobilelocation.CurrentMobileLocationFinder


    import com.axeda.drm.sdk.mobilelocation.MobileLocation


    import net.sf.json.JSONObject


    import com.axeda.drm.sdk.data.*


    import com.axeda.drm.sdk.device.*


    import java.util.*;


    import groovy.xml.MarkupBuilder


    import org.custommonkey.xmlunit.*



    try {




    def deviceSerial = parameters.deviceSerial


    def context = Context.create(parameters.username.toString())




      DeviceFinder df = new DeviceFinder(context)


      df.serialNumber = deviceSerial


      Device device = df.findOne();



      if (device == null) {


        response = [


                params: parameters,


                faultcode: "Runtime Error",


                faultstring: "DEVICE NOT FOUND"


        ]


      } else {


     


        CurrentDataFinder cdf = new CurrentDataFinder(context, device)


        DataValueList dvl = cdf.find()



    writer = new StringWriter()


    xml = new MarkupBuilder(writer)




    xml.root() {



      Device(device.getName())



      for (d in dvl)


      {


      if (d.getTimestamp() != null)


      {


      DataItem(d.dataItem.name)


      }


      }


      }


      }


    }



    catch (Exception ex) {


      writer = new StringWriter()


      xml = new MarkupBuilder(writer)


      xml.Response() {


        Fault {


          Code('Groovy Exception')


          Message(ex.getMessage())


          StringWriter sw = new StringWriter();


          PrintWriter pw = new PrintWriter(sw);


          ex.printStackTrace(pw);


          Detail(sw.toString())


        }


      }


    logger.error(writer.toString());


    }




    return ['Content-Type': 'text/xml', 'Content': writer.toString()]


    I don't include any values etc. although that could easily be included,

    Alan