Forum Discussion
SnoekLaurens
1 year agoAdvocate I
Notebook semantic link (sempy) extract report usage
Hi, does anyone know if there is a way to use Python semantic link package to extract report usage form all reports that are in a workspace or connected to a certain shared dataset in power bi Servic...
- 1 year ago
Already found it 🙂
This works for me:
import sempy.fabric as fabricimport jsonmethod = 'GET'start_time = "'2024-12-11T00:55:00.000Z'"end_time = "'2024-12-11T12:00:00.000Z'"filter = "$filter=Activity eq 'viewreport'"query = '&'.join(['startDateTime='+start_time,'endDateTime='+end_time,filter])full_url = url + '?' + queryclient = fabric.PowerBIRestClient()def get_activity_events(url😞response = client.request(method, url)data = response.json()# Process the current batch of eventsevents = data.get('activityEventEntities', [])# Check for continuationcontinuation_uri = data.get('continuationUri')while continuation_uri:response = client.request(method, continuation_uri)data = response.json()events.extend(data.get('activityEventEntities', []))continuation_uri = data.get('continuationUri')return eventsevents = get_activity_events(full_url)print(json.dumps(events, indent=4))
SnoekLaurens
1 year agoAdvocate I
Hi spencer_sa,
I got the data from the tables you adviced and loaded them into my lakehouse.
Now next step is to understand how I can get the report usage from that data. Should these be specific items? I guess it would only work if the reports are also in a workspace with fabric capacity?
spencer_sa
1 year agoImpactful Individual
Ahh, I see you're after geting the report usage;
I've succeeded doing this with the following;
import sempy.fabric as fabric
import json
method = 'GET'
url = 'https://api.powerbi.com/v1.0/myorg/admin/activityevents'
start_time = "'2024-12-11T00:55:00.000Z'"
end_time = "'2024-12-11T12:00:00.000Z'"
filter = "$filter=Activity eq 'viewreport'"
query = '&'.join(['startDateTime='+start_time,'endDateTime='+end_time,filter])
full_url = url + '?' + query
client = fabric.PowerBIRestClient()
response = client.request(method, full_url)
print(json.dumps(json.loads(response.content), indent=2))