Kibana report generation - Spring Boot

I am trying to automatically download the Kibana report in PDF format. Following the documentation here : Automatically generate reports | Kibana Guide [8.13] | Elastic

The issue is, on hitting the path that has been returned by the POST call, it returns JSON data. But I want the PDF to be downloaded and stored at a location.

JSON to PDF seems to be a lengthy process and there's no schema that is fixed for the pdf report json that we will get every time. And apparently it requires schema to be fixed for json to pdf conversion in spring boot.

Any better way to do it?

The documentation is clear on how this works:

  • Get the POST URL from Kibana for your report
  • Call that URL correctly (this depends on your environment) in my case using curl would be as:
currl --user $ELASTIC_USER:$ELASTIC_PASSWORD \
  -XPOST \
  -H "kbn-xsrf:true" \ 
  "${KIBANA_HOST}${KIBANA_REPORT}
{
    "path": "/api/reporting/jobs/download/47a25336-c2a2-4d94-88da-0b01566dc42f",
    "job": {
        "id": "47a25336-c2a2-4d94-88da-0b01566dc42f",
        "index": ".reporting-2024-04-28",
        "jobtype": "printable_pdf_v2",
        "created_at": "2024-04-29T14:50:42.420Z",
        "created_by": "elastic",
        "meta": {
            "objectType": "dashboard",
            "layout": "preserve_layout",
            "isDeprecated": false
        },
...
}

The JSON returned has a path parameter that, concatenated to your Kibana host URL will return your PDF

curl --user $ELASTIC_USER:$ELASTIC_PASSWORD \
  -XGET \
  -H "kbn-xsrf:true" \
  --output report.pdf \
  "${KIBANA_HOST}/api/reporting/jobs/download/47a25336-c2a2-4d94-88da-0b01566dc42f"

So just to reiterate, downloading a report from Kibana is a two-steps process, minding that the first step triggers an async process that may need some time to deliver the report as detailed in the 503 (Service Unavailable) section.