<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=2854636358152850&amp;ev=PageView&amp;noscript=1">
5 min read

SBA 260: How to work with APIs in BAS

By Phil Zito on Jul 14, 2021 6:00:00 AM

Topics: Podcasts

In this episode we discuss to consume data from API's and how to bring that data into your building automation system.

Click here to download or listen to this episode now.

Resources mentioned in this episode

Subscribe via iTunes

Subscribe via Stitcher


Phil Zito 0:00
This is the smart buildings Academy podcast with Phil Zito Episode 260 Hey folks, Phil Zito here and welcome to Episode 260 of the smart buildings Academy podcast. And in this episode we're going to talk about how to work with API's in building automation systems. Alright, so in our previous episode Episode 259, we talked through what API czar, and in this episode we're going to talk through start to finish. How do we consume an API this should be a fairly short episode because consuming API's is a fairly straightforward thing I know it's confusing to a lot of folks. But hopefully after this episode, you will feel a lot more comfortable with consuming and working with API's. As always, everything that is discussed in this podcast can be found along with transcripts at podcasts at smart buildings academy.com forward slash 260 once again, this podcast has smart buildings Academy comm forward slash 260 and this week's episode is brought to you by our it for VA s professionals version two course. You want to learn about networking databases, servers, virtualization, remote access cybersecurity API's and more. And check out our it for be as professional as version two course at podcast smart buildings academy.com, forward slash 260. Alright, so you come on to a project and they have a weather station that is remote accessible via an API. And you're told you need to bring in the data into your supervisory device. How do you do it? Well, I'm going to talk through two ways. One is assuming your VA s system has a way of consuming HTTP endpoints, which is the majority of API's these days, and another assuming that your device does not have that capability. Alright, so let's assume your device does have that capability. Well, then First off, you need to go to that API, or that API manufacturers website, you need to find out Do I need to get a user account and a key primarily, you're concerned about the key because the key enables you to do what are called API calls calls against the API. Those are requests against the API. So you get a key, right? You fill that out, sometimes you get a pay per transaction per call, sometimes you just need to get a key and everything else is free. So get your key. All right, then you go into the software, you enter into the HTTP API module, you enter the URL, you enter the key, and you hit call. And usually, it will query the API, sometimes it will, sometimes it won't. Sometimes you will have to go and put in custom quarters yourselves. In which case, you're gonna go to what is called the SDK or software development kit for that API. Usually, this is a webpage and it describes all the calls, they're acceptable parameters and their return types and return messages, what you'll do is you'll figure out the calls you need to make to get the data you want, let's say you want temperature by zip code, maybe you want forecasts, seven day, whatever, you go and figure out what queries you need to make you enter them into that API module. You make those queries, you get returned data from those queries. And then you need to parse that data out into whatever format you need. Maybe it's an enumeration set, maybe you've got a seven day enumeration set, that is temperature for Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday. And so you go and you pass in that temperature, you pass in the high and then that high temperature can be used to drive maybe your morning cooldown. Or your maybe if it's a Low Temp your morning warm up.

But whatever it is, you pull that data in to the data types that your VA s can consume. Pretty straightforward, right? Good. Now, let's talk about if you don't have an HTTP API module in your VA s. Now if you're like me, you would go and write a script, and you would consume it via a script and run that script as a service. But that's a pain in the butt. And when you get to scale, it is not scalable. So you go to someone like a Sierra monitoring or in TCS or someone like that, who has a back net to API and API to back net gateway. You pass them the API information, once again, you pass them your key, you pass them the parameters and queries you want. And then based on that information, they will go and strongly coupled the API to the back net points that you will then discover via BACnet API, or BACnet IP integration. And that's how I did a lot of API integrations in the past because they did not have that capability built into a lot of building automation systems, at least not in a way that was usable without doing some code writing and compiling. So grab the gateway, give the GAPI gateway manufacturer the information you need, or they need rather, they'll set it up, map that in as a BACnet device and Bob's your neighbor, Bob's your uncle, rather, you've got API data coming into your bi s. Now there is one thing that I would be remiss if I didn't tell you about, which is version management do realize that API's are version managed. This is typically in the URL of the API itself, which version it is, and you need to be cognizant of version because version will go and determine what queries are deprecated or functions are deprecated. So a deprecated function means it's no longer supported. So if you're running a query or a function that is no longer supported or changed, you're not going to get data and that's going to break your API. It's the most common way in which API's are broken, is deprecated functions due to version mismatches, session keys no longer valid or URL changes. That's why you got to be cognizant of those three things and have a process to check your API's to make sure they're still working. So there you have it, folks, pretty straightforward. If you follow those steps, you'll be able to implement an API No, I make it sound rather simple. If you are looking for a more visual representation of this, then definitely go and check out our it for bs professionals course where we will be talking about API's in much greater detail. Thanks a ton, and I look forward to seeing you in the next podcast. Take care

Phil Zito

Written by Phil Zito

Want to be a guest on the Podcast?