How to download MS Teams Chats messages attachments using Graph API with the token created against client credentials flow on behalf of all users?

Anns 61 Reputation points

I have a script to scan MS Teams signed-in user's attachments from the user's chats. I was using authorization flow to access the files using the following URL:
" Teams Chat Files/{}"
Now, I have upgraded my integration method and set up the client credentials flow. For this, I am unable to fetch attachments and couldn't find any URL that will be helpful in downloading my file.
I have tried 'contentUrl' from the message response but didn't get any results.

{   'id': 'a54b09c98-f0va-46c2-b3f7e-5daef19213f3',   'contentType': 'reference',   'contentUrl': ' Teams Chat Files/file.ppt',   'content': None,   'name': 'file.ppt',   'thumbnailUrl': None,   'teamsAppId': None }
Microsoft Teams
Microsoft Teams
A Microsoft customizable chat-based workspace.
8,153 questions
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
9,166 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
17,599 questions
{count} votes