Home > Software engineering >  How do we filter the signin activity based on email address using graph?
How do we filter the signin activity based on email address using graph?

Time:06-03

I am using below graph API

https://graph.microsoft.com/beta/users?$select=id,mail,displayName,signInActivity

this returns data as shown below

"value": [
    {
        "mail": "[email protected]",
        "displayName": "Jhon Jhon",
        "id": "2a0e34d5-ca90-4500-9f09-efc23c33a2c7",
        "signInActivity": {
            "lastSignInDateTime": "2021-08-03T06:32:39Z",
            "lastSignInRequestId": "c11dbf8a-11e3-1111-96c4-114f7252d700",
            "lastNonInteractiveSignInDateTime": "2021-08-03T06:30:43Z",
            "lastNonInteractiveSignInRequestId": "11111bb0-8550-4ece-12f5-0b11a50ad100"
        }
    },

But it has more than 10k records and among them around 7k records does not have signInActivity. So how can I fetch only those records which has 'signInActivity' and also based on 'mail'

I tried below, but does not work.

 https://graph.microsoft.com/beta/users?$select=id,mail,displayName,signInActivity$filter=mail eq '[email protected]'

error

  {
"error": {
    "code": "BadRequest",
    "message": "Parsing OData Select and Expand failed: Term 'id,mail,displayName,signInActivity$filter=mail eq '[email protected]'' is not valid in a $select or $expand expression.",
    "innerError": {
        "date": "2022-06-01T14:12:08",
        "request-id": "c88f2dc4-16f6-47cb-b4e2-44be451b2e06",
        "client-request-id": "c88f2dc4-16f6-47cb-b4e2-44be451b2e06"
    }
}

}

CodePudding user response:

You have to use & (ampersand) before $filter to separate query parameters select and filter.

https://graph.microsoft.com/beta/users?$select=id,mail,displayName,signInActivity&$filter=mail eq '[email protected]'
  • Related