Created dateUpdated dateAffects versionFix version

 

 

Management PortalN/A

Description

This page includes a collection of example scripts which can be used to get introduced with the Blancco Management Portal API endpoints.

NOTE! The provided scripts are fully experimental and built a single use case scenario in mind and are not meant to be used in a production environment!

There is no guarantee or warranty that these scripts will work as intended in a customer specific environment.

Running this script is only recommended in a controlled, non-production environment. Use the provided scripts at your own risk.

Python

Requirements:

  • Python
  • Requests library

This script will export multiple pages of reports one report at a time ("size" parameter set to 1) printing the results and giving a summary after exporting the last page/report.

The endpoint URL, API key, export filter and other parameters are provided as part of the script and can be modified.

Example python script to export multiple pages of reports a single report at a time
import requests

def execute_curl_request(cursor=None):
    url = 'https://api.eu-west-1.blancco.cloud/v1/report/export'
    headers = {
        'Content-Type': 'application/json',
        'X-BLANCCO-API-KEY': 'YOUR-API-KEY'
    }
    data = {
        "filter": {
            "date": {
                "gte": "2023-07-01T00:00:00Z"
            }
        },
        "format": "XML",
        "container": "NONE",
        "size": 1
    }

    if cursor:
        url += f"?cursor={cursor}"

    response = requests.post(url, headers=headers, json=data)
    return response

def check_and_print_response(response):
    if response.status_code == 200:
        print(response.text)

        cursor_header = response.headers.get('x-blancco-cursor')
        return cursor_header, True
    else:
        print("Request failed with status code:", response.status_code)
        return None, False

if __name__ == "__main__":
    cursor = None
    success_count = 0
    failure_count = 0

    while True:
        response = execute_curl_request(cursor)

        if success_count == 0:
            print("\n--------------------------------------------------")

        new_cursor, success = check_and_print_response(response)

        if success:
            success_count += 1
        else:
            failure_count += 1

        if new_cursor:
            cursor = new_cursor
        else:
            break

    print("\n--------------------------------------------------")
    print("All matching reports exported. Summary of exported reports:")
    print(f"Successful exports: {success_count}")
    print(f"Failed exports: {failure_count}")