Generating reports via APIs
A simple guide to generate reports using APIs
Usually reports can be generated directly via the clients (see how to produce reports using the codebase scanner or the container scanner), and it's also possible to generate reports from the web report page. However, sometimes one may need to generate a report just using the APIs. This is easy and requires a simple HTTP call that can be executed with a curl command.
First, please make sure you have an adequate token to invoke the API, loaded in the environment variable METERIAN_API_TOKEN. The token can be generated via the Web Dashboard.
You will also need the UUID of the project you want to report: this can be picked up from the URL of a report, which is in the form https://www.meterian.io/projects/?pid=UUID&mode=.... Let's assume we have this loaded in the environment variable PROJECT_UUID, and the branch is "master".
Synchronous generation
Reports can be generated synchronously, but when generating large reports you should allow a long timeout, as the generation may take time. This depends on the condition of the project and of the platform. This is especially true with the SBOM reports, as they include copyright information about the packages. Please see the specific section to learn how to execute calls asynchronously if you want to avoid long timeouts.
Generating a JSON report
A JSON report containing the results of the analysis.
Generating a PDF report
A PDF report containing the results of the analysis.
Generating a JSON dependency tree report
A JSON report listing the full dependency tree of the project.
Generating a SBOM CSV report
A simple CSV report listing all the components of the projects.
Generating a SBOM CycloneDX JSON report
A JSON report in CycloneDX format.
Generating a SBOM CycloneDX XML report
An XML report in CycloneDX format.
Generating a PDF BIBLE report
Asynchronous generation
In case of large project or large reports, it's possible to generate then asynchronously. You can send a request to the server asking to start the report generation, which will return a unique id. you can then use this id to enquiry about the progress of the generation. When complete, you can then call any of the synchronous APIs and get the report immediately.
Start preparation
When this API is executed the preparation of the report will be initiated. A unique identifier will be returned, to be used in following enquiries. In this case we store the result in the variable ID, which we will later use.
Check progress
With this API you can check the progress of the preparation. It returns a number from 0 to 100 that is equivalent to the percentage of preparation. When it's 100, you can then call any of the synchronous API listed before. It also returns 200 if done or 404 if in progress.
When finished, please use the synchronous section to see how to call the APIs to collect the reports. Please note that a prepared bible, which is used to generate reports, will expire usually in 10 minutes, or even earlier, based on the status of the server.
Last updated