Search code examples
emailfiltermicrosoft-graph-apiwildcard

Use wildcard for graph API Microsoft with $filter


During a Microsoft graph API call, I'm looking to retrieve an email from its subject with the following python code: f"$filter=subject eq '{subject}'"

The problem is that the filter separator <<'>> is present in the subject, the variable <<subject>>.

So I'm looking to replace the <<'>> with wildcard to keep the current method.

I tried replacing the <<'>> with <<">>, but the filter doesn't work with them, it absolutely needs <<'>>.


Solution

  • You need to duplicate a single quote ' which is present in the subject

    subject = subject.replace("'","''")
    f"$filter=subject eq '{subject}'"
    

    It will ensure that a single quote is escaped