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.

curl -X GET \
"https://www.meterian.com/api/v1/reports/$PROJECT_UUID/full?branch=master" \
--max-time 90 \
-H "Authorization: token $METERIAN_API_TOKEN" \
-H "accept: application/json" > report.json

Generating a PDF report

A PDF report containing the results of the analysis.

curl -X GET \
"https://www.meterian.com/api/v1/reports/$PROJECT_UUID/pdf?branch=master" \
--max-time 90 \
-H "Authorization: token $METERIAN_API_TOKEN" \
-H "accept: application/pdf" > report.pdf

Generating a JSON dependency tree report

A JSON report listing the full dependency tree of the project.

curl -X GET \
"https://www.meterian.com/api/v1/reports/$PROJECT_UUID/tree?branch=master" \
--max-time 90 \
-H "Authorization: token $METERIAN_API_TOKEN" \
-H "accept: application/json" > report.tree.json

Generating a SBOM CSV report

A simple CSV report listing all the components of the projects.

curl -X GET \
"https://www.meterian.com/api/v1/reports/$PROJECT_UUID/sbom.csv?branch=master" \
--max-time 90 \
-H "Authorization: token $METERIAN_API_TOKEN" \
-H "accept: text/csv" > report.sbom.csv

Generating a SBOM CycloneDX JSON report

A JSON report in CycloneDX format.

curl -X GET \
"https://www.meterian.com/api/v1/reports/$PROJECT_UUID/sbom-cdx.json?branch=master" \
--max-time 90 \
-H "Authorization: token $METERIAN_API_TOKEN" \
-H "accept: application/json" > report.cdx.json

Generating a SBOM CycloneDX XML report

An XML report in CycloneDX format.

curl -X GET \
"https://www.meterian.com/api/v1/reports/$PROJECT_UUID/sbom-cdx.xml?branch=master" \
--max-time 90 \
-H "Authorization: token $METERIAN_API_TOKEN" \
-H "accept: application/xml" > report.cdx.xml

Generating a PDF BIBLE report

curl -X GET \
"https://www.meterian.com/api/v1/reports/$PROJECT_UUID/bible.pdf?branch=master" \
--max-time 90 \
-H "Authorization: token $METERIAN_API_TOKEN" \
-H "accept: application/pdf" > bible.pdf

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.

ID=`curl -X POST \
"https://www.meterian.com/api/v1/reports/$PROJECT_UUID/bible?branch=master" \
-H "Authorization: token $METERIAN_API_TOKEN" \
-H "accept: text/plain"`

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.

curl -X GET \
"https://www.meterian.com/api/v1/reports/$PROJECT_UUID/bible/$ID" \
-H "Authorization: token $METERIAN_API_TOKEN" \
-H "accept: application/json"

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