web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Office 365 Connector -...
Power Automate
Unanswered

Office 365 Connector - Get Emails (v3): Search parameter

(1) ShareShare
ReportReport
Posted on by 25
I'm seeking clarity on the rules for the search query parameter in the Office 365 Connector - Get Emails (v3)
 
It strikes me there's a bug here in the connector, as if the developer hasn't implemented escaping properly.
 
In the editor I would expect to be able to put a KQL search query, as per the supporting documentation https://learn.microsoft.com/en-us/graph/search-query-parameter 
 
e.g.
subject:"hello world"
 
However, as may people see, this returns an "unexpected character" warning for the double quotes.
I've seen recommendations to use single quotes, however that simply doesn't work in the intended way.
 
Looking at the json, double quotes are correctly escaped, so it's not the editor at fault:
 
{
  "type": "OpenApiConnection",
  "inputs": {
    "parameters": {
      "importance": "Any",
      "folderPath": "Inbox",
      "fetchOnlyUnread": false,
      "includeAttachments": false,
      "searchQuery": "subject:\"hello world\"",
      "top": 25
    },
    "host": {
      "apiId": "/providers/Microsoft.PowerApps/apis/shared_office365",
      "connection": "shared_office365",
      "operationId": "GetEmailsV3"
    }
  },
  "runAfter": {}
}
So the connector should have no problem seeing the search query has the value 
subject:"hello world"
In theory, it should then be able to prepare the API request correctly from this parameter, escaping the values as required, e.g. for a url as per https://learn.microsoft.com/en-us/graph/search-query-parameter?tabs=http:
(note rigorous url encoding of space colon and backslash not shown)
 
However, in practice you get a 400:
 
{
  "status": 400,
  "message": "Syntax error: character '\"' is not valid at position 21 in '\"subject:\"Hello world\"\"'.\r\nclientRequestId: a08f1c39-a11f-4a2c-99a3-3b9e8aa4435e\r\nserviceRequestId: a1097faa-735f-4af9-bd34-c289483c17b6",
  "error": {
    "message": "Syntax error: character '\"' is not valid at position 21 in '\"subject:\"Hello world\"\"'.",
    "code": "BadRequest",
    "originalMessage": "Syntax error: character '\"' is not valid at position 21 in '\"subject:\"Hello world\"\"'."
  },
  "source": "office365-ne.azconn-ne-003.p.azurewebsites.net"
}
i.e. it's seeing 
"subject:"Hello world""
 
In order to get this to work one has to escape the " character with a backslash manually in the editor, which results in an doubly-encoded searchQuery:
 
"searchQuery": "subject:\\\"hello world\\\"",
This strikes me that the search query is not being encoded at all on the way out - instead it is being wrapped with double quotes with no concern for escaping quotes or encoding characters.
I'm concluding the implementation is using a HTTP interface, as putting in a query that breaks URL encoding rules returns a 400 too, indicating no URL encoding is going on at all either.
 
e.g.
If I use
searchQuery:&
I get the error
{
  "status": 400,
  "message": "There is an unterminated string literal at position 9 in '\"subject:'.\r\nclientRequestId: e17bdda4-b56e-4bd9-96b9-85a7ed212098\r\nserviceRequestId: 9636df8b-d65b-4e45-aeea-fb48da796a5b",
  "error": {
    "message": "There is an unterminated string literal at position 9 in '\"subject:'.",
    "code": "BadRequest",
    "originalMessage": "There is an unterminated string literal at position 9 in '\"subject:'."
  },
  "source": "office365-ne.azconn-ne-003.p.azurewebsites.net"
}
 
Which indicates it was probably naievly sent through unencoded as
 
So:
 
1. Is this a bug? It looks like a junior developer hasn't been guided properly around encoding.
 
2. If we do have to painfully escape our own values - these are completely dependent on the implementation: can we have some guarantee the implementation will stay with HTTP, and we can refer to https://learn.microsoft.com/en-us/graph/search-query-parameter?tabs=http:
 
3. Can you escape it properly in GetEmailsV4 so we're not doing the developer's work please!
 
Categories:
I have the same question (0)
  • Expiscornovus Profile Picture
    33,189 Most Valuable Professional on at
     
    This might be a small typo? Subject is not a parameter, it is part of the value you are searching for with the $search query parameter. As far as I know the quotes should be around the whole search query (including the searchable email property you are searching within).
     
    So, your example for a Graph API call would be:
    "subject:hello world"
     
    Microsoft has also shared a sample for the subject searchable email property in their documentation. As you can see in the example they also place the double quotes around "subject:has"
    ../me/messages?$search="subject:has"&$select=subject
     
    In case of the GetEmailsV4 the below should also work (without any quotes at all).
     
  • AA-13011050-0 Profile Picture
    4 on at
    Thanks for your interest Expiscornovus 
     
    Fundamentally, the only way to reliably use search in v3 is to assume that it has been coded as just putting double quotes around the search parameter with no escaping.
     
    Indeed as you say, you put have to quotes around the whole $search parameter, which is what the Get Email step is responsible for doing ... but it does it naively, resulting in problems. This is not something we have control of when editing the flow.
     
    As for your suggestion of doing this without any quotes - the query is sent as
    $search="subject:hello world"
    which does indeed work for simple single-term searches.
    However this question is the result of trying to pass more complex multi-term searches.
     
     
     
     
     
  • Expiscornovus Profile Picture
    33,189 Most Valuable Professional on at
     
    Can you clarify what you mean with complex type of multi-term searches? Do you mean you want to search for multiple keywords in one search query (separately)? So, in the example you find matches for both the hello and world keywords individually? 

    If that is the case try using OR or AND operators in your query.
     
    subject:hello OR subject:world
     
    Or do you mean you cannot search for special characters in the subject field, like the double quote character?

  • AA-13011050-0 Profile Picture
    4 on at
    I'm not quite sure what your're refering to re a typo - we're talking about the searchQuery parameter on the Get Emails v3 connector.
    I appreciate that right now that gets sent through as a $search parameter in an HTTP GET query to ms graph/odata by the connector, but that implementation's not directly controllable by us as it's microsoft's connector.
     
    Re more complex queries: the $search parameter supports a KQL syntax - informally documented for sharepoint here (can't find a link to outlook or a rigorous spec unfortuantely, hence this question)
     
    The query that triggered this exploration was just a simple search for a few different multi-word strings. Using unquoted or using single quotes rather than double quotes doesn't seem to work correctly.
    e.g. given two emails one with subject hello world, and another with the subject hallo wereld, the searchQuery:
    subject:'hello world' OR subject:'hallo wereld'
    only retrieves hallo wereld, as does searchQuery:
    subject:hello world OR subject:hallo wereld
    whereas searchQuery following the KQL guidance using double quotes, but additionally escaping manually:
    subject:\"hello world\" OR subject:\"hallo wereld\"
    works as expected, finding both.
     
    Having a simple rule about how to escape/enode this KQL grammar makes it fully usable, rather than having to know which parts of the grammar work without escaping. Right now it's entirely possible although inconvenient to apply the rule manually to the searchQuery parameter. 
     
    Also my note about GetEmails v4 was referring to what I would like in a hypothetical next version of this connector, we're currently on v3 unless you know something different! Naturally one wouldn't make breaking changes to an existing published connector.
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 522 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 364 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard