Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X
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
Solved! Go to Solution.
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.
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.
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?
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>
Theoretically yes, it will be a good workaround and I can parse the items list from the response.
Unfortunately is returning the list of all dataItems associated with the model that is mapped with the assetId.
Any other suggestions are welcome.
Thank you.
The following seemed to work for me:
POST: /services/v2/rest/dataItem/findHistoricalValues
Depending on how tight your time window is will determine how many data items get returned. Each dataitem could return multiple values of itself depending on retention history and activity.
In my case the Dashboard shows 5 data items for this asset, and this query returns 5 data items.
This is working in a way, it is true this only returns dataItemsValues for the current Asset but the dataItems are repeating and since I have many values in response ("totalCount" : 63010 until now) it will be kinda awkward parse it all to create a set of 5 unique dataItems ...
The solution with /services/v2/rest/dataItem/findCurrentValues was perfect if it was working.
Current values is the way to go. If an asset has a data item, the most recent value will appear in the current table. With historical, it had to have been received within the date range. And the query will probably be less efficient since the table can be much larger.
Current values is returning the list of all dataItems associated with the model that is mapped with the assetId ...
Ignore the ones with null value?
I have no DataItemValue with null or empty values in response. I should be 5 items but I'm getting 7 because there are 2 other assets using the same model.
Depending on the particular design characteristics of this service, this may be considered a defect. Personally I would expect the CurrentDataItems query to do what you expect, which is reflect what's shown on the Dashboard.
I would suggest opening a support case .
http://www.axeda.com/community/services-support
Case 109511 has been submitted.
Thank you guys for your answers.
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.
Meaning that some of the values may not be populated for this particular device?
If you need a list of just populated values, you may need to build a scripto service to do the API work of pulling the current value list and only including the populated values in the reponse.
Alternatively, you can just ignore null or empty values in your consumer and use the default web service?
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