Skip to main content
PI System
OSIsoft
Programming
PI Web API
Data Analysis

Mastering the PI Web API: From Beginner to Advanced

Master the PI Web API from beginner to advanced levels. Learn core functionalities, data manipulation, and advanced techniques like batch requests and streaming updates. Navigate the documentation and utilize code samples for effective API usage.

Roshan Soni

7 min read

Welcome to your comprehensive guide on using the PI Web API, designed to take you from a beginner to an advanced user. Whether you're new to the PI System or looking to deepen your understanding, this blog will cover the core functionalities of the PI Web API and how to utilize them effectively with various tools. We'll also explore how to navigate the PI Web API documentation so you can independently find the information you need as you progress.

Table of Contents

  1. What is the PI Web API?
  2. Key Features and Benefits
  3. Comparing PI Web API with Other Developer Technologies
  4. Getting Started: Simple Read Requests
  5. Manipulating Data: Write Requests
  6. Advanced Topics
    • Generating Web IDs Client-Side
    • Executing Batch Requests
    • Subscribing to Streaming Updates
  7. Navigating the PI Web API Documentation
  8. Utilizing Code Samples and Resources
  9. Conclusion

1. What is the PI Web API?

The PI Web API is a RESTful web service that provides programmatic access to the PI System using HTTP requests. Built on ASP.NET Web API, it leverages the AF SDK (Asset Framework Software Development Kit) for underlying data access. The PI Web API adheres to REST principles, ensuring a stateless, client-server architecture where each request is an independent transaction.

RESTful Principles in PI Web API

  • Client-Server Architecture: Separates client and server concerns.
  • Stateless Interactions: No client context is stored on the server between requests.
  • Resource-Oriented: Interactions are organized around resources like assets, data servers, points, elements, attributes, and event frames.
  • Navigable Links: Responses include hyperlinks to related resources, facilitating easy navigation.

2. Key Features and Benefits

  • Platform Agnostic: Accessible from any platform or programming language that supports HTTP requests.
  • Flexibility: More adaptable compared to other PI System developer technologies, especially in heterogeneous environments.
  • Scalability: Suitable for building web and mobile applications that interact with the PI System.
  • Ease of Integration: Simplifies the process of integrating PI System data into existing workflows and applications.

3. Comparing PI Web API with Other Developer Technologies

OSIsoft offers several developer technologies for interacting with the PI System:

PI Web API

  • Pros:
    • Platform-independent.
    • Utilizes standard web protocols.
    • Easy to integrate with web and mobile applications.
  • Cons:
    • Performance is inherently tied to HTTP overhead.
    • Functionality is a subset of what AF SDK provides.

AF SDK

  • Pros:
    • Comprehensive functionality.
    • Best performance due to direct access.
  • Cons:
    • Limited to .NET languages.
    • Only supports Windows operating systems.

PI SQL Products

  • Pros:
    • Exposes the PI System as a relational database.
    • Familiar to those with SQL backgrounds.
  • Cons:
    • Limited features compared to PI Web API and AF SDK.
    • Read-only access to certain components like the AF Server.

4. Getting Started: Simple Read Requests

The journey begins with making simple read requests using a web browser or tools like Postman. This foundational step helps you understand how to retrieve data from the PI System.

Example: Retrieving an Element

GET https://your-server/piwebapi/elements/{webId}
  • Parameters:
    • {webId}: The Web ID of the element you want to retrieve.
  • Response:
    • JSON representation of the element, including links to related resources.

5. Manipulating Data: Write Requests

Once you're comfortable with read operations, you can move on to write requests to create, update, or delete data within the PI System.

Example: Creating a New Element

POST https://your-server/piwebapi/elements
Content-Type: application/json

{
  "Name": "New Element",
  "Description": "Created via PI Web API",
  "TemplateName": "Your Template"
}
  • Note: Write operations require appropriate permissions and should be performed cautiously to avoid unintended data manipulation.

6. Advanced Topics

As you progress, you'll delve into more complex functionalities that can enhance your applications and workflows.

Generating Web IDs Client-Side

  • Purpose: Allows you to generate Web IDs without making a request to the server.
  • Benefit: Reduces the number of network calls, improving performance.

Executing Batch Requests

  • Purpose: Enables you to execute multiple requests in a single HTTP call.
  • Benefit: Minimizes latency and improves efficiency when performing bulk operations.

Subscribing to Streaming Updates

  • Purpose: Allows clients to receive real-time updates from the PI System.
  • Benefit: Essential for applications that require live data feeds.

7. Navigating the PI Web API Documentation

Understanding how to effectively use the documentation is crucial for long-term success.

  • API Reference: Provides detailed information on endpoints, parameters, and response formats.
  • Developer Guides: Offer tutorials and best practices.
  • Search Functionality: Helps you quickly find the information you need.

Tips

  • Bookmark Important Sections: Quick access to frequently used pages.
  • Use Code Samples: Leverage examples to understand implementation.

8. Utilizing Code Samples and Resources

OSIsoft maintains a GitHub repository with sample code that can accelerate your learning.

  • Languages: Samples are available in multiple programming languages like Python, C#, and JavaScript.
  • Applications: Demonstrate common use cases and advanced functionalities.
  • Community Contributions: Benefit from and contribute to community knowledge.

9. Conclusion

Embarking on the journey to master the PI Web API opens up a world of possibilities for interacting with the PI System. From simple data retrieval to advanced real-time applications, the PI Web API provides the tools you need to build robust, scalable solutions. By starting with the basics and progressively tackling more complex topics, you'll develop a deep understanding that will serve you well in any project involving the PI System.


Additional Resources

  • PI Web API Online Documentation: [Link to documentation]
  • OSIsoft GitHub Samples: [Link to GitHub repository]
  • Community Forums: [Link to forums]

Happy coding!

Tags

#OSIsoft
#PI System
#AFSDK
#PI Web API
#Programming
#Data Access
#API
#C#

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