Developer

 View Only
  • 1.  AOS 8 API advice needed

    Posted 18 days ago

    Hello,

    AOS 8.13.1.1
    Multi-controller cluster and failover cluster with MCR and standby MCR (x2)

    First off - I'm not very experienced with programming so I'm sure this is something I'm doing wrong rather than a bug etc!

    I'm trying to use the API to run the 'apmove' command.

    I successfully get the UIDARUBA and X-CRSF-Token (I'm a little confused about if and when I need the X-CSRF-Token but the API developer tool puts that in the header so I am too).

    For info I can run this successfully from the API reference page using the 'Try It Out' option, so I know it is possible!

    This is the relevant snip of what I have so far:

            url = f"https://{ctlr_ip}:4343/v1/configuration/object/apmove_ap"

            for ap in ap_list:
                urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

                params = {"config_path":"/mm","UIDARUBA":str(uidaruba)}
                querystring = urllib.parse.urlencode(params)

                full_url = f"{url}?{querystring}"
                print(f"full_url = {full_url}")

                payload = {
                        "ap-mac": ap,
                        "target_v4": target_ip,
                        "target_v6": ''
                        }

                print(f"payload = {payload}\n")

                headers = {
                        "Content-Type": "application/json",
                        "X-CSRF-Token": x_csrf,
                        "Cookie" : f"SESSION={uidaruba}"
                        }

                print(headers)

                try:
                    response = requests.post(full_url, json=payload, headers=headers, verify=False)
                    print(response)
                    print(response.text)

    But this is what I get when I run it (with some redactions):

    full_url = https://<correct url>:4343/v1/configuration/object/apmove_ap?config_path=%2Fmm&UIDARUBA=<uid looks normal>
    payload = {'ap-mac': 'AP MAC is correct', 'target_v4': 'cluster IP address', 'target_v6': ''}

    {'Content-Type': 'application/json', 'X-CSRF-Token': '<x-csrf token>', 'Cookie': 'SESSION=<uid>'}
    <Response [200]>
    {
      "Error": "Exception raised while processing request"
    }

    Is it true to say that authentication is working as I get a 200 response? In which case is the issue somehow with running the endpoint URL itself?

    Any help much appreciated.

    Guy



    -------------------------------------------


  • 2.  RE: AOS 8 API advice needed

    Posted 13 days ago

    I'm still stuck on this, but I did find this in the controller logs:

    Jan 27 10:38:02 2026  webui[3604]: USER: username has logged in from 172.x.x.x. 
    Jan 27 10:38:02 2026  httpd[18031]: <350008> <18095> <ERRS> |httpd| |webserver| SSL Library Error: error:0A000126:SSL routines::unexpected eof while reading  
    Jan 27 10:38:02 2026  profmgr[3755]: <334200> <ERROR> |profmgr| Exception in py_set_config, TYPE: <type 'exceptions.ValueError'>:::EXCEP::: No JSON object could be decoded File pos: 88JSON File: 
    Jan 27 10:38:02 2026  profmgr[3755]: <334200> <ERROR> |profmgr| !! Traceback (most recent call last): !!   File "./ds_py_intf.py", line 1123, in py_set_config !!   File "/lib/python2.7/json/__init__.py", line 290, in load     **kw) !!   File "/lib/python2.7/json/__init__.py", line 351, in loads     return cls(encoding=encoding, **kw).decode(s) !!   File "/lib/python2.7/json/decoder.py", line 366, in decode     obj, end = self.raw_decode(s, idx=_w(s, 0).end()) !!   File "/lib/python2.7/json/decoder.py", li
    Jan 27 10:38:02 2026  httpd[18031]: <350008> <18095> <ERRS> |httpd| |webserver| SSL Library Error: error:0A000126:SSL routines::unexpected eof while reading  
    Jan 27 10:38:02 2026  profmgr[3755]: <334200> <ERROR> |profmgr| Exception in py_set_config, TYPE: <type 'exceptions.ValueError'>:::EXCEP::: No JSON object could be decoded File pos: 88JSON File: 
    Jan 27 10:38:02 2026  profmgr[3755]: <334200> <ERROR> |profmgr| !! Traceback (most recent call last): !!   File "./ds_py_intf.py", line 1123, in py_set_config !!   File "/lib/python2.7/json/__init__.py", line 290, in load     **kw) !!   File "/lib/python2.7/json/__init__.py", line 351, in loads     return cls(encoding=encoding, **kw).decode(s) !!   File "/lib/python2.7/json/decoder.py", line 366, in decode     obj, end = self.raw_decode(s, idx=_w(s, 0).end()) !!   File "/lib/python2.7/json/decoder.py", li

    So that explains why cURL works and running it from the controller API interface works, it's a Python problem? We run Python 3.x.

    But strangely when I ran this with a different endpoint URL (apboot) it worked fine.  

    Does anyone have any ideas about what I might be doing wrong? Or is this a bug? 

    -------------------------------------------



  • 3.  RE: AOS 8 API advice needed

    Posted 13 days ago

    Hi Guy.

    I don't know if it will help, but on GitHub you have AOS8 example scripts.

    From error you will see that your json data is not in json format. Try using json.dumps() to convert dictionary to json string.

    Best, Gorazd



    ------------------------------
    Gorazd Kikelj
    MVP Guru 2025
    ------------------------------



  • 4.  RE: AOS 8 API advice needed

    Posted 13 days ago

    Hi

    I tried using json.dumps on the payload - that didn't complain, and I changed the request to include 'data=payload' rather than 'json=payload'. But I get the same issue.

    If I just send the AP MAC in the payload and remove the two other vars then I don't get the exception (but of course I get an incomplete command error instead). So it does seem to be something about the payload. 

                payload =   {
                            "ap-mac": "11:22:33:44:55:66",
                            "target_v4": "2:2:2:2",
                            "target_v6": ""
                            }

    payload = {'ap-mac': '11:22:33:44:55:66', 'target_v4': '2.2.2.2', 'target_v6': ''}

    When I test with cURL from the same server it works:

    curl -X POST --insecure -b "aruba-cookie" -d "{ \"ap-mac\": \"11:22:33:44:55:66\", \"target-v4\": \"2.2.2.2\", \"target-v6\": \"\" }" "https://1.1.1.1:4343/v1/configuration/object/apmove_ap?config_path=/mm&UIDARUBA=<uid>" -v

    {
      "apmove_ap": {
        "ap-mac": "mac", 
        "target-v4": "ip", 
        "target-v6": "", 
        "_result": {
          "status": 0, 
          "status_str": "apmove command succeed"
        }
      }, 
      "_global_result": {
        "status": 0, 
        "status_str": "apmove command succeed", 
        "_pending": false
      }

    -------------------------------------------



  • 5.  RE: AOS 8 API advice needed

    Posted 13 days ago

    Oh <facepalm> I was using "target_v4" and target_v6", it should be target-v4 and target-v6

    Sigh. It now works. Thanks for taking a look both of you!

    -------------------------------------------



  • 6.  RE: AOS 8 API advice needed

    Posted 13 days ago

    Glad it is resolved. Good job.

    Best, Gorazd



    ------------------------------
    Gorazd Kikelj
    MVP Guru 2025
    ------------------------------



  • 7.  RE: AOS 8 API advice needed

    Posted 13 days ago

    oh good catch ! 



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

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

    PowerArubaCL: Powershell Module to use Aruba Central

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

    ACEP / ACMX #107 / ACDX #1281
    ------------------------------



  • 8.  RE: AOS 8 API advice needed

    Posted 13 days ago

    What the curl when you are using Try it ? it is from directly on controller ? or using https://developer.arubanetworks.com/aos8/reference ?



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

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

    PowerArubaCL: Powershell Module to use Aruba Central

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

    ACEP / ACMX #107 / ACDX #1281
    ------------------------------



  • 9.  RE: AOS 8 API advice needed

    Posted 13 days ago

    Thanks - turns out I was using 'target_v4' and 'target_v6' instead of 'target-v4' and 'target-v6' <raised eyes>. I think my head was in Python vars!

    -------------------------------------------



  • 10.  RE: AOS 8 API advice needed

    Posted 13 days ago

    Feel your pain :-) Been there many times. Those hyphens and dashes are pain in the a...

    Best, Gorazd



    ------------------------------
    Gorazd Kikelj
    MVP Guru 2025
    ------------------------------