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:
- Create the API Application
- Login to the device API
- Construct a GET request
- Construct a POST request
- 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
- 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.
- 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.
- 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
- In Postman, construct it like this:
- It's a http POST to the URL
- In the body use "username", "password" and "client_id" variables. The client_id is from the previous step. Note.- The variables are case sensitive
- If everything is ok we'll get a response like this:
- This respone includes2 cookies: csrftoken and session which we'll use in the following requests.
- 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.
- If everything is ok, we'll get the "auth_code" which will be required in the next request to get the acess_token.
- 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.
- If everything is ok, we'll get the access_token which we'll need to make requests.
- Construct a GET request.
- According to the documentation, to obtaint the configured Groups URL is: https://apigw-prod2.central.arubanetworks.com/configuration/v1/groups
- It's a GET to the URL
- This time we use a Authorization section with the type OAuth2.0 and the access_token as value.
- Int his particular request it's mandatory to the de limit and offset values. For this example is 20 and 0.
- If everything is ok, we'll get something like this:
- Construct a POST request
- According to the documentation, to create a Group the URL is: https://apigw-prod2.central.arubanetworks.com/configuration/v2/groups
- It's a POST to the URL
- 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.
- 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.
- 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
Post a Comment