Forum Discussion
LittleMarie_MT
5 months agoFrequent Visitor
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url
Trying to collect activity data from the cloud following instructions here https://learn.microsoft.com/en-us/rest/api/power-bi/admin/get-activity-events, keep getting this error: requests.exceptions...
- 5 months ago
Solution found. Here are correct date formats accepted by API:
#Set Power BI REST API to get Activities for today url = "https://api.powerbi.com/v1.0/myorg/admin/activityevents?startDateTime='" + activityDate + "T00:00:00'&endDateTime='" + activityDate + "T23:59:59'"
(found in this post: https://community.fabric.microsoft.com/t5/Developer/Power-BI-Get-Activity-REST-API/m-p/3564225)
Or alternatevely the following transformations helped to achieve the proper date:
day = datetime.utcnow().date() - timedelta(days=1)day = datetime.combine(day, datetime.min.time())start_of_day = datetime(day.year, day_utc.month, day_utc.day, 0, 0, 0)start_param = f"'{start_of_day .strftime('%Y-%m-%dT%H:%M:%SZ')}'"
LittleMarie_MT
5 months agoFrequent Visitor
Solution found. Here are correct date formats accepted by API:
#Set Power BI REST API to get Activities for today url = "https://api.powerbi.com/v1.0/myorg/admin/activityevents?startDateTime='" + activityDate + "T00:00:00'&endDateTime='" + activityDate + "T23:59:59'"
(found in this post: https://community.fabric.microsoft.com/t5/Developer/Power-BI-Get-Activity-REST-API/m-p/3564225)
Or alternatevely the following transformations helped to achieve the proper date:
day = datetime.utcnow().date() - timedelta(days=1)
day = datetime.combine(day, datetime.min.time())
start_of_day = datetime(day.year, day_utc.month, day_utc.day, 0, 0, 0)
start_param = f"'{start_of_day .strftime('%Y-%m-%dT%H:%M:%SZ')}'"