--- title: "Example: using the web services API" slug: "example-using-the-web-services-api" tags: ["Reference"] updated: 2026-08-20T06:54:20Z published: 2026-09-03T18:40:54Z canonical: "docs.trellix.com/example-using-the-web-services-api" --- > ## Documentation Index > Fetch the complete documentation index at: https://docs.trellix.com/llms.txt > Use this file to discover all available pages before exploring further. # Example: using the web services API In the following code example, a Python script is used to authenticate to the Central Management System appliance and then to request a report from the Central Management System appliance. ``` #!/usr/bin/env python3 import base64 import ssl import sys import urllib.request ctx = ssl.create_default_context() ctx.check_hostname = False ctx.verify_mode = ssl.CERT_NONE class WsConnection:    def __init__(self, base_url, username, password):        url = base_url + "/auth/login"        print("Authenticating: %s %s %s" % (url, username, password))        request = urllib.request.Request(url=url, data="POST".encode())        base64string = base64.b64encode(bytes('%s:%s' % (username, password), 'ascii'))        request.add_header("Authorization", "Basic %s" % base64string.decode('utf-8'))        result = urllib.request.urlopen(url=request, context=ctx)        self.auth_token = result.getheader('X-FeApi-Token')        print("Authenticated. Token:" + self.auth_token)        return    def send_request(self, url):        print("SEND_REQUEST:" + url)        request = urllib.request.Request(url)        request.add_header("X-FeClient-Token", "test")        request.add_header("X-FeApi-Token", self.auth_token)        result = urllib.request.urlopen(url=request, context=ctx)        return result.read() def getAlerts(connection, baseurl, argsList):    url = baseurl + "/alerts?"    for arg in argsList:        url += arg[0] + "=" + arg[1] + "&"    print(connection.send_request(url).decode()) def getReports(connection, baseurl, argsList):    url = baseurl + "/reports/report?"    file_type = -1    for arg in argsList:        url += arg[0] + '=' + arg[1] + '&'        if arg[0] == 'type':            file_type = arg[1]    res = connection.send_request(url)    if len(res) != 0 and file_type != -1:        report_file_name = None        if file_type == 'pdf':            report_file_name = 'report.pdf'        if file_type == 'csv':            report_file_name = 'report.csv'        if report_file_name:            with open(report_file_name, 'wb') as f:                f.write(res) def logout(token, base_url):    url = base_url + "/auth/logout"    print("Calling  logout:" + url)    request = urllib.request.Request(url, "POST".encode())    request.add_header("X-FeClient-Token", "test")    request.add_header("X-FeApi-Token", token)    urllib.request.urlopen(request, context=ctx)    return def usage_exit():    print("python3 api_client.py cms={cms address} port={port} user={user} pass={pass} api={api} [filter1={value1}]")    exit(1) cmsAddress = False cmsPort = False username = False password = False api = "alerts" version = "/v2.0.0" argList = [] if __name__ == "__main__":    skipOnce = True    for arg in sys.argv:        if skipOnce:            skipOnce = False            continue        key, value = arg.split("=")        if key == "cms":            cmsAddress = value            continue        if key == "port":            cmsPort = value            continue        if key == "user":            username = value            continue        if key == "pass":            password = value            continue        if key == "api":            api = value            continue        tpl = [key, value]        argList.append(tpl)    if cmsAddress and cmsPort and username and password:        baseurl = "https://" + cmsAddress + ":" + cmsPort + "/wsapis" + version        conn = WsConnection(baseurl, username, password)        if api == "alerts":            print("Calling alerts API")            getAlerts(conn, baseurl, argList)        if api == "reports":            print("Calling reports API")            getReports(conn, baseurl, argList)        logout(conn.auth_token, baseurl)    else:        usage_exit() ``` :