Get trends - Metasys - LIT-12013522 - Software Application - Basic Services client library for .NET (and COM) - Metasys API - 4.2

Metasys REST Client for .NET and COM Developer Guide

Product name
Basic Services client library for .NET (and COM)
Metasys API
Document type
API Reference Guide
Document number
Revision date
English (United States)

To get all available samples using a specific time filter, use the GetSamples method. The library delivers a PagedResult that contains a list of Sample. The GetSamples method accepts the GUID of the object, the attribute ID, and a TimeFilter object to filter the response.

Table 1. Get trend samples .NET signature
Library method name GetSamples
Description To get available trends samples
Method signature PagedResult<Sample> GetSamples(Guid objectId, int attributeId, TimeFilter filter);
Method input parameters
  • objectId: GUID of the object the method targets and retrieves the trend samples.
  • attributeId: numeric identifier of the attribute configured for the trend.
  • filter: filter object that specifies the start time and the end time the method uses to filter the target samples.
Return value A PagedResult of Sample.
The following .NET C# code is an example of a successful get trends response:
Guid trendedObjectId = client.GetObjectIdentifier("Win2016-VM2:vNAE2343701/Field Bus MSTP1.VAV-08.ZN-T");
// Get attributes where trend extension is configured
List<Attribute> trendedAttributes = client.Trends.GetTrendedAttributes(trendedObjectId);
int attributeId = trendedAttributes[0].Id;
TimeFilter timeFilter = new TimeFilter
    StartTime = new DateTime(2020, 5, 12),
    EndTime = new DateTime(2020, 5, 13)
PagedResult<Sample> samplesPager = client.Trends.GetSamples(trendedObjectId, attributeId, timeFilter);              
// Prints the number of records fetched and paging information
Console.WriteLine("Total:" + samplesPager.Total);
Console.WriteLine("Current page:" + samplesPager.CurrentPage);
Console.WriteLine("Page size:" + samplesPager.PageSize);
Console.WriteLine("Pages:" + samplesPager.PageCount);
Current page:1
Page size:100
Sample firstSample = samplesPager.Items.FirstOrDefault();
    "Value": 82.0,
    "Unit": "deg F",
    "Timestamp": "2020-05-12T05:00:00Z",
    "IsReliable": true