Automate teams user activity report using python SDK

manoj kumar v 0 Reputation points
2023-09-05T16:31:33.9566667+00:00
Hello Everyone, 

      I have a problem: I need to automate the extraction of team user activity reports from the team admin center and store data needs to be S3 bucket in CSV format with the help of aws lambda funtion. For this, I have done app registration and with the help of Python SDK along with client secret, client id and tenant id, I was trying to automate the process. But I'm getting the below mentioned error.

Error Message: 

msgraph.generated.models.o_data_errors.o_data_error.ODataError: APIError 404: None MainError(additional_data={}, code='UnknownError', details=None, inner_error=InnerError(additional_data={'date': datetime.timedelta(seconds=46105)}, client_request_id=6aabfa3e', date=None, odata_type=None, request_id='c5b7ff119'), message='{"error":{"code":"InvalidArgument","message":"The requested function cannot be found."}}', target=None)

The code which I'm was using:

import asyncio
from azure.identity import DeviceCodeCredential
from msgraph import GraphServiceClient

scopes = ['Reports.Read.All']
tenant_id = 'Value from App registration'
client_id = 'Value from App registration'
client_secret = 'Value from App registration'

# azure.identity.aio
credential = DeviceCodeCredential(tenant_id=tenant_id, client_id=client_id, client_secret=client_secret)

graph_client = GraphServiceClient(credential, scopes)


async def get_reports():
    await graph_client.reports.get_teams_user_activity_user_detail_with_period(period='D7').get()
asyncio.run(get_reports())


Can anyone please help with the solution?
Thanks in Advance!
Manoj
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,007 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.