can't get pdf export to give me a file

I'm developing a python script that is calling the mode API.  The main purpose of the script is the following:

  1. run a report using the post command of https://modeanalytics.com/api/<account>/reports/<report>/runs
  2. wait for the report to finish (while loop checking the run state) using https://modeanalytics.com/api/<account>/reports/report/runs/<run>
  3. when the run is done, I want to get the PDF rendition of the report. I've implemented bits of the sample script from this thread https://forum.modeanalytics.com/t/18m91b/ftp-report-uploads ; however, when I get the pdf export url, it always returns the state 'new' below. Is there some addition setting or a different method required to get the pdf rendition?

{
    "state": "new",
    "created_at": null,
    "content_length": null,
    "stale": false,
    "filename": null,
    "_links": {
        "self": {
            "href": "/api/account/reports/442fea1af25d/exports/runs/fba24d438923/pdf.pdf"
        }
    }
}

2replies Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
  • Hi Paul Kaisharis - thanks for writing in. The answer to your question is both undocumented and non-obvious - apologies that it's a bit opaque!

    Whenever a new report run completes and a PDF has not already been generated (either via the Mode UI or a scheduled email job with an attached PDF), you will see the type of response listed above  (with `state: new`) when you hit endpoint located at `_links.pdf_export.href' located in the report run endpoint.

    Therefore, there are a few additional steps to perform after the ones you outlined. To complete the process:

    4) Kick off a PDF generation job on our end by hitting that `pdf_export` endpoint with a POST. If successful, the response will include `state: enqueued`

    5) Poll the same endpoint with a GET occasionally (the job usually takes a few seconds to complete) until you get `state: completed`

    6) Once completed, the PDF download link will be available in `_links.download.href`

    Hope that helps!

    Reply Like
  • great, thx Jonathan Krangel .  i ended up using the 'preview' image (our reports are typically one pagers) and rendering that to pdf, but good to know there is a way to get to the pdf as well.  i also ended up using the csv data to generate an excel output, as an aside. 

    Reply Like
Like Follow
  • Status Answered
  • 2 mths agoLast active
  • 2Replies
  • 173Views
  • 2 Following

Create A New Discussion

Share your thoughts