Developer

 View Only
last person joined: 5 days ago 

Expand all | Collapse all

Unable to update group configuration template through API

This thread has been viewed 19 times
  • 1.  Unable to update group configuration template through API

    Posted Dec 09, 2020 08:58 AM
    Hello there!

    Thanks for all the resources in this discussion!

    I have been struggling a bit with the results of a similar post in this community.

    In my case, I can't seem to update (patch) or create (post) any configuration templates for my groups on Aruba Central.

    1) Update an existing template.

    I am using the following python code:
    import requests
    from pprint import pprint
    
    group_name = 'home'
    
    url = 'https://eu-apigw.central.arubanetworks.com/configuration/v1/groups/' + group_name + '/templates' 
    
    params = {"name":"initial_template",
              "device_type":"CX",
              "version":"ALL",
              "model":"ALL"}
    
    headers = {'Content-Type': 'application/json',
                    'Authorization': 'Bearer ' + access_token}                
    
    file = {"template": open('template_files/initial_template.txt', 'rb')}
    
    response = requests.patch(url, headers=headers, files=file, params=params)
    response_json = response.json()
    pprint(response_json)​

    which returns a successful code:
    $ python3 set_template.py
    'Success'​

    And the template on Aruba Central updates its "last modified" attribute accordingly, but the changes are not in the template. The template in Aruba Central remains unchanged.

    2) Creating a new template, using the same code but changing the template name and the HTTP method:

    import requests
    from pprint import pprint
    
    group_name = 'home'
    
    url = 'https://eu-apigw.central.arubanetworks.com/configuration/v1/groups/' + group_name + '/templates' 
    
    params = {"name":"initial_template2",
              "device_type":"CX",
              "version":"ALL",
              "model":"ALL"}
    
    headers = {'Content-Type': 'application/json',
                    'Authorization': 'Bearer ' + access_token}
    
    file = {"template": open('template_files/initial_template.txt', 'rb')}
    
    response = requests.post(url, headers=headers, files=file, params=params)
    response_json = response.json()
    pprint(response_json)

    Which returns:

    $ python3 set_template.py
    {'detail': "Missing formdata parameter 'template'",
     'status': 400,
     'title': 'Bad Request',
     'type': 'about:blank'}

    even though I am using the 'template' key in the dict.

    Any thoughts on any of those issues would be really appreciated!
    Thanks!



    ------------------------------
    Alex
    ------------------------------


  • 2.  RE: Unable to update group configuration template through API

    EMPLOYEE
    Posted Dec 10, 2020 03:32 PM
    Hey Alex,

    Thanks for the explanation and the details of your errors as well as the code. I took a quick glance at it and compared to what we have in the configuration module of our PyCentral SDK. It seems pretty close.

    I'd recommend you use the PyCentral SDK; the functions are already prewritten and you just call them with the desired arguments. There are a few additional instructions on using it on our Developer Hub page.

    Thanks,
    Derek

    ------------------------------
    Derek Wang
    ------------------------------



  • 3.  RE: Unable to update group configuration template through API

    EMPLOYEE
    Posted Dec 11, 2020 03:26 PM
    Hi Alex,

    You have used the header Content-Type as 'application/json'. Try removing the Content-Type.

    ------------------------------
    Karthikeyan Dhandapani
    ------------------------------



  • 4.  RE: Unable to update group configuration template through API

    Posted Dec 14, 2020 03:04 AM
    Thank you, Karthikeyan!

    That was it!


    ------------------------------
    Alejandro Barbulo
    ------------------------------