Microsoft Graph API - unterminated string literal Error when searching for emails which contain # in the subject

1.1k views Asked by At

When i am searching for emails on office 365 in a batch query, i am getting a unterminated string literal error. This is happening only when i have a # character in the subject search query.

Forum discussions like this (https://issues.oasis-open.org/browse/ODATA-1101) have suggested me to percentage encode the # symbol but it gave the same error.

When I am POSTing the below request to the batch endpoint(https://graph.microsoft.com/v1.0/$batch)

{
    "requests": [{
        "id": 1,
        "method": "GET",
        "url": "/users/[email protected]/messages?$select=id,internetMessageId,toRecipients,ccRecipients,bccRecipients,subject,isRead,sender,receivedDateTime&$top=500&$search=\"received>=2019-06-19 AND (subject:\\\"PO# 123\\\" AND from:[email protected])\""
    }]
}

I get this error

{
  "responses": [
    {
      "id": "1",
      "status": 400,
      "body": {
        "error": {
          "code": "BadRequest",
          "message": "There is an unterminated string literal at position 39 in '\"received>=2019-06-19 AND (subject:\\\"PO'.",
          "innerError": {
            "request-id": "801078a5-d3c6-4b93-a152-6653a3d8ca44",
            "date": "2019-07-22T06:29:16"
          }
        }
      }
    }
  ]
}

Can you guys please help me with fixing my search query?

Thanks, Ashish

1

There are 1 answers

0
Brad On

The # character is used to delimit fragments in a URL, which are intended to represent client side state. Browsers will generally not send the # or anything following it, and servers will generally ignore it if it's sent accidently.

Your issue is most likely an encoding one - depending on how you're encoding the query string the # might be getting left alone, when in actuality you want it to be encoded to %23.