How to get transcript content with Graph Service Client

Nyan Cat 25 Reputation points
2025-01-22T14:50:05.6766667+00:00

Hello,

I am trying to get transcript content through Graph API using Graph Service Client in Python SDK, but I get this error "Invalid format 'application/octet-stream, application/json' specified."

How can I add custom headers to the API call?

Thanks!

graph_client.users.by_user_id(user_id).online_meetings.by_online_meeting_id(
    online_meeting_id).transcripts.by_call_transcript_id(transcript_id).content.get()
Microsoft Teams Development
Microsoft Security Microsoft Graph
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Anonymous
    2025-01-23T02:47:12.33+00:00

    Hello Nyan Cat,

    Thank you for reaching out to Microsoft Support!

    Please try the following code:

    # Define the custom headers
    config = RequestConfiguration()
    config.headers.add('Prefer', 'Content-Type="application/json"')
    
    # Make the API call with custom headers
    response = await graph_client.users.by_user_id('user-id').online_meetings.by_online_meeting_id('onlineMeeting-id').transcripts.by_call_transcript_id('callTranscript-id').content.get(config)
    

    Reference document:

    https://learn.microsoft.com/en-us/graph/api/calltranscript-get?view=graph-rest-1.0&tabs=python

    https://learn.microsoft.com/en-us/graph/sdks/create-requests?tabs=python#use-http-headers-to-control-request-behavior

    Hope this helps.

    If the answer is helpful, please click Accept Answer and kindly upvote it. If you have any further questions about this answer, please click Comment.


  2. Anonymous
    2025-01-27T09:53:46.8666667+00:00

    Hello @Nyan Cat,

    I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this! Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to "Accept " the answer.

    Issue: When using the Graph Service Client in the Python SDK to get transcript content through the Graph API, How can I add custom headers to the API call?

    Solution: Resolved by @Nyan Cat, following the below steps.

    Using access tokens in the code instead of graphical clients solves this problem.

    headers = {"Authorization": f"Bearer {access_token}", "Accept": "text/vtt"}
    url = (f"https://graph.microsoft.com/v1.0/users/{user_id}/onlineMeetings/{online_meeting_id}/transcripts/{transcript_id}/content")
    response = requests.get(url, headers=headers, stream=True)
    with open(file_name, "wb") as f:
    	for chunk in response.iter_content(chunk_size=8192):
        	if chunk:
            	f.write(chunk)
    

    If you have any other questions or are still running into more issues, please let me know. Thank you again for your time and patience throughout this issue.

    Please remember to "Accept Answer" if any answer/reply helped, so that others in the community facing similar issues can easily find the solution.

    Thanks, Yakun Huang.

    0 comments No comments

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.