Using API in Aruba Central with Postman by Ulises Cázares

 Hi, today I'm gonna show how to interact with the Aruba Central API using postman.

My intention is that you know how to construct the request using headers, parameters and the body of the request.

The first things to start working with the Aruba Central API are: to have administrative access to Aruba Central and to see the API documentation in Aruba Central

To access the Aruba Central API documentation go to Global-Organization-Platform Integration-API Gateway - Rest API

The next page appears and you can access the documentation


 

Once you click there,  you'll be redirected to a page like this. 



Now, let's do 4 thing so you can use the API:

  1. Create the API Application
  2. Login to the device API
  3. Construct a GET request
  4. Construct a POST request


  1. Click in "Add APPs and Tokens" and Aruba Central will create the API Application so you have a client_id, and client_secret which you'll need later. This happens only the first time, following tokens won't create another Application

    1. If you want, you can click "Download Token" and go directly to step 3 and 4 (GET and POST) but I'll show you how to get the access token with https requests.
  1.     Login to the dAruba Central to get the access token (using your Aruaba Central administrative credentials). In order to get the access_token we have to construct 3 requests in the following order.
      1. According to the documentation, for my user accout which is hosted in the US-2 instance, the URL is:  https://apigw-prod2.central.arubanetworks.com/oauth2/authorize/central/api/login
      2. In Postman, construct it like this:
        1.  It's a http POST to the URL
        2. In the body use "username", "password" and "client_id" variables. The client_id is from the previous step. Note.- The variables are case sensitive
      3. If everything is ok we'll get a response like this:
        1. This respone includes2 cookies: csrftoken and session which we'll use in the following requests.
      4. We make another POST to https://apigw-prod2.central.arubanetworks.com/oauth2/authorize/central/api including two Headers using the previously obtained cookies. These Hearders will be Cookie and X-CSRF-Token. The request also requires the "client_id" and the "customer_id". The request mandates for two parameters too, which are "response_type" set to code and "scope" set to read or all. If you don't send these parameters the request will fail. For the client_id, you can obtain it from the application creation and the customer_id is a unique value for every Aruba Central  customer.                                                                        
      5. If everything is ok, we'll get the "auth_code" which will be required in the next request to get the acess_token.                                            
      6. Now we make another POST to https://apigw-prod2.central.arubanetworks.com/oauth2/token including the following: "clinet_id", "client_secret", "grant_type" set to "authorization_code" and "code" using the auth_code value obtained in the previuos step. Note: client_id and customer_id would be obtained from the application page when the app was created.             
      7. If everything is ok, we'll get the access_token which we'll need to make requests.
  2. Construct a GET request.
      1.  According to the documentation, to obtaint the configured Groups URL is:  https://apigw-prod2.central.arubanetworks.com/configuration/v1/groups
        1. It's a GET to the URL
        2. This time we use a Authorization section with the type OAuth2.0 and the access_token as value.
        3. Int his particular request it's mandatory to the de limit and offset values. For this example is 20 and 0.                         
        4. If everything is ok, we'll get something like this:       
  3. Construct a POST request
      1. According to the documentation, to create a Group the URL is:  https://apigw-prod2.central.arubanetworks.com/configuration/v2/groups
      2. It's a POST to the URL
      3. This time we use a Authorization section with the type OAuth2.0 and the access_token as value or we can send it in the param section as access_token and value obtained previously.
      4. Since we're creating something we need more information in the request. In this case, we need at least the following: "group", "group_password", "wireless" and "wired" int he body section.                   
      5. If everythig is ok we'll get something like this:               

 

When you get an error after a GET or a POST review the code of the status, it'll give you a clue or reason of why the method didn't work.


In order to do more things with the switch API, refer to the documentation in Aruba Central (login required)


Hope this helps



Comments

Popular posts from this blog

Aruba Clearpass - How to configure the Cisco WLC for Guest and MAC Caching by Ulises Cázares

Using API in ArubaOS Switches with Postman by Ulises Cázares

WiFi - How to know supported channels by a wireless client by Ulises Cázares