AirWave RestAPI with PowerShell

Reading Time: 4 minutes

In some of my latest projects, I used the AirWave RestAPI. The main purpose was to either extend the functionality of AirWave or to automate some workflows. In this post, I show, how to interact with the AirWave RestAPI.

AirWave RestAPI: Yes, AirWave has an API

AirWave is a great tool to manage your wireless and wired infrastructure. And like all other products from Aruba, it as an API as well. You can use a RestAPI to communicate with AirWave. I agree, this API is not the most powerful one and is leaking some functions. Especially, when it comes to adding and removing devices. But I’m pretty sure, that some smart guys already working on this.

You can get access to the API from your AirWave system. Login to AirWave and go to “Home–>Documentation”:

AirWave RestAPI - Documentation
AirWave RestAPI – Documentation

The section in the blue frame has the RestAPI documentation. I have some experience with the “State and Statistical XML API”. You can find the documentation and examples after you click the “HTML” link.

AirWave RestAPI uses XML to transfer information. The input is URL encoded. This makes the AirWave RestAPI very simple and easy to use.

AirWave RestAPI: How to Use the RestAPI

You can use the AirWave RestAPI with every language, who supports HTTP requests. For the example below, I use PowerShell. Just because I wanted to learn PowerShell.

Before you can read or write data with the RestAPI you need to log in. Unfortunately, the authentication is not described in the documentation. The reason might be, that it is not rocket science for those who do programming all day long. For me, it was the hardest part.

You use the default login page to create a session. Specifically, the HTTP Post request, from the login page. In PowerShell, it looks like this:

#Create the Login URL
$loginUri = "https://" + $airwavehost + "/LOGIN"
#Create the username password combination
$body = "credential_0=" + $username + "&credential_1=" + $password + "&destination=/index.html"

#Login to AirWave and save the session into the session variable
$loginObj = Invoke-RestMethod -Uri $loginUri -Method Post -Body $body -ContentType 'application/x-www-form-urlencoded;charset=UTF-8' -SessionVariable session

Just convert this into an undersandable language.

First I create the URL for the login request. This looks like this:

https://airwave.flomain.local/LOGIN

Now, I create the username/password combination and the destination after a successful login. I send this to the URL from above. The data look like this:

credentials_0=admin&credentials_1=admin&destiantion=/index.html

This still looks very cryptic. Forget about the “destination” variable. The important one is “credentials_0” and “credentials_1”. The first one is the username and the second one is the password.

Put all together in a request like this:

$loginObj = Invoke-RestMethod -Uri $loginUri -Method Post -Body $body -ContentType 'application/x-www-form-urlencoded;charset=UTF-8' -SessionVariable session

This creates an HTTP Post to the URL from above. It uses the data with the credentials to log in and it creates a session. I save this session in the “session” variable. If the login is successful you can use the “session” variable for all other requests without any login.

AirWave RestAPI: A Simple Script

To play around with the API, my goal was to extract some data from AirWave. I always play with AirWave in my lab and brake something. So I do a fresh installation. No time for backups, for this kind of play and destroy systems. After the installation, I need to add all the devices from my lab to AirWave, again.

My idea is, to have a script, which can extract all or some devices in a format which I can use to reimport into a new AirWave installation. Sure, I could create this file by hand, but I wanted to play with PowerShell and the RestAPI. and the script is really simple. It took me only half a day to write the script. Most of the time I spend figuring out, how the login works.

I use the search API to query the devices. The URL looks like this:

https://airwave.flomain.local/ap_search.xml?query=querystring

The only parameter for this request is the “query”. Here you can use every string, you would use in the search from the GUI as well. I use the IP, with only the first octet. like this:

https://airwave.flomain.local/ap_search.xml?query=192.

In the PowerShell script, it looks like this:

#Create the Search URL
$apSearchUri = "https://" + $airwavehost + "/ap_search.xml?query=" + $queryString

#Request the device list and save the answer to a variable
$apsObj = Invoke-RestMethod -Uri $apSearchUri -WebSession $session

The answer is in XML. So I just need to parse the XML answer and write it into a CSV file. Parsing XML and writing it into a CSV file is not related to the RestAPI, so I did not cover this as well. But you can find the whole script on GitHub:

https://github.com/FlorianBaaske/export_airwave_devices

Unfortunately, you cannot add devices to AirWave with the RestAPI, but I’m sure we will see something like this in the future.

Are you working with RestAPI’s? Which language do you prefer for writing such scripts?

If you find this post interesting, leave me a comment and share it with your friends. If you don’t like the post, leave me a comment and share it with your enemy. But whatever you do, leave me a comment, now.

4 thoughts on “AirWave RestAPI with PowerShell”

  1. Hello, I’m new in Aruba, our client has Aruba, I don’t have any other information of their hard ware and software , token,….. I should findout how aruba is working, how the RestAPI ,is working what kind of Data I can have from API, I already read this link : “Central Network Management APIs ”
    culd you please help me to have more information about Aruba

    Reply
    • Hi Sheila,

      Thanks for your question. As this request is very generic, It is hard to help you. Is it possible to share information for which products from Aruba you are looking for information? This would make it much easier for me 🙂
      A good starting point might be this page here:

      https://www.youtube.com/channel/UCFJCnuXFGfEbwEzfcgU_ERQ/search?query=api

      This is the Aruba Youtube Account and a list of videos just for API topics. Maybe this is something you are looking for.

      You can also have a look into the Aruba GitHub repository. There are some example scripts for the different API’s available:

      https://github.com/aruba

      I hope this helps.

      BR
      Florian

      Reply
    • hi MP,

      The API in AirWave is not very powerful and you cannot do any system configuration with the help of the API, only some limited requests regarding managed devices.

      BR
      Florian

      Reply

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.