MS graph does not return body of message (other fields like subject, from is returned).

Martin Koch 5 Reputation points
2024-02-09T08:52:01.9666667+00:00

The query returns all other data of the message except the body-tag. My application has mail.readwrite authorization.




message_id = "<removed>"
user_email = "<removed>"
access_token = "<removed>"

headers = {
    "Authorization": f"Bearer {access_token}"
}

def get_message_details(message_id):
    message_url = f"https://graph.microsoft.com/v1.0/users/{user_email}/messages/{message_id}"
    query_parameters = {"$select": "from,subject,body"}
    response = requests.get(message_url, headers=headers, params=query_parameters)

    if response.status_code == 200:
        data = response.json()
        return data
    else:
        return None
    

result = get_message_details(message_id)
print(json.dumps(result, indent=4))


Output:

{ "@odata.context": "<removed>", 
     "@odata.etag": "<removed>",
    "id": "<removed>", 
    "subject": "Do Taylor Swift and Travis Kelce have blogs on Podia?", 
   "from": { "emailAddress": { "name": "Spencer from Podia", "address": "create@podia.com" } } }

I have also tried selecting all fields ("*") and still no message body...

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,003 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Martin Koch 5 Reputation points
    2024-02-09T13:44:37.6066667+00:00

    I deleted and re-added the permission to MS Graph and re-generated the client secret. Behold now it works (and now I know the truth about the blog 🤩) For some reason i only got BasicRead rights and that does not show the body-part of the messages.

    1 person found this answer helpful.
    0 comments No comments