HomeGuidesAPI Reference
GuidesAPI ReferenceGitHubAirheads Developer CommunityLog In

REST API Workflows

Leveraging automation, can save time and cost to implement workflows that are done manually.

API endpoints for some of the workflows mentioned in the Use Cases section are provided below.

Site Deployment Workflow

In this workflow let's do the following

  • Create a Group
  • Move devices to the created Group
  • Create a Site
  • Assign devices to the created Site

Create a Site:

API Endpoint Path: /central/v2/sites
Request Method: POST
Request Headers: "Authorization": "Bearer <access_token>"
Request Payload:

{
  "site_name": "site1",
  "site_address": {
    "address": "3970 Rivermark Plaza",
    "city": "Santa Clara",
    "state": "California",
    "country": "United States",
    "zipcode": "95053"
  },
  "geolocation": {
    "latitude": "38.8951",
    "longitude": "-77.0364"
  }
}

HTTP Response: For successful request, site_id will be returned for created site

{
  "site_id": 9,
  "site_name": "site1"
}

Create a Group:

API Endpoint Path: /configuration/v2/groups
Request Method: POST
Request Headers: "Authorization": "Bearer <accesstoken>"
Request Payload: Setting _true
for Wired, Wireless keys will make the group a template group.

{
  "group": "Central_Group",
  "group_attributes": {
    "group_password": "Aru2Ba@",
    "template_info": {
      "Wired": true,
      "Wireless": true
    }
  }
}

HTTP Response: For successful request

"Created"

Assign device to a Site:

API Endpoint Path: /central/v2/sites/associate
Request Method: POST
Request Headers: "Authorization": "Bearer <access_token>"
Request Payload:

{
  "device_id": "AD12412345",
  "device_type": "IAP",
  "site_id": 4
}

HTTP Response: No response message will be received for successful HTTP request.

Move devices to a Group:

This API endpoint moves a list of devices to a group. The devices are represented as serial numbers.

API Endpoint Path: /configuration/v1/devices/move
Request Method: POST
Request Headers: "Authorization": "Bearer <access_token>"
Request Payload:

{
  "group": "Central_Group",
  "serials": [
    "string"
  ]
}

HTTP Response: For successful request

"Success"

Python Example

Python script developed using pycentral Python SDK for site deployment workflow.

# Create the following files by refering to the samples.
csv_filename = "csv_file.csv"
central_filename = "input_token_only.yaml"

# Get instance of ArubaCentralBase from the central_filename
from pycentral.workflows.workflows_utils import get_conn_from_file
central = get_conn_from_file(filename=central_filename)

# Import Groups and Sites class
from pycentral.configuration import Groups, Devices
from pycentral.monitoring import Sites
g = Groups()
s = Sites()
d = Devices()

# Define Workflow Variables
group_name = "demo-grp"
group_pass = "pass@123"
site_name = "demo-site"
site_address = {
  "address": "3000 Rivermark Plaza",
  "city": "Santa Clara",
  "state": "California",
  "country": "United States",
  "zipcode": "95053"
}
device_type = "IAP"
device_serials = ["CNXXXXXX01", "CNXXXXXX02", "CNXXXXXX03"]

# 1. Create a Template Group
print("1. Create a Group")
resp = g.create_group(central, group_name=group_name, group_password=group_pass, 
                      wired_template=True, wireless_template=True)
print(resp)

# 2. Move devices to a Group
print("2. Move devices to a Group")
resp = d.move_devices(central, group_name=group_name,
                      device_serials=device_serials)
print(resp)  
    
# 3. Create a Site
print("3. Creating Site")
resp = s.create_site(central, site_name=site_name, site_address=site_address)
print(resp)

# 4.1 Find site_id from site_name
site_id = s.find_site_id(central, site_name=site_name)

# 4.2 Assign Devices
print("4. Assign Devices to a Site")
resp = s.associate_devices(central, site_id=site_id, 
                           device_type=device_type, device_id=device_serials)
print(resp)