BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
idziemianczyk
Obsidian | Level 7

In the Create report document there is an example of creation VA report. I tested this piece of code and the creation of the report is not complete. I can’t open the report created by this code in SAS VA(so I can’t apply modifications using Ctrl+Alt+B XML code or any other way). 

 

My questions are:

  1. Do I need extra parameters in BODY_IN or Headers to allow SAS VA to open the file? In the documentation we see exactly this example and no more options.
  2. Do we have any other way to create a new report or create copy existing report using REST API or CLI?

 

%let folder_uri=/folders/folders/6bcef06c-554c-4ac8-8790-d921977f9933;

%let BASE_URI=%sysfunc(getoption(servicesbaseurl));

filename rep_id temp;

filename body_in temp;

 

data _null_;

               file body_in;

               put '{  "name": "test_report",';

               put '"description": "testdescription"}';

run;

 

proc http url="&BASE_URI.reports/reports?parentFolderUri=&folder_uri"

               method='post'

               oauth_bearer=sas_services

               in = body_in

               out=rep_id;

               headers "Content-Type"="application/vnd.sas.report+json"

                                            "Accept"="application/vnd.sas.report+json";

run;

1 ACCEPTED SOLUTION

Accepted Solutions
joeFurbee
Community Manager

Hi @idziemianczyk,

My colleague @CindyWong attempted to reply to your inquiry, but experienced technical issues. She forwarded me her response in the meantime and I'll place it below.

 

  1. The codes you pasted are only to create a report object. In order to open the report in VA, you need to create the report content object ahead, and hook the two together. About the relationship between report object and the report content object, please see the chart in the composition of a report object in Discover Visual Analytics Report Paths with REST APIs - SAS Users.

 

  1. We can create a new report or create copy existing report using REST API. Below codes for your reference:

 

/* retrieve the report content object  from an existing report */

%let BASE_URI=%sysfunc(getoption(SERVICESBASEURL));

FILENAME rContent TEMP ENCODING='UTF-8';

PROC HTTP METHOD="GET" oauth_bearer=sas_services OUT= rContent

    URL = "&BASE_URI/reports/reports/ffb113b7-9cfa-434b-99f1-9b3fe5a9f340/content";

    HEADERS "Accept" = "application/vnd.sas.report.content+json";

RUN;

 

/* create a new report object in a folder  */

FILENAME tReport TEMP ENCODING='UTF-8';

FILENAME hdrout TEMP ENCODING='UTF-8';

PROC HTTP METHOD = "POST"

     URL = "&BASE_URI/reports/reports?parentFolderUri=/folders/folders/dbbc365c-69dc-4e3f-97c9-49818029fde1"

     OUT = tReport HEADEROUT=hdrout

     OAUTH_BEARER = SAS_SERVICES

     IN = '{

                                     "name": "Report by API",

                                     "description": "Create Report from REST API"

            }' ;

      HEADERS "Accept" = "application/vnd.sas.report+json"

                    "Content-Type" = "application/vnd.sas.report+json" ;

RUN;

 

/* print the response header, and get the value of 'ETag' and 'Last-Modified' */

data  _null_;

         infile hdrout;

         input;

         put _infile_;

run;

 

/* save the retrieved report content object to the newly created report */

/* need to replace the IF-MATCH value with the value of ‘ETag’ from previous response header */

/* need to replace the IF-UNMODIFIED-SINCE value with the value of ‘Last-Modified’ from previous response header */

PROC HTTP METHOD = "PUT"

     URL = "&BASE_URI.&rptid/content"

     OAUTH_BEARER = SAS_SERVICES

     IN = rContent ;

     HEADERS "Accept" = "*/*"

                            "Content-Type" = "application/vnd.sas.report.content+json"

                            "IF-MATCH" = """kjv0va4n"""

                            "IF-UNMODIFIED-SINCE" = "Wed, 13 Jan 2021 06:07:37 GMT"

      ;

RUN;

 

 

/* Now you should be able to open the new report in VA   */


Join us for SAS Community Trivia
SAS Bowl XXXVIII, SAS Programming: Getting Started
Wednesday, February 14, 2024, at 10 a.m. ET | #SASBowl

View solution in original post

2 REPLIES 2
joeFurbee
Community Manager

Hi @idziemianczyk,

My colleague @CindyWong attempted to reply to your inquiry, but experienced technical issues. She forwarded me her response in the meantime and I'll place it below.

 

  1. The codes you pasted are only to create a report object. In order to open the report in VA, you need to create the report content object ahead, and hook the two together. About the relationship between report object and the report content object, please see the chart in the composition of a report object in Discover Visual Analytics Report Paths with REST APIs - SAS Users.

 

  1. We can create a new report or create copy existing report using REST API. Below codes for your reference:

 

/* retrieve the report content object  from an existing report */

%let BASE_URI=%sysfunc(getoption(SERVICESBASEURL));

FILENAME rContent TEMP ENCODING='UTF-8';

PROC HTTP METHOD="GET" oauth_bearer=sas_services OUT= rContent

    URL = "&BASE_URI/reports/reports/ffb113b7-9cfa-434b-99f1-9b3fe5a9f340/content";

    HEADERS "Accept" = "application/vnd.sas.report.content+json";

RUN;

 

/* create a new report object in a folder  */

FILENAME tReport TEMP ENCODING='UTF-8';

FILENAME hdrout TEMP ENCODING='UTF-8';

PROC HTTP METHOD = "POST"

     URL = "&BASE_URI/reports/reports?parentFolderUri=/folders/folders/dbbc365c-69dc-4e3f-97c9-49818029fde1"

     OUT = tReport HEADEROUT=hdrout

     OAUTH_BEARER = SAS_SERVICES

     IN = '{

                                     "name": "Report by API",

                                     "description": "Create Report from REST API"

            }' ;

      HEADERS "Accept" = "application/vnd.sas.report+json"

                    "Content-Type" = "application/vnd.sas.report+json" ;

RUN;

 

/* print the response header, and get the value of 'ETag' and 'Last-Modified' */

data  _null_;

         infile hdrout;

         input;

         put _infile_;

run;

 

/* save the retrieved report content object to the newly created report */

/* need to replace the IF-MATCH value with the value of ‘ETag’ from previous response header */

/* need to replace the IF-UNMODIFIED-SINCE value with the value of ‘Last-Modified’ from previous response header */

PROC HTTP METHOD = "PUT"

     URL = "&BASE_URI.&rptid/content"

     OAUTH_BEARER = SAS_SERVICES

     IN = rContent ;

     HEADERS "Accept" = "*/*"

                            "Content-Type" = "application/vnd.sas.report.content+json"

                            "IF-MATCH" = """kjv0va4n"""

                            "IF-UNMODIFIED-SINCE" = "Wed, 13 Jan 2021 06:07:37 GMT"

      ;

RUN;

 

 

/* Now you should be able to open the new report in VA   */


Join us for SAS Community Trivia
SAS Bowl XXXVIII, SAS Programming: Getting Started
Wednesday, February 14, 2024, at 10 a.m. ET | #SASBowl

idziemianczyk
Obsidian | Level 7
Thank you so much.
@CindyWong @joeFurbee you made my day.

suga badge.PNGThe SAS Users Group for Administrators (SUGA) is open to all SAS administrators and architects who install, update, manage or maintain a SAS deployment. 

Join SUGA 

CLI in SAS Viya

Learn how to install the SAS Viya CLI and a few commands you may find useful in this video by SAS’ Darrell Barton.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 1054 views
  • 1 like
  • 2 in conversation