Skip to main content
PI System
Data Optimization
Web API

Optimizing PI Web API Requests: Efficient Attribute Value Retrieval

Explore how to efficiently retrieve PI System attribute values using PI Web API's StreamSet controller, optimizing application performance with bulk requests.

Roshan Soni

4 min read

Optimizing PI Web API Requests: Efficient Attribute Value Retrieval

In today's fast-paced digital environment, optimizing our data retrieval processes can significantly impact the performance of applications, especially when working with large datasets like those managed by the OSIsoft PI System. One common scenario is retrieving values of specific attributes across a hierarchy using the PI Web API, a RESTful interface to the PI Server.

The Challenge: Bulk Retrieval of Specific Attributes

When developing applications that interact with the PI System, there may be a need to retrieve values of attributes that share a specific name (for example, 'Attribute1') from a parent element and all its descendant elements. Retrieving these values efficiently, particularly when dealing with large hierarchies, poses a challenge. Ideally, you would want to avoid making multiple requests to reduce latency and improve overall performance.

Solution: Using the StreamSet Controller's GetValues Action

One effective way to achieve this is by leveraging the GetValues action of the StreamSet controller in the PI Web API. This approach allows for efficient retrieval of data in a single request, minimizing network overhead and optimizing data processing time. Here’s how you can configure your request:

  1. Identify the Root Element: Obtain the WebId of the parent element from which you wish to begin your search. This WebId serves as the starting point for your data retrieval query.

  2. Use the nameFilter Parameter: Set the nameFilter parameter to the specific attribute name you wish to retrieve, such as "Attribute1". This ensures the API returns only the attributes that match this filter.

  3. Enable Full Hierarchy Search: By setting the searchFullHierarchy flag to true, the request will propagate through the entire hierarchy, fetching attributes that match the name filter across the root element and all its descendants.

Implementation Example

Below is a conceptual implementation outline of how this request can be structured in your application:

let parentElementWebId = "<WebId of parent element>";
let baseUrl = "https://your_piwebapi_server/piwebapi/streamsets/{0}/recorded?nameFilter=Attribute1&searchFullHierarchy=true";
let requestUrl = baseUrl.replace("{0}", parentElementWebId);

fetch(requestUrl, {
    method: 'GET',
    headers: {
        'Accept': 'application/json',
        'Authorization': 'Basic ' + btoa('username:password')
    }
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error fetching attribute values:', error));

Conclusion

By using the StreamSet controller's GetValues action, developers can efficiently retrieve bulk attribute values within a hierarchy, thereby optimizing application performance. This method not only consolidates multiple actions into a single request but also streamlines data processing. When building robust PI System-based applications, leveraging such optimized API calls is critical for maintaining speed and efficiency.

For further customization or additional data retrieval needs, consider exploring the full capabilities of the PI Web API documentation. Implementing efficient data querying strategies helps ensure your application scales well with your PI System's growth, providing seamless and reliable performance for end-users.

Tags

#PI Web API
#Data Optimization
#Attribute Retrieval
#StreamSet Controller

About Roshan Soni

Expert in PI System implementation, industrial automation, and data management. Passionate about helping organizations maximize the value of their process data through innovative solutions and best practices.

Sign in to comment

Join the conversation by signing in to your account.

Comments (0)

No comments yet

Be the first to share your thoughts on this article.

Related Articles

Enhancing PI ProcessBook Trends with Banding and Zones: User Needs, Workarounds, and the Road Ahead

A look at the user demand for trend banding/zoning in OSIsoft PI ProcessBook, current VBA workarounds, UI challenges, and how future PI Vision releases aim to address these visualization needs.

Roshan Soni

Migrating PIAdvCalcFilVal Uptime Calculations from PI DataLink to PI OLEDB

Learn how to translate PI DataLink's PIAdvCalcFilVal advanced calculations—like counting uptime based on conditions—into efficient PI OLEDB SQL queries. Explore three practical approaches using PIAVG, PIINTERP, and PICOunt tables, and get tips for validation and accuracy.

Roshan Soni

Understanding PI Web API WebID Encoding: Can You Generate WebIDs Client-Side?

Curious about how PI Web API generates WebIDs and whether you can encode them client-side using GUIDs or paths? This article explores the encoding mechanisms, current documentation, and best practices for handling WebIDs in your applications.

Roshan Soni