According to the Graph API documentation, you can list all messages from a logged-in user through the /messages
endpoint, which returns information about all messages, including the ID of the message, and the endpoint also supports OData query parameters, which helps you filter out the ID of the message you need more quickly.
Below is the result of my test, which uses the $filter query parameter to filter messages by subject.
Hope this helps.
If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.