Forum Discussion
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.HTTPError: 400 Client Error: Bad Request for url: https://api.powerbi.com/v1.0/myorg/admin/activityevents?startDateTime='2026-02-13T00:00:00.000Z'&endDateTime='2026-02-14T00:00:00.000Z'
What is wrong with this request?
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')}'"
1 Reply
- LittleMarie_MTFrequent 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')}'"