Wired Intelligent Edge (Campus Switching and Routing)

Reply
CJL
New Contributor

Trouble getting started with REST API

Hi all,

 

I'm trying to get started with network automation, and I'm having some issues figuring out how to use the REST API.

 

I've been using Postman to try to interrogate the API (i'm trying to pull VLANs with x.x.x.x/rest/v1/vlans, but every time I try to do a GET request, I get 400 bad request, the REST session timed out. Please try again.

 

Could this be because the switch requires a username and password?

 

Does anyone have any suggestions that could help me out?

Aruba Employee

Re: Trouble getting started with REST API

Can you make sure, below points are taken cared before accessing vlans?

1. REST API enabled on switch (show rest-interface).

2. REST API login to switch is successful and cookie is returned. ( you can check this thread on how to parse the credentials in Postman. http://community.arubanetworks.com/t5/Campus-Switching-and-Routing/2930M-16-04-Unable-to-Login-via-REST-API/m-p/404685 )

Login URL --> x.x.x.x/rest/v3/login-sessions

body, select 'raw' and give the JSON --> 

{"userName" : "switchusername","password" : "password"}

 

Once this is successful, GET command for vlans should work. 

URL what you mentioned looks good ( x.x.x.x/rest/v1/vlans)

 

You can also download detailed documention for switch REST API from https://support.hpe.com (attached here)

 

Also, try out sample python code for ArubaOS-Switch REST API  workflows at https://github.com/aruba/arubaos-switch-api-python 

 

Aruba Employee

Re: Trouble getting started with REST API

Hi CJL,

 

Can you tell which switch you are trying to access? What's the config of the switch?

 

Kind regards,

 

Dik

New Contributor

Re: Trouble getting started with REST API

Hello, I am a student employee at a university serviced by Aruba, and am working on using your software aruba-switch-ansible to automate our network.  I also tried using aruba-ansible modules, but switched after I couldn't get it to work. I am working on a test switch, a 2930M.  After aruba-switch-ansible and aruba-ansible-modules had the same problem, I realized that it is probably an issue with a switch setting, not something with the software.  The problem that I encountered with both softwares was that it could not navigate to https://x.x.x.x/rest/v4/login-sessions, and I did try different version numbers.  Whenver I try to access it via this web browser, I get the same error as the guy who posted the original thread, 400: Bad Request.  When I navigate to the switch via https://x.x.x.x , it directs me to an html page: https://x.x.x.x/html/banner.html and after clicking 'continue' on the webpage it directs me to https://x.x.x.x/html/login.html.  The first command I have been trying to execute is a POST login command, the one in aruba-switch-ansible playbook, arubaoss_tasks_config_example.

 

I believe the problem may have to do with my SSL interactions or my web-management settings.  In the CLI, I see several things that led me to this conclusion:

1) I get that the SSL port is already in use:

SW-NAME-01(config)# web-management ssl
web-management: The specified TCP/UDP port is in use by another protocol.

 

2) The management URL is still the default management URL, I didn't know if this needed to be changed to the https://x.x.x.x/rest/v4/login-sessions or how to change it, if this is the problem: 

SW-NAME-01(config)# show web-management

Web Management - Server Configuration

HTTP Access : Enabled
HTTPS Access : Enabled
SSL Port : 443
Idle Timeout : 600 seconds
Management URL : http://h17007.www1.hpe.com/device_help
Support URL : https://www.hpe.com/us/en/networking.html
User Interface : Improved
Listen Mode : both

 

My REST interface settings appear to all be correct based on the Aruba documentation I have seen:

SW-NAME-01# show rest-interface

REST Interface - Server Configuration

REST Interface : Enabled
REST Operational Status : Up
REST Session Idle Timeout : 600 seconds
HTTP Access : Enabled
HTTPS Access : Enabled
SSL Port : 443

 

I have already tried a few solutions, like switching the body_format in login_switch.yml in aruba-switch-ansible to raw, and form-urlencoded from its default json.  This caused status 200 and status -1 errors, but neither could login to the switch.  I also tried setting it to raw, and making the text objects that I'm looking for, so that they match those on the page.  Eg. "password" to how it was on the page, "Password:".  The last thing I tried was just changing the url to https://x.x.x.x/html/login.html, but this also did not work.

 

I had pretty much the exact same problem with aruba-ansible-modules and could also not figure out how to fix it there.  Any support would be appreciated, thank you.

 

New Contributor

Re: Trouble getting started with REST API

also, using Aruba switch software version WC.16.07.0005.  I can update it to the newest version if you think that may be the problem.

MVP Expert

Re: Trouble getting started with REST API

do you have fix your issue ?

 

it is better to use last release for API Stuff




PowerArubaSW: Powershell Module to use Aruba Switch API for Vlan, VlanPorts, LACP, LLDP... More info


PowerArubaCP: Powershell Module to use ClearPass API (create NAD, Guest...) More info


PowerArubaCX: Powershell Module to use ArubaCX API (get interface/vlan/ports info)


PowerArubaIAP: Powershell Module to use Aruba Instant AP




ACMP 6.4 / ACMX #107 / ACCP 6.5
Highlighted
New Contributor

Re: Trouble getting started with REST API

Yes, I was able to solve the issue, and the problem was not something posted here before.  I had to change the web interface URL in our Enterprise Network, Configuration Manager (Solarwinds Orion) from the default, http://x.x.x.x to https://x.x.x.x/rest/v3 (or whatever rest version).  With that, it now can interact with the REST features on the switch.

New Contributor

Re: Trouble getting started with REST API

I'm having the same kind of a problem still going on that I haven't solved yet. I have Aruba 2530. Web-management ssl and rest-interface are enabled. Only concern is that web-management ssl returns "web-management: The specified TCP/UDP port is in use by another protocol."

 

When I run my test playbook, it returns status "-1".

Whole error ansible returns is following:

 

fatal: [switch1]: FAILED! => {
"changed": false,
"invocation": {
"module_args": {
"api_version": "None",
"contact": "",
"default_gateway": "",
"default_gateway_ip": "",
"device_operation_mode": "DOM_AUTONOMOUS",
"domain_name": "",
"host": "x.x.x.x",
"hostname": "testhost",
"location": "",
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"port": 80,
"provider": {
"api_version": null,
"host": "x.x.x.x",
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"port": 80,
"ssh_keyfile": null,
"timeout": 30,
"transport": "aossapi",
"use_proxy": false,
"use_ssl": false,
"username": "user",
"validate_certs": false
},
"ssh_keyfile": null,
"timeout": 30,
"uplink_ip": "",
"uplink_vlan_id": "",
"use_ssl": false,
"username": "user",
"validate_certs": false,
"version": "IAV_IP_V4"
}
},
"msg": "Connection failure: connection was closed before a valid response was received: ''",
"status": -1,
"url": "http://x.x.x.x:80/rest/v6.0/login-sessions"

 

Same with trying to go to MM IP REST URL https://x.x.x.x/rest/v6/login-sessions it returns The site cannot be reached in Chrome. Help appreciated here. Can provide more information when asked.

 

Thanks,

Zirhaze

MVP Expert

Re: Trouble getting started with REST API

Hi Zirhaze

 

it will be better to open a another topic

What firmware on the switch ?

 

From log, you are using HTTP and not HTTPS

the HTTP is enable on the switch ?




PowerArubaSW: Powershell Module to use Aruba Switch API for Vlan, VlanPorts, LACP, LLDP... More info


PowerArubaCP: Powershell Module to use ClearPass API (create NAD, Guest...) More info


PowerArubaCX: Powershell Module to use ArubaCX API (get interface/vlan/ports info)


PowerArubaIAP: Powershell Module to use Aruba Instant AP




ACMP 6.4 / ACMX #107 / ACCP 6.5
New Contributor

Re: Trouble getting started with REST API

I solved the problem. I was missing a conf line from switch.

 

ip authorized-managers <ip_addr> <mask> access manager access-method web

 

Thanks alagoutte for the effort!

Search Airheads
cancel
Showing results for 
Search instead for 
Did you mean: