In my earlier weblog Programmatically export a Visible Analytics report back to PDF – SAS Customers, I exploit the SAS Visible Analytics SDK to export a report back to PDF, which is sort of easy if now we have primary information with JavaScript programming. It really works for each the most recent model of SAS Viya and model 3.5. The brand new model of SAS Viya provides enhancements and now we have the choice to export VA report back to PDF — utilizing REST API, with out want of JavaScript programming. That is what I’ll focus on on this publish.
The API underneath Visible Analytics class in newest SAS Viya, supplies the flexibility to export a report, or a report object, to a PDF file. It additionally supplies the flexibility to create and run a job to do the exporting. Truly, we are able to export a report PDF, picture, package deal, and information utilizing the APIs. All are fairly straight ahead. On this article, I’ll present how you can export a report or report object to PDF file instantly, and how you can create and run a job to export to a PDF.
Get all of the API hyperlinks of Visible Analytics
The API underneath Visible Analytics supplies the flexibility to retrieve all of the API hyperlinks by way of the http ‘GET’ methodology. You’ll want to set the “Settle for” = “software/vnd.sas.api+json” within the HEADERS of PROC http. Beneath is my pattern code snippet, I outline a json library so we are able to view the output of PROC http visually.
%let BASE_URI=%sysfunc(getoption(SERVICESBASEURL)); FILENAME vaJason TEMP ENCODING='UTF-8'; FILENAME hdrout TEMP ENCODING='UTF-8'; PROC HTTP METHOD="GET" oauth_bearer=sas_services out=vaJason headerout=hdrout URL = "&BASE_URI/visualAnalytics/"; HEADERS "Settle for" = "software/vnd.sas.api+json"; RUN; LIBNAME vaJason json; |
If we see the message of ‘200 OK’ returned (one thing like under), we all know the PROC runs efficiently.
Now in SAS Studio, if I’m going to the ‘Libraries’ tab, double click on the LINKS desk within the VAJASON library, all of the API hyperlinks of Visible Analytics are listed within the ‘href’ columns as proven under. We see the assist of exporting the report PDF, picture, package deal, and information with corresponding methodology and href.
Export a report or report object to PDF
Now, let me export a report back to PDF instantly. Beneath is the code snippet I used. With the FILENAME assertion, the exported PDF might be saved in a bodily location (I reserve it as rpt.pdf file within the /tmp/ folder). You’ll want to set the “Settle for” = “software/pdf” within the HEADERS of PROC http. In my instance, I export a report with two report objects: a bar chart and a forecasting object.
%let BASE_URI=%sysfunc(getoption(SERVICESBASEURL)); FILENAME rptFile "/tmp/rpt.pdf"; PROC HTTP METHOD="GET" oauth_bearer=sas_services OUT=rptFile headerout=hdrout URL = "&BASE_URI/visualAnalytics/stories/d940126c-f917-4a13-8e1a-51b6729f50ec/pdf"; HEADERS "Settle for" = "software/pdf" "Settle for-Language" = "*" "Settle for-Locale" = "en-US"; RUN; |
Run the code, and if we see the message of ‘200 OK’ returned, we all know the export succeeded. We are able to go to the /tmp/ folder and verify the rpt.pdf file there.
Subsequent, let me export a report object to PDF. In case you are not accustomed to objects composition of a VA report, confer with my earlier publish Uncover Visible Analytics Report Paths with REST APIs. Completely different from exporting a report, I must set the parameter ‘reportObjects’ for the exported object. With the ‘GET’ methodology in PROC http, I exploit the QUERY choice to set all of the parameters I wish to use for the article. For instance, I set some cowl web page textual content. Beneath is the code snippet for report object exporting.
%let BASE_URI=%sysfunc(getoption(SERVICESBASEURL)); FILENAME rptFile "/tmp/rpt.pdf"; PROC HTTP METHOD="GET" oauth_bearer=sas_services OUT=rptFile headerout=hdrout URL = "&BASE_URI/visualAnalytics/stories/d940126c-f917-4a13-8e1a-51b6729f50ec/pdf" QUERY = ("reportObjects"="ve58" "includeCoverPage"=true "coverPageText"="That is cowl web page for a report object."); HEADERS "Settle for" = "software/pdf" "Settle for-Language" = "*" "Settle for-Locale" = "en-US"; RUN; |
Equally, if we see the message of ‘200 OK’ returned, we all know the export runs efficiently. The next screenshots present the exported report PDF and the exported report object PDF, respectively.
Create and run a job to export a PDF
In addition to exporting a report or report object instantly, the API underneath Visible Analytics supplies the flexibility to asynchronously execute the export job. The variations between instantly export and job export are:
- The ‘POST’ methodology is used for the job export motion.
- To export a report or report object by working a job, we have to apply the rendering choice values within the request object, in addition to choices for the creation of the PDF.
- Job export will save the export pdf file to the SAS Viya Content material server folder, not a bodily disk location. The PDF file might be then downloaded to native disk from SAS Studio or SAS Drive.
Beneath is the code snippet of making a job to export report pdf. You’ll want to set the “Settle for” = “software/vnd.sas.visible.analytics.report.export.pdf.job+json”, and “Content material-Sort” = “software/vnd.sas.visible.analytics.report.export.pdf.request+json” within the HEADERS of PROC http.
%let BASE_URI=%sysfunc(getoption(SERVICESBASEURL)); FILENAME hdrout TEMP ENCODING='UTF-8'; PROC HTTP METHOD="POST" oauth_bearer=sas_services headerout=hdrout URL = "&BASE_URI/visualAnalytics/stories/d940126c-f917-4a13-8e1a-51b6729f50ec/exportPdf" IN = '{ "resultFolder": "/folders/folders/9d78f045-e7d9-4e82-b4aa-c7220cb85558", "resultFilename": "Exported PDF File.pdf", "nameConflict": "exchange", "wait": 30, "timeout": 60, "choices": { "orientation": "panorama", "paperSize": "A4", "showPageNumbers": true, "includeCoverPage": true, "coverPageText": "That is cowl web page for export pdf job." }, "model": 1 }' ; HEADERS "Settle for" = "software/vnd.sas.visible.analytics.report.export.pdf.job+json" "Content material-Sort" = "software/vnd.sas.visible.analytics.report.export.pdf.request+json" "Settle for-Language" = "*" "Settle for-Locale" = "en-US"; RUN; |
If we see the message of ‘201 Created’ returned as proven under, we all know the export job runs efficiently.
Beneath screenshot exhibits the exported report PDF.
Lastly
In abstract, for the most recent model of SAS Viya, the REST API underneath Visible Analytics class supplies a straightforward strategy to export a report or a report object to a PDF file, both instantly, or by a job asynchronously. We are able to additionally simply export the report object to picture, the report information to CSV, TSV, XLSX, and the report sources to a package deal. You might be inspired to search out extra at Visualization – Visualization API Reference (sas.com).