Microsoft Graph Rest API - Filter by last X days

Viewed 34

I have a rest URL that I am running against Microsoft Graph via POSTMAN and I'd like to know how to make the date filter check for records with activity in the last 90 days. My URL is this:

https://graph.microsoft.com/beta/users?$select=signInActivity&$filter=signInActivity/lastSignInDateTime%20le%202022-09-01

I do not want to use the hard-coded date like in this example or have to lean on something like powershell. Is there a way to calculate the date in the url or to tell the filter to do so? Something like this would be nice:

https://graph.microsoft.com/beta/users?$select=signInActivity&$filter=signInActivity/lastSignInDateTime%20le%20(today()-days(90))
1 Answers

Graph API does not support functions for working with date.

You can declare a property in Postman and set the property before the request is sent.

Example

The Graph API request is in a Postman collection. You can create a collection variable MyVar and use the variable in $filter query.

enter image description here

Then you can write a pre-request script in JavaScript and set the collection variable.

let d = new Date();
d.setDate(d.getDate()-90);
pm.collectionVariables.set("MyVar", d.toISOString().split('T')[0]);

enter image description here

Send the request and check console how the request looks like.

enter image description here

Resources:

Filter query operators

Related