Building custom solutions that extend, automate, and integrate Microsoft 365 apps.
Based on the information you provided, I understand that you are running into a 400 Bad Request error when trying to retrieve emails from a user's mailbox via the Microsoft Graph API. The issue specifically occurs when filtering messages by a subject that contains a single quote or apostrophe (like "It's Working!"), because the single quote prematurely breaks the OData string literal syntax in your $filter query parameter (subject eq 'It's Working!').
After looking into this, the correct approach for the Microsoft Graph $filter parameter is not to simply URL encode the single quote right away. Instead, you need to escape the single quote by doubling it inside the OData string value first.
The official Microsoft Graph documentation for query parameters states that when a string value is enclosed in single quotes and the value itself contains a single quote, that internal quote must be escaped by using two consecutive single quotes (''). Once the string is properly escaped, the entire query parameter value should then be percent-encoded (URL encoded) according to RFC 3986 before sending the final HTTP request.
Please refer to the following guide and documentation details:
Use the $filter query parameter
Use this:
GET https://graph.microsoft.com/v1.0/users/{user-id}/messages?$filter=subject eq 'It''s Working!'
If you are building or viewing the raw URL manually, the final percent-encoded URL string sent over the wire should look like this (notice the %27%27 representing the two escaped single quotes):
GET https://graph.microsoft.com/v1.0/users/{user-id}/messages?$filter=subject%20eq%20%27It%27%27s%20Working!%27
By escaping the apostrophe as '' before the URL encoding step, Microsoft Graph will correctly parse the complete phrase as a single text string and return your filtered emails without throwing a Bad Request error.
Hope this helps resolve the error.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click ""Comment"".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.