12 Replies Latest reply on Aug 2, 2017 3:13 PM by gregor

    Using Postman for PI Web API training

    Jerome Lefebvre

      I am looking for some feedback regarding using Postman collections for PI Web API training.

      Postman is a chrome extension for testing out HTTP requests and Postman collections are a grouping of HTTP requests, including bodies, headers and authentications. Along with placeholders to make them flexible.

       

      I put a few requests together using the Public PI Web API endpoint  this allows anyone to try out these requests without any PI software installed and as the requests are already made, all you need is to fill in some authentications information to be able to start trying out PI Web API.

       

      Here are the steps to tests this out.

      1. Install Postman (this requires having Google Chrome).

      2. Install the collection. (To view the list of requests, make sure to select the Collections tab in the top left corner.

      3. Grab the credentials for the Public PI Web API endpoint (requires a SSO account).

      4. You will then need to enter the credentials as follow. First, select a request and in the Authorization tab, select type "Basic Auth". You then need to enter the Username and Password that you found in step 3.

       

      For each request, you won't need to enter the username/password each time, but you will need to update the authorization tab for each requests.

       

      The list of included requests is quite small and limited to requesting data from the Public PI Web API endpoint.

      But, I hope this can be easily fleshed out in a good way for users to get a first taste of PI Web API.

       

      Again, this is a work in progress and I am looking for some early feedback into this approach.

      To update the list of requests (once I add some more), all you need to do is open the link on step 2 again.

        • Re: Using Postman for PI Web API training
          gregor

          Hi Jerome,

           

           

          While your post is a question, I wasn't able to locate a single question mark and I believe this could be the reason why there's no reply yet. What's the information you are interested in?

           

          I find Postman a useful tool to test requests against RESTful services. It allows to focus on forming queries outside a development environments GUI. Yes, one can do similar in a browser but only with GET requests. As soon as I need to try requests that require additional information to be submitted (POST, UPDATE or DELETE), I can't use pure browser functionality anymore and Postman as add-on to Google Chrome comes in handy.

          • Re: Using Postman for PI Web API training
            rsun

            Does Postman allow us to do Kerberos Authentication? Is anyone know how to do that?

              • Re: Using Postman for PI Web API training
                jlangan

                Ricky,  I've found it to work for me.  With the way that Postman connects, your PI Web API server has to be set up to use only Kerberos (see KB01229).  As an alternative, if you use fiddler, you can have both Kerberos and Basic allowed at the same time as it can negotiate to a Kerberos authentication.

                2 of 2 people found this helpful
                • Re: Using Postman for PI Web API training
                  pmartin

                  I believe that Postman piggybacks off Chrome's authentication so I've always selected "No Authentication" in Postman and it works with Kerberos configured.

                  2 of 2 people found this helpful
                    • Re: Using Postman for PI Web API training
                      magreenberg

                      Can someone give me a little more detail on how to run a GET request in Postman with Kerberos configured?  Our Web API install is configured for Kerberos authentication, so the Admin says.  In Postman, I've tried No Auth and Basic but I always get "401 Unauthorized: Authorization has been denied for this request."  The query works in the Chrome browser but not Postman.

                       

                      Thanks!

                        • Re: Using Postman for PI Web API training
                          pmartin

                          Hi Mark,

                           

                          It sounds like you have the right idea but something is going wrong.  Can you check a couple things for me?

                           

                          1) What is your PI Web API AuthenticationMethods value set to?

                          You can check at: https://<your web api server>/piwebapi/system/configuration

                           

                          2) Let's compare the request header from Chrome to the request header from Postman.  If you've never done this, it's a great debugging tool that I use frequently.

                           

                          Chrome:

                          Open Chrome Developer Tools (F12) and go to the Network tab. Refresh the page.  You should see a couple rows pop up.  Click the one that has the name of the action you are trying to invoke (for example, the URL in step one would have "configuration").  A new window should appear where the table was - click the headers tab in that window.  Scroll down to Request Headers.  Copy the Authorization header into a notepad or some other text editor (please do not post it on PI Square)

                           

                          Postman:

                          Right click in Postman and click "Inspect".  This should bring you to the familiar Chrome Developer Tools.  Do the same procedure as Chrome but instead of refreshing, send the query again.

                           

                          Compare the authorization headers - do they match?  If not, where are they different? 

                               Is the first word different?

                               Are the first 3 letters of second word the same?

                          1 of 1 people found this helpful
                            • Re: Using Postman for PI Web API training
                              magreenberg

                              Ok, the value for AuthenticationMethods is set to Kerberos.  And using the Chrome Dev tools, I was able to capture the Request Header / Authorization value. It is a very long encrypted string.

                               

                              But there is no Inspect option on the popup menu when right-clicking in Postman.  I know Postman is a Chrome extension but it does not appear to run within Chrome.   Is there another setting or option I am missing in Postman?

                               

                              BTW, in Fiddler the Response Header only shows 401 Unauthorized with WWW-Authenticate: Negotiate. 

                              Thanks for your help!

                                • Re: Using Postman for PI Web API training
                                  pmartin

                                  I forgot that you need to set a flag in Chrome to allow debugging in apps, see this post:

                                  Enabling Chrome Developer Tools inside Postman – Postman Blog

                                   

                                  It may also be a Postman headers settings issue that is messing up  your request (I've had it happen to me before).  Here's mine for reference:

                                    • Re: Using Postman for PI Web API training
                                      magreenberg

                                      Thanks Paul, I really appreciate all the very good tips.  But let me give you an update on my progress so far today:

                                      First, this morning I went to another Windows 10 machine on the same domain and using Postman, I was able to successfully connect to our PI data.  The request returned JSON that matched what Chrome had returned earlier, same response headers as well, 200 OK!  I haven't compared Postman on the two machines to see what might be different but it might be related the header settings in Postman like you mentioned.  But I will check it out and let you know ASAP.

                                       

                                      Next, I used Fiddler to send the same request but it continued to return the 401 Not Authorized response.  But then I remembered seeing another post, I think it was yours, on selecting the Automatically Authenticate checkbox on the Options tab when using the Composer in Fiddler.  And then automagically ( a technical term) I started getting the 200 OK responses from Fiddler as well, but with one little problem.  Immediately before the 200, I get a 401 Unauthorized.  So I receive the responses back to back within the same second, a 401 and immediately afterwards I get the 200.  This doesn't seem normal to me.

                                       

                                      -Mark

                                        • Re: Using Postman for PI Web API training
                                          pmartin

                                          Hi Mark,

                                           

                                          Actually, what you're seeing is the correct behavior.  The client first attempts to authenticate with Anonymous (why send credentials when you don't have to?) and then the server says "No, I will only take these types of credentials" so the client sends the requested credentials in the second request.

                                          1 of 1 people found this helpful
                                            • Re: Using Postman for PI Web API training
                                              magreenberg

                                              Hi Paul,

                                               

                                              Thanks for the info.  I've really learned a lot from this tread the past few days!  All my authentication issues were related to how to tell Postman and Fiddler to send my current credentials with the request.

                                               

                                              PI is a new technology for me and for our company; we are implementing 30-something facilities in PI now.  Now that I know I can authenticate in Fiddler and Postman with kerberos enabled, I can begin building an example application.  Plus now I know I can come to the PI Web API forums to find answers!

                                               

                                              Thanks again,

                                              -Mark

                                            • Re: Using Postman for PI Web API training
                                              gregor

                                              Hi Mark and Paul,

                                               

                                              With System.Net.HttpClient, the initial attempt to send a request anonymously can be suppressed by setting PreAuthenticate = true for the HttpClientHandler. I am not very familiar with Fiddler or Postman that much and tried to find an answer in the internet. Looks like this is the real challenge besides knowing if the header is supported by the client, namely Fiddler or Postman. I am currently stuck but do not consider this a very high priority question. Whoever stumbles across this discussion and has related information to share, please do not hesitate.

                                              1 of 1 people found this helpful