Microsoft Graph filter on subject with an ' in the subject

Tjeerd | Tel-it 20 Reputation points
2026-07-08T08:46:02.1133333+00:00

I'm trying to get emails from a users mailbox but filter on a specific subject. However this subject can contain an ' symbol.

For example:

It's Working!

I have it running fine with subjects that do not containt his symbol however when it does contain it, I get a bad request error.

I think it has to do with the fact that the filter is like subject eq 'It's Working!'. I've tried encoding it for an Url, however this doesn't work.

Can anyone help me with this?

Thanks in advance!

Microsoft 365 and Office | Development | Other
0 comments No comments

Answer accepted by question author
Michelle-N 20,735 Reputation points Microsoft External Staff Moderator
2026-07-08T09:37:03.4366667+00:00

Hi @Tjeerd | Tel-it

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.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.