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
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:
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 XLIII, The New SAS Developer Portal
Wednesday, August 14, 2024, at 10 a.m. ET | #SASBowl
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 XLIII, The New SAS Developer Portal
Wednesday, August 14, 2024, at 10 a.m. ET | #SASBowl
thanks Joe!
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:
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 XLIII, The New SAS Developer Portal
Wednesday, August 14, 2024, at 10 a.m. ET | #SASBowl
Hi Joe,
This is exactly what I was looking for. And thanks to your reply on my other
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 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.