When are scan data available for report generation ?

we're developing an automated virtual machine creation procedure, one of the final quality control test is a powershell script that triggers a Qualys security scan of the newly generated vm, parses the report for vulnerabilities and downloads the technical report. The script works fine, but sometimes the report generated is blank, even though the scan result has the approriate data. The report says:

"No data is displayed due to one or more of these reasons:- There was no data found for this host.- This host was never scanned.- The data for this host was purged.- One or more hosts are in the Excluded Hosts list.- Hosts were scanned but no open port was found."

By trial and error we're now making the script wait 15 minutes between the scan completion and the report generation, and this way the reports are correct, but I'm wondering if there is a Qualys condition to test that allows us to be sure it's the right time to generate the report without resorting to just sleep the script for an arbitrary amount of time.

Here's the psedo-code of the script:

gets newly generated vm ip address and adds it to the host assets

adds the ip address to a Windows authentication record (VMs are Windows servers in workgroup)

launches a scan on the ip address and waits for the scan to complete using the following test:

SCAN_LIST_OUTPUT.RESPONSE.SCAN_LIST.SCAN.STATUS.STATE -eq 'finished'

parses the scan result for vulnerabilities

At this stage of the script we already have the data we need, but we couldn't find an api call to just download the scan results, what can be done via this gui menu:

insted, we proceed to wait an arbitrary amount of time and then generate a report

waits for 15 minutes

launches the report and waits for the report to complete using the following test:

and thanks for the support: we're actually already fetching the json_extended scan result with

/api/2.0/fo/scan/?action=fetch

to parse the number and severity of the vulnerabilities on the newly generated vm when the scan is complete, and drop the vm if they're over a certain threshold. As for reporting, we want to keep the .mht format report for future reference, and it is my understanding the /api/2.0/fo/scan/?action=fetch is limited to {csv|json| csv_extended| json_extended} output formats only.

The .mht is what you can get both with the view and download menu in the Gui context menu for the completed scan, the web pages that open up show these kind of endpoints, I haven't found a way to use them programmatically:

/fo/report/report_view.php?&id=123456&default=1&format=30

/fo/report/download_report.php?report_id=987654321

it'd be great if there's an api I'm missing to fetch the .mht directly from the scan results.