This documentation does not describe all available APIs. It focuses on the most useful ones.
Currently, it is only possible to use Python code to interact with the APIs.
Most of the available APIs can be found in the server.py file located at /opt/wapt/waptserver/server.py on Debian.
Additional APIs are available in other files such as enterprise.py, repositories.py, wads.py, etc.
Warning
Since version 2.5, most API URLs are protected with SSL client certificates. Therefore, it is no longer possible to use HTML requests like: https://admin:MYPASSWORD@srvwapt.mydomain.lan/api/v1/hosts.
1- Create a WAPT user and assign the ACL “launch requests” (It is recommended to create a new user for requests because the password is included in the request).
In the waptconsole : Go to Tools > Manage Wapt users and rights.
New account > F2 name like reporting.
Change User password on Wapt server (an key appear on the right on your reporting user in the red on the picture below).
Click on “Run Reports” ACL ( in green in the picture below).
2- Depending on the request, it may be necessary to add ACLs on the reporting user. This can be see in the request file You can see this in the request in the api source file.
The Command-Line Method involves executing API requests directly from the command line interface (CLI) using tools like cmd on Windows or bash on Unix-based systems.
This method is quick and efficient for simple or one-off requests.
The Script-Based Method requires creating a Python script (.py file) to define and execute the API request.
This method is more flexible and powerful, allowing for complex logic, error handling, and data processing.
Connect to a WAPT Windows agent.
Create a directory named waptdev at the root of your disk, like, c:\waptdev\API_request.
Create a .py file in this directory to edit the request, like, api-1.py.
Copy the python script below and personalize the password for your user “reporting” and the desired API.
Run the file with the following command: “C:\Program Files (x86)\wapt\wapt-get.exe” c:\waptdev\API_request\api-1.py.
The output can be displayed in CSV format: cat api-1.csv.
Connect to a WAPT Linux agent.
Create a directory named waptdev at the root of your disk, like, /wapdev/.
Create a .py file in this directory to edit the request, like, api-1.py.
Copy the python script below and personalize the password for your user “reporting” and the desired API.
Run the file with the following command: /opt/wapt/wapt-get.bin /wapdev/api-1.py.
The output can be displayed in CSV format: cat api-1.csv.
Connect to a WAPT Linux agent.
Create a directory named waptdev at the root of your disk, like, /wapdev/.
Create a .py file in this directory to edit the request, like, api-1.py.
Copy the python script below and personalize the password for your user “reporting” and the desired API.
Run the file with the following command: /opt/wapt/wapt-get.bin /wapdev/api-1.py.
The output can be displayed in CSV format: cat api-1.csv.
The python script
importjsonimportwaptlicencesimportcsvimportsyssys.path.append('/opt/wapt')fromcommonimportWaptWAPT=Wapt()ini_wapt_path=WAPT.config_filenameuser="reporting"password="[Enter the password for user reporting]"defrun_report():auth_context=waptlicences.waptserver_login(ini_wapt_path,user=user,password=password)try:res=waptlicences.waptserver_request(ini_wapt_path,action='[enter the desired api]',auth_context=auth_context)ifres['http_status']==200:data=json.loads(res['content'])['result']# Debugging: Print the raw data received from the APIprint("Raw data from API:",json.dumps(data,indent=2))# Check if data is not emptyifnotdata:print("No data received from the API.")return[]# Check if the first element of data is a listifisinstance(data[0],list):forrowindata:# Assuming row is a list of stringsfori,valueinenumerate(row):ifisinstance(value,list):row[i]='|'.join(value)withopen('test.csv','w',newline='',encoding='utf-8')ascsvfile:fieldnames=data[0]writer=csv.writer(csvfile,delimiter=';')writer.writerow(fieldnames)writer.writerows(data[1:])# Write the rest of the dataelse:print("Unexpected data format. First element is not a list.")return[]returndataelse:raiseException('Request failed with status %s : %s'%(res['http_status'],res['content']))finally:waptlicences.waptserver_logout(ini_wapt_path)# Call the function and print the returned datadata=run_report()print(repr(data))
# Args:# has_errors (0/1): filter out hosts with packages errors# need_upgrade (0/1): filter out hosts with outdated packages# groups (csvlist of packages): hosts with packages# columns (csvlist of columns):# uuid (csvlist of uuid): <uuid1[,uuid2,...]>): filter based on uuid# filter (csvlist of field):regular expression: filter based on attributes# not_filter (0,1):# limit (int): 1000# trusted_certs_sha256 (csvlist): filter out hosts based on their trusted package certs# Returns:# result (dict): {'records':[],'files':[]}# query:# uuid=<uuid># or# filter=<csvlist of fields>:regular expression# """
Here is a python script that executes a query with a specific id from WAPT Console Reporting tab. In this script, user “reporting” should have “Run reports” ACL.
It works on every platform (windows, linux and mac agents).
"""Remove one or several hosts from the WAPT Server database and optionnally the host packagesArgs: uuids (list): list of uuids to delete filter (csvlist of field:regular expression): filter based on attributes delete_packages (bool): delete host's packages delete_inventory (bool): delete host's inventoryReturns: result (dict):"""
If you want to delete a host from the inventory:
curl--cert"C:\Program Files (x86)\wapt\private\71253c6c-f412-455b-a907-93b10ce07490.crt"--key"C:\Program Files (x86)\wapt\private\71253c6c-f412-455b-a907-93b10ce07490.pem"--insecure-XPOST--data-raw'{"uuids":["UUID"],"delete_inventory":"True","delete_packages":"True"}'-H"Content-Type: application/json""https://admin:MYPASSWORD@srvwapt.mydomain.lan/api/v3/hosts_delete"{"msg":"1 files removed from host repository\n1 hosts removed from DB","result":{"files":["/var/www/wapt-host/UUID.wapt"],"records":[{"computer_fqdn":"computer_fqdn","uuid":"UUID"}]},"success":true,"request_time":null}
If you do not want to delete from the inventory:
curl--cert"C:\Program Files (x86)\wapt\private\71253c6c-f412-455b-a907-93b10ce07490.crt"--key"C:\Program Files (x86)\wapt\private\71253c6c-f412-455b-a907-93b10ce07490.pem"--insecure-XPOST--data-raw'{"uuids":["UUID"],"delete_inventory":"False","delete_packages":"False"}'-H"Content-Type: application/json""https://admin:MYPASSWORD@srvwapt.mydomain.lan/api/v3/hosts_delete"{"msg":"0 files removed from host repository\n1 hosts removed from DB","result":{"files":[],"records":[{"computer_fqdn":"computer_fqdn","uuid":"UUID"}]},"success":true,"request_time":null}