Create a Post
cancel
Showing results for 
Search instead for 
Did you mean: 
AOBELAR
Contributor

How to Create and Populate a Virtual Group Using Python and the Harmony Endpoint API

Introduction

In this article, I will share a Python script that allows you to create and populate a Virtual Group using the Harmony Endpoint API. I will explain the necessary steps to obtain the CLIENT_ID and ACCESS_KEY and how to use them to authenticate and consume the API.

Step 1: Authentication

Thanks to Facundo García Parolari (Novared), I understood which options to select to generate the CLIENT_ID and ACCESS_KEY. Once obtained, these credentials will be used to generate a token that is passed as a parameter to access the API.

 

harmony.png

Which in this case is "Endpoint", in my case it was not clear to me among so many options.

 

Step 2: Required URLs

It is important to consider your subscription region when defining the URLs:

AUTH_URL = "https://cloudinfra-gw-us.portal.checkpoint.com/auth/external

LOGIN_URL = "https://cloudinfra-gw.portal.checkpoint.com/app/endpoint-web-mgmt/harmony/endpoint/api/v1/session/lo...

CREATE_VIRTUAL_GROUP_URL = "https://cloudinfra-gw.portal.checkpoint.com/app/endpoint-web-mgmt/harmony/endpoint/api/v1/organizati...

Note: The region cloudinfra-gw-us is for this specific configuration.

Step 3: Obtain Computer IDs

To populate the Virtual Group, it is necessary to obtain the computer IDs. I search for objects (e.g., "Computer"), store them in an array, and then pass them as a parameter when creating the group.

Step 4: Create and Populate the Virtual Group

The following code demonstrates how to perform this task:

 

import requests 

import json 

def get_token(client_id, access_key): 

    payload = { 

        "clientId": client_id, 

        "accessKey": access_key 

    } 

    response = requests.post(AUTH_URL, json=payload) 

    return response.json().get("token") 




def create_virtual_group(token, api_token, group_name, description, computer_ids): 

    headers = { 

        "Authorization": f"Bearer {token}", 

        "X-API-Key": api_token, 

        "Content-Type": "application/json" 

    } 

    payload = { 

        "name": group_name, 

        "description": description, 

        "computerIds": computer_ids 

    } 

    response = requests.post(CREATE_VIRTUAL_GROUP_URL, headers=headers, json=payload) 

    return response.json() 

# Get the authentication token 

client_id = "YOUR_CLIENT_ID" 

access_key = "YOUR_ACCESS_KEY" 

token = get_token(client_id, access_key) 

# Group data 

group_name = "Group1" 

description = "Test group" 

computer_ids = [ 

    "c8929cd6-c69e-47d7-b8d8-f9b9dcf7a2a1", 

    "f2d01a1f-efd1-495c-9abf-f62edcbdfb26" 

]  # Replace with valid IDs 

# Create the virtual group 

api_token = "YOUR_API_TOKEN" 

response = create_virtual_group(token, api_token, group_name, description, computer_ids) 

print("API Response:", response) 

 

Final Explanation

The script is designed to:

  1. Authenticate using the CLIENT_ID and ACCESS_KEY.
  2. Obtain a session token.
  3. Create a Virtual Group using the specified computer IDs.

I hope this guide helps you automate the management of Virtual Groups within your Harmony Endpoint environment.

 

0 Replies

Leaderboard

Epsum factorial non deposit quid pro quo hic escorol.

Upcoming Events

    CheckMates Events