Using Graph API, how to filter events whose subject does not contain a specific string?

Aravind Pai 0 Reputation points
2023-02-09T04:23:31.2733333+00:00

Hello everyone,
I want to use the Graph API to filter events from the Outlook calendar, which do NOT contain a specific string in the subject line.
I followed the following documentation:

I created the following query:

https://graph.microsoft.com/v1.0/me/events?$filter=not(contains(subject, 'HOST'))&select=subject,start/dateTime,end/dateTime,onlineMeeting/joinUrl&$count=true

In the request header, I set ConsistencyLevel to eventual as specified in the advanced query documentation.

However, this doesn't work and gives the following error:

{
    "error": {
        "code": "ErrorInternalServerError",
        "message": "An internal server error occurred. The operation failed.",
        "innerError": {
            "date": "2023-02-09T04:11:01",
            "request-id": "a0781ad4-0aac-4774-a30a-15f9a88596aa",
            "client-request-id": "8b988658-0166-b9a8-812d-88413dc01b6f"
        }
    }
}

I couldn't figure out what is wrong with my query. Could someone kindly explain and help me to achieve this?

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,282 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. CarlZhao-MSFT 42,526 Reputation points
    2023-02-10T07:35:32.75+00:00

    Hi @Aravind Pai

    The $filter query parameters don't yet support not and contains combined, but you can try using code filtering, which I've tested locally and it works perfectly.

    var events = await graphClient.Me.Events
          .Request()
          .Select("subject,start,end,onlineMeeting")
          .GetAsync();
    
    foreach (var e in events) {
     
          if (!e.Subject.Contains("HOST")) {
     
                Console.WriteLine(JsonConvert.SerializeObject(e)); 
          } 
    }
    

    By the way, $select query parameters are only used to return the properties of the event, not to return the children of the event properties.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".


Your answer

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