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

Hello all, 

 

I want to create a report listing all reports created in VA 8.3 and the related CAS data tables.

 

I am assuming I need to use the RESI API for this, specifically the relationships call. https://developer.sas.com/apis/rest/CoreServices/#relationships

 

However before I begin, perhaps I am missing a more obvious way to create such a report. Has anyone created such a report? 

 

kind regards, 

 

Richard

 

1 ACCEPTED SOLUTION

Accepted Solutions
joeFurbee
Community Manager

Hi @RichardP. Sorry for the delay. Also, I apologize in advance if I made assumptions in this response. If you need further info, please reach out.

 

Using the relationships API in combination with the reports API seems to be the way to go. I'll explain what I did and provide the code I used. Hopefully, it will give you enough info to go on. All of the APIs I used are documented here. 

 

I used the following API call to get a list of relationships:

curl --location --request GET 'http://sasserver.demo.sas.com/relationships/relationships \
--header 'Accept: application/vnd.sas.collection+json' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer ........'

In the response, I see the following:

    "name""items",
    "accept""application/vnd.sas.relationship",
    "start"0,
    "count"547,
    "items": [
This indicates that there are 547 relationships. Be aware that the default limit is 20 for the REST call, so I tacked on a limit to the url > count: curl --location --request GET 'http://sasserver.demo.sas.com/relationships/relationships?limit=1000

 

This made me think though that 547 is a lot more than the number of reports I had created. Also, the report name is not in the response, only the id. I then ran a request to get a list of reports:

curl --location --request GET 'http://sasserver.demo.sas.com/reports/reports' \
--header 'Authorization: Bearer ........'

and got the response:

 

"name": "reports",
"accept": "application/vnd.sas.summary",
"start": 0,
"count": 24,
"items": [

 

This a much more manageable number. At this point, I thought it better to get the reports first and then get the relationship based on this query. Now, I have a plethora of options to merge the results. What I decided to do was to convert the JSON responses to a csv files. Again, I have many options on scrubbing/combining the data. I used the following Python script to get a csv file with report id and name:

import json
import csv
with open('C:/Users/jofurb/reportsResponse.json','r') as myfile:
    response_data=myfile.read()
response_parsed = json.loads(response_data)
resp_data = response_parsed['items']
respon_data = open('C:/Users/jofurb/reportsResponseData.csv','w')
csvwriter= csv.writer(respon_data)
count=0
for resp in resp_data:
    if count == 0:
        header = resp.keys()
        csvwriter.writerow(header)
        count += 1
    csvwriter.writerow(resp.values())
respon_data.close()

I could then use that data along with the relationships response JSON to combine the data into a dataset I can use for the report.

 

I hope this helps,

Joe


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

4 REPLIES 4
joeFurbee
Community Manager

Hi @RichardP, I'm setting up an env to test this out and talk to a couple of colleagues to see if there is a recommendation for this. I'll get back to you as soon as I complete the analysis.


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

RichardP
Quartz | Level 8

thanks Joe!

joeFurbee
Community Manager

Hi @RichardP. Sorry for the delay. Also, I apologize in advance if I made assumptions in this response. If you need further info, please reach out.

 

Using the relationships API in combination with the reports API seems to be the way to go. I'll explain what I did and provide the code I used. Hopefully, it will give you enough info to go on. All of the APIs I used are documented here. 

 

I used the following API call to get a list of relationships:

curl --location --request GET 'http://sasserver.demo.sas.com/relationships/relationships \
--header 'Accept: application/vnd.sas.collection+json' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer ........'

In the response, I see the following:

    "name""items",
    "accept""application/vnd.sas.relationship",
    "start"0,
    "count"547,
    "items": [
This indicates that there are 547 relationships. Be aware that the default limit is 20 for the REST call, so I tacked on a limit to the url > count: curl --location --request GET 'http://sasserver.demo.sas.com/relationships/relationships?limit=1000

 

This made me think though that 547 is a lot more than the number of reports I had created. Also, the report name is not in the response, only the id. I then ran a request to get a list of reports:

curl --location --request GET 'http://sasserver.demo.sas.com/reports/reports' \
--header 'Authorization: Bearer ........'

and got the response:

 

"name": "reports",
"accept": "application/vnd.sas.summary",
"start": 0,
"count": 24,
"items": [

 

This a much more manageable number. At this point, I thought it better to get the reports first and then get the relationship based on this query. Now, I have a plethora of options to merge the results. What I decided to do was to convert the JSON responses to a csv files. Again, I have many options on scrubbing/combining the data. I used the following Python script to get a csv file with report id and name:

import json
import csv
with open('C:/Users/jofurb/reportsResponse.json','r') as myfile:
    response_data=myfile.read()
response_parsed = json.loads(response_data)
resp_data = response_parsed['items']
respon_data = open('C:/Users/jofurb/reportsResponseData.csv','w')
csvwriter= csv.writer(respon_data)
count=0
for resp in resp_data:
    if count == 0:
        header = resp.keys()
        csvwriter.writerow(header)
        count += 1
    csvwriter.writerow(resp.values())
respon_data.close()

I could then use that data along with the relationships response JSON to combine the data into a dataset I can use for the report.

 

I hope this helps,

Joe


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

RichardP
Quartz | Level 8

Hi Joe, 

 

This is exactly what I was looking for. And thanks to your reply on my other

 

question https://communities.sas.com/t5/Developers/Translating-cURL-command-to-equivalent-PROC-HTTP-statement...

I am now able to do this directly in SAS Studio and ready the JSON response directly into a SAS data. 

 

You provided the magic tip - LIMIT= option. I was aware of the relationships API but could not see my report anywhere, this was due to the limit=20!

 

many thanks ,

 

Richard

 

 

 

 

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1366 views
  • 2 likes
  • 2 in conversation