I attach the full code.
As I had mentioned before, it runs without error and creates a file for each report in the target folder. The text is a json format that allows you to rebuild the Visual Analytics report by loading the pasted json string into a blank report.
BUT it cuts at 32167 bytes which is far to short to describe more sophisticated reports.
cas mySession sessopts=(caslib=casuser timeout=1800 locale="en_US");
caslib _all_ assign;
/* --- Begin Edit --- */
%let BASE_URI=%sysfunc(getoption(servicesbaseurl));
%put &base_uri.;
%let baseurl=https://XXXXXXXXXX;
filename folders temp;
proc http
url = "https://XXXXXXXXXX"
out= folders
oauth_bearer = sas_services;
headers
'Accept'= 'application/vnd.sas.collection+json';
run;
libname folders clear;
libname folders json;
%let hostname = https://XXXXXXXX;
%let endpoint = /folders/folders;
%let path = "/Public/ODAP_REPORTS" ;
%let output = "/in_pdf";
cas mySession sessopts=(caslib=casuser timeout=1800 locale="en_US");
caslib _all_ assign;
/**********************************************************/
/* Retrieve the ID of the folder where the report resides */
/**********************************************************/
filename folders clear;
filename folders temp;
proc http
url = "&hostname.&endpoint/@item"
query = ("path"=&path)
out= folders
oauth_bearer = sas_services;
headers
'Accept'= 'application/vnd.sas.content.folder+json';
run;
libname folders clear;
libname folders json;
/*************************************************/
/* Get a list of objects in that specific folder */
/*************************************************/
/* Identify the endpoint to be used */
proc sql ;
select href, type into :endpoint, :type
from folders.links
where method="GET" and rel = "members";
quit;
/* Retrieve the list of objects */
filename memList clear;
filename memList temp;
proc http
url = "&hostname.%trim(&endpoint)"
out= memList
oauth_bearer = sas_services;
headers
"Accept"= "%trim(&type)+json";
run;
libname memList clear;
libname memList json;
/******************************************************/
/* Extract report content (structure) for each report */
/******************************************************/
/* Macro to write the output to a json file */
%sysmacdelete writeJson;
%macro writeJson(name, path);
filename outcsv FILESRVC FOLDERPATH='/Users/XXXX@company.com/My Folder/in_pdf' FILENAME="_&name..json";
proc json out=outcsv nosastags pretty noscan ;
export casuser.info;
run;
%mend;
/* Macro to read the report content and generate the output file */
%sysmacdelete readReportContent;
%macro readReportContent (url, name, path, endpoint, output);
filename content clear;
filename content temp;
proc http
url="&url.%trim(&endpoint)/content"
out=content
oauth_bearer=sas_services;
headers
"Accept"="application/vnd.sas.report.content+json";
quit;
data casuser.info;
length report $128
path $1024
content varchar(200000);
infile content;
input;
report="&name";
path="&path";
content=substrn(_infile_, 1, 200000);
run;
data _null_;
set casuser.info;
where path ne '';
location=tranwrd(path, "/", "_");
mcall=cat('%writeJson(', trim(report), ',', trim(location), ')');
call execute(mcall);
run;
/* proc sql; */
/* drop table info; */
/* quit; */
%mend;
/* Generate a view containing information to call readReportContent */
proc sql;
create table merged as
select "&hostname" as url,
a.ordinal_items,
a. name,
a.uri,
b.href,
b.type ,
b.method
from memlist.items as a
left join memlist.items_links as b
on a.ordinal_items=b.ordinal_items
having a.contentType="report" and b.rel="getResource";
quit;
options mlogic;
/* Call readReportContent macro for each report */
data _null_;
length mcall $1024;
set merged(firstobs=1);
out=&output;
path=&path;
mcall=cat('%readReportContent(', trim(url), ",", trim(name), ",", trim(path),",", trim(href), ",", trim(out), ')');
call execute(mcall);
run;
... View more