Using the Postman to fetch data from a Swagger Site

We’re using The Things Network to get data from our PAX (passenger) counters. We have Things Network application that receives Lora messages from our counters and we’ve added a data storage integration to hold the data from the counters. We’re not doing much with the data at the moment, but today I thought I’d try and get it out of the Things Network data store sot that I could play with it.

I was thinking that I might have to write a little application to make the request that fetches the data but it turns out that it is actually very easy to use The Postman to fetch the data for me. The Postman is a program that posts web requests and gets the result back for you. It’s great for testing and also for performing quick web requests when you can’t be bothered to write a program to do it. Which is what I’m doing.

thingswagger.png

If you ever need to do this too it’s actually quite easy. Just open up the integration from your application on the Things Network as shown above. Press the Authorize button in the top right and copy the application key from the application into the dialog that appears so that you can authenticate requests to the Swagger api. Then find the query that you want to run. Iin this case it is the query one you can see on the screenshot above.

swagger2.png

Now scroll down to reveal more of the query settings. I’ve set the parameter to get the last 7 days of data. The Things Network only hold the data for 7 days, so this will fetch all of the data. If you hit the “Try it out” button the query runs and you will see the data appear in the browser. That’s fine, but it is very hard to do much with the data in a web page like this.

To use Postman you just have to copy some of the elements from the sample curl query generated by the web page into a new Postman GET behaviour. As you can see below I’ve set the url for the GET request to the Request URL above and added two header values to the request. These give the output format and the authorisation key.

postman swagger.png

When you click the Send button the request is sent and you can then save the response in a file. You can save the query for later use. Postman and swagger are a couple of technologies that it is worth learning a bit about.