PI World 2020 Lab Using PI Web API

PI World 2020 Lab

Using PI Web API

From Beginner to Advanced (v1.0)

Operational IntelligenceCopyright Copyright & Trademark ? Copyright 1995-2020 OSIsoft, LLC 1600 Alvarado Street San Leandro, CA 94577 ? 2020 by OSIsoft, LLC. All rights reserved. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, mechanical, photocopying, recording, or otherwise, without the prior written permission of OSIsoft, LLC. OSIsoft, the OSIsoft logo and logotype, Managed PI, OSIsoft Advanced Services, OSIsoft Cloud Services, OSIsoft Connected Services, PI ACE, PI Advanced Computing Engine, PI AF SDK, PI API, PI Asset Framework, PI Audit Viewer, PI Builder, PI Cloud Connect, PI Connectors, PI Data Archive, PI DataLink, PI DataLink Server, PI Developers Club, PI Integrator for Business Analytics, PI Interfaces, PI JDBC Driver, PI Manual Logger, PI Notifications, PI ODBC Driver, PI OLEDB Enterprise, PI OLEDB Provider, PI OPC DA Server, PI OPC HDA Server, PI ProcessBook, PI SDK, PI Server, PI Square, PI System, PI System Access, PI Vision, PI Visualization Suite, PI Web API, PI WebParts, PI Web Services, RLINK and RtReports are all trademarks of OSIsoft, LLC. All other trademarks or trade names used herein are the property of their respective owners. U.S. GOVERNMENT RIGHTS Use, duplication or disclosure by the US Government is subject to restrictions set forth in the OSIsoft, LLC license agreement and/or as provided in DFARS 227.7202, DFARS 252.227-7013, FAR 12-212, FAR 52.227-19, or their successors, as applicable.

Published: March 27, 2020

2|Page

Table of Contents

Contents

Table of Contents .................................................................................................................................................................... 3 1. Introduction .................................................................................................................................................................... 5

Overview of Lab ...................................................................................................................................................... 5 What is PI Web API?................................................................................................................................................ 5 Goals for this Lab..................................................................................................................................................... 6 Section outline ........................................................................................................................................................ 6 Out of scope topics ................................................................................................................................................. 6 Virtual Learning Environment ................................................................................................................................. 7 Exercise 1 ? Exploring the PI Web API .................................................................................................................................... 8 2. PI Web API Basics .......................................................................................................................................................... 10 Controllers............................................................................................................................................................. 10 Methods ................................................................................................................................................................ 10 URL parameters .................................................................................................................................................... 11 Exercise 2 ? Using URL parameters....................................................................................................................................... 12 3. Constructing PI Web API Requests................................................................................................................................ 14 HTTP verbs ............................................................................................................................................................ 14 Headers ................................................................................................................................................................. 14 Request body ........................................................................................................................................................ 15 Exercise 3 ? Make requests in Postman................................................................................................................................ 16 4. Searching with PI Web API ............................................................................................................................................ 18 Traditional endpoints with filters.......................................................................................................................... 18 Using the Search controller................................................................................................................................... 18 Using the AFSearch methods ................................................................................................................................ 18 Benefits of the AFSearch methods........................................................................................................................ 19 Exercise 4 ? Making queries with the AFSearch methods .................................................................................................... 20 5. WebId 2.0 ...................................................................................................................................................................... 21 WebId types .......................................................................................................................................................... 21 Exercise 5a ? Decode WebIds ............................................................................................................................................... 23 Exercise 5b ? Generate a WebId ........................................................................................................................................... 24 6. Batch requests .............................................................................................................................................................. 25

Structure of a batch request ................................................................................................................................. 25 Parent-Child requests ........................................................................................................................................... 26 Exercise 6a ? Get System Endpoints ..................................................................................................................................... 28 Exercise 6b ? Create AF Hierarchy ........................................................................................................................................ 29 7. Channels........................................................................................................................................................................ 30 WebSockets........................................................................................................................................................... 30 Query Parameters ................................................................................................................................................. 31 Exercise 7 ? Using Channels .................................................................................................................................................. 32 8. Stream updates ............................................................................................................................................................. 33 Registering for updates ......................................................................................................................................... 33 Retrieving updates ................................................................................................................................................ 33 Exercise 8 ? Using Stream Updates....................................................................................................................................... 34 9. OSIsoft GitHub .............................................................................................................................................................. 35 Final Exercise......................................................................................................................................................................... 35 Appendix ............................................................................................................................................................................... 36 Postman Introduction ....................................................................................................................................................... 36 Save the Date! ................................................................................................................... Error! Bookmark not defined.

4|Page

1. Introduction

Overview of Lab

This lab will go through some of the main functionality of the PI Web API, from basic actions like retrieving a set of values, to signing up for streaming updates on a group of attributes. This lab is designed for students who are familiar with the PI System but are new to PI Web API. Advanced programming capabilities are not required, but students should have some familiarity with general programming concepts.

What is PI Web API?

The PI Web API is a RESTful Web API that allows for programmatic access to the PI System. Through PI Web API, client applications can perform for read/write operations on AF Servers and the PI Data Archives through web requests. RESTful web services are a common architecture type for modern APIs. In the context of PI Web API, adhering to this type of architecture means that the API is:

? Stateless - This means that PI Web API retains no observable knowledge of clients across requests. Each request is an independent transaction between the client and the server.

? Resource-oriented - Interaction with the PI Web API is organized around resources. Most important PI and AF objects, such as Asset Servers, Data Servers, points, elements, attributes, event frames, and so on, map to resources in the PI Web API.

? Navigable by links - Links capture the organization of the resources exposed by the PI Web API. You're probably familiar with the hierarchical structure of AF objects: Asset Servers contain databases, which contain elements, which contain attributes, and so on. Links returned from requests express these relationships, which make it easy for clients to navigate between related resources.

Comparison to AF SDK The PI Web API itself uses AF SDK for data access, so its functionality is a subset of what AF SDK provides. This also means that it is not possible for PI Web API to have better performance than AF SDK. However, for many applications the performance difference is small, and PI Web API is much more flexible in terms of what platforms and languages can be used. AF SDK is a .NET library, so it must be run on Windows and in a language that supports loading .NET dlls. On the other hand, PI Web API can be used by any platform and language that supports making HTTP(S) requests.

5|Page

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download