Developer

 View Only
  • 1.  JSON config export runningconfig/template (from group) classic central api

    Posted 19 days ago

    Hello,
    I'm working on a script where I need to fetch a configuration template from a template group in JSON format so I can process the config more easily. However, I have only found API endpoints that return the data as multipart/form-data:

    • GET /configuration/v1/groups/:group/templates/:template

    • GET /configuration/v1/devices/:device_serial/configuration

    I have also looked through the AOS-CX API documentation but couldn't find any JSON-based alternative for this. I even tried setting different Accept headers (like application/json), but that didn't help either.

    Can anyone explain why this isn't possible via the API? Or is there a workaround I might be missing?

    Thanks in advance!



  • 2.  RE: JSON config export runningconfig/template (from group) classic central api

    Posted 19 days ago
    Edited by shpat 19 days ago

    Try to parse the multipart manually. If you are using python you could do something like:

    import requests
    from requests_toolbelt.multipart.decoder import MultipartDecoder

    url = "https://central.example.com/configuration/v1/groups/YourGroup/templates/YourTemplate"
    headers = {
        "Authorization": "Bearer YOUR_TOKEN",
        "Accept": "multipart/form-data"
    }

    response = requests.get(url, headers=headers)
    decoder = MultipartDecoder.from_response(response)


    for part in decoder.parts:
        print("Part Headers:", part.headers)
        print("Part Body:", part.text)  # Or .content for bytes


    Or, if you are using configs as JSON and you are on AOS-CX 10.x+ you can use the following (but if you are using directly AOS-CX and not through Aruba Central):
    GET /rest/v10/fullconfigs/running?depth=1
    Accept: application/json





    ------------------------------
    Shpat | ACEP | ACMP | ACCP | ACDP
    Just an Aruba enthusiast and contributor by cases
    If you find my comment helpful, KUDOS are appreciated.
    ------------------------------



  • 3.  RE: JSON config export runningconfig/template (from group) classic central api

    Posted 19 days ago

    Hi,
    Thanks for the response,
    Or i am trying wrong or the response is wrong for this library because the response content type is not supported?

      "content-type": "text/plain; charset=UTF-8",

    "requests_toolbelt.multipart.decoder.NonMultipartContentTypeException: Unexpected mimetype in content-type: 'text/plain'"

    Im not familiar with this methodes and library.
    The response is just a plain text block as "show run" does, but ideally i want the output of "show run json"

    Maybe you know how to do this?
    Thanks




  • 4.  RE: JSON config export runningconfig/template (from group) classic central api

    Posted 19 days ago

    The response you are getting is Content-Type: text/plain, which means the Aruba API is not returning a multipart object, but instead just plain CLI config output.

    Can you try via REST to push this code (if you are using AOS-CX 10.x+ locally):


    GET /rest/v10/fullconfigs/running?depth=1
    Accept: application/json

    this should show the output of the command show running-config json via REST


    ------------------------------
    Shpat | ACEP | ACMP | ACCP | ACDP
    Just an Aruba enthusiast and contributor by cases
    If you find my comment helpful, KUDOS are appreciated.
    ------------------------------



  • 5.  RE: JSON config export runningconfig/template (from group) classic central api

    Posted 18 days ago

    Hey,

    It works, but it's a real pain right now. I have to pull the template and other calls through Central (with all the tokens), while the switch's direct API needs an admin account and a totally different setup.

    Any idea why we can't just load the template as JSON? We could pull the running config over serial- not ideal, but it only gives back plain text anyway.
    Can someone from HPE let me know? I'm sure I'm not the only one frustrated by this. Loading templates or configs as JSON via Classic Central should be possible!




  • 6.  RE: JSON config export runningconfig/template (from group) classic central api

    Posted 18 days ago

    I am not an expert on Central and i don't have much experience with it, however my opinion here is that Central is a true JSON-Based config with API in CX using REST and GraphQL (If not mistaken). AOS-CX can support JSON Config on the switch itself but Central will not reflect this in the template workflows (maybe i am wrong).

    What you can try to do (maybe) is to treat the Central templates as RAW CLI and parse them manually. So you could store your template definitions outside of Central and use the switch REST API (/rest/v10/.......) for GET and PUSH through real JSON Configs.

    One example would be, if you are using REST paths:
    GET /rest/v10/system
    GET /rest/v10/interfaces
    GET /rest/v10/vlans





    ------------------------------
    Shpat | ACEP | ACMP | ACCP | ACDP
    Just an Aruba enthusiast and contributor by cases
    If you find my comment helpful, KUDOS are appreciated.
    ------------------------------



  • 7.  RE: JSON config export runningconfig/template (from group) classic central api

    Posted 18 days ago

    Thanks, but I prefer to manage everything through Central, as it makes it much easier to control multiple devices without having to log into each one individually - which is necessary when using the AOS-CX API.

    Can someone from HPE or the API development team confirm whether it's possible to retrieve the running config or a template in JSON format via Central?




  • 8.  RE: JSON config export runningconfig/template (from group) classic central api

    Posted 18 days ago

    I would recommend to check with TAC or your Aruba/HPE local partner.



    ------------------------------
    Shpat | ACEP | ACMP | ACCP | ACDP
    Just an Aruba enthusiast and contributor by cases
    If you find my comment helpful, KUDOS are appreciated.
    ------------------------------