Wired Intelligent Edge

last person joined: 4 hours ago 

Bring performance and reliability to your network with the HPE Aruba Networking Core, Aggregation, and Access layer switches. Discuss the latest features and functionality of your switching devices, and find ways to improve security across your network to bring together a mobile-first solution
Expand all | Collapse all

Trouble getting started with REST API

This thread has been viewed 34 times
  • 1.  Trouble getting started with REST API

    Posted Apr 30, 2018 03:06 PM

    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?



  • 2.  RE: Trouble getting started with REST API

    EMPLOYEE
    Posted Apr 30, 2018 04:29 PM
      |   view attached

    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 

     

    Attachment(s)

    pdf
    REST_API_ArubsOS_Switch.pdf   247 KB 1 version


  • 3.  RE: Trouble getting started with REST API

    Posted Jul 10, 2019 01:13 PM

    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.

     


    #2930M
    #2930M


  • 4.  RE: Trouble getting started with REST API

    Posted Jul 10, 2019 01:21 PM

    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.



  • 5.  RE: Trouble getting started with REST API

    MVP GURU
    Posted Aug 06, 2019 06:29 AM

    do you have fix your issue ?

     

    it is better to use last release for API Stuff



  • 6.  RE: Trouble getting started with REST API
    Best Answer

    Posted Aug 08, 2019 12:00 PM

    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.



  • 7.  RE: Trouble getting started with REST API

    EMPLOYEE
    Posted May 04, 2018 07:22 AM

    Hi CJL,

     

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

     

    Kind regards,

     

    Dik



  • 8.  RE: Trouble getting started with REST API

    Posted Sep 16, 2019 05:21 AM

    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



  • 9.  RE: Trouble getting started with REST API

    MVP GURU
    Posted Sep 16, 2019 08:37 AM

    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 ?



  • 10.  RE: Trouble getting started with REST API

    Posted Sep 16, 2019 10:46 AM

    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!



  • 11.  RE: Trouble getting started with REST API

    Posted Oct 20, 2020 05:58 PM

    ok please could you tell me exactly what're a steps to login and use API for aruba SW. because i'm trying but still in error step specially I have a login successful message but when i tried to delete a body to edit a vlan i faced a same unauthorized message again. And i had did your solve command on cli.



  • 12.  RE: Trouble getting started with REST API

    MVP GURU
    Posted Oct 21, 2020 03:14 PM

    @Hatemelashker wrote:

    ok please could you tell me exactly what're a steps to login and use API for aruba SW. because i'm trying but still in error step specially I have a login successful message but when i tried to delete a body to edit a vlan i faced a same unauthorized message again. And i had did your solve command on cli.


    Hi,

     

    What language and what firmware version ?