Announcing the Saviynt Knowledge Exchange unifying the Saviynt forums, documentation, training,
and more in a single search tool across platforms. Read the announcement here.

Import Azure AD User by using filter on lastcreatedDateTime

JPMac
Regular Contributor
Regular Contributor

I am importing users from Azure AD.

I only want to import users whose createdDatetime is less than 24 hours from the current time.

JPMac_0-1707823695519.png

 

GET

https://graph.microsoft.com/v1.0/users?$select=id,userPrincipalName,accountEnabled,mail,userType,cre...


How can I apply a filter according to the above requirements?

6 REPLIES 6

JPMac
Regular Contributor
Regular Contributor

I know I can filter like this, but I want "202024-02-13 T00:00:00.000Z" to pull the current time automatically and within 24 hours.

https://graph.microsoft.com/v1.0/users?$select=id,userPrincipalName,displayName,mail,accountEnabled,...

AmitM
Valued Contributor
Valued Contributor

Hi @JPMac , this question deserves Microsoft forum. But in my knowledge MS graph API filter does not support dynamic dates.

Also not sure why you wan to only import last 24 hr users only , is it because user import from AAD doesn't support incremental import?

Better to raise an Idea for that - https://ideas.saviynt.com/ideas

As a workaround, you can ask Azure to update an attribute as 'New User' when created and you can use filter to query that. And later make the attribute null using update account json. Or Azure team can do. 

Thanks,

Amit

If it helped you , please ACCEPT SOLUTION and close thread.

GET https://graph.microsoft.com/v1.0/users?
$select=id,userPrincipalName,accountEnabled,mail,userType,createdDateTime
$filter=createdDateTime ge {{startDateTime}}

You can calculate date refer below posts 

Sample URL format: https://<url>?%24format=json&%24filter=status%20in%20%27t%27,%27f%27&fromDate=${(new Date()).format('yyyy-MM-dd'T'HH:mm:ss'Z')}


Regards,
Rushikesh Vartak
If you find the response useful, kindly consider selecting Accept As Solution and clicking on the kudos button.

JPMac
Regular Contributor
Regular Contributor

@rushikeshvartak 

Thanks for your comment.

I check below command.

https://graph.microsoft.com/v1.0/users?$select=id,userPrincipalName,displayName,mail,accountEnabled,...{(new Date()).format('yyyy-MM-dd'T'HH:mm:ss'Z')}

However, an error was returned.

===

{
    "error": {
        "code": "BadRequest",
        "message": "Parsing OData Select and Expand failed: Term 'id,userPrincipalName,displayName,mail,accountEnabled,createdDatetime?$format=json' is not valid in a $select or $expand expression.",
        "innerError": {
            "date": "2024-02-14T11:47:08",
            "request-id": "9cd5c8f4-cd24-4386-b018-b4cbaffa24e4",
            "client-request-id": "9cd5c8f4-cd24-4386-b018-b4cbaffa24e4"
        }
    }
}
===
 
JPMac_0-1707911337942.png

Is my confirmation way correct? Please share the URL to be executed again.

GET https://graph.microsoft.com/v1.0/users?
$select=id,userPrincipalName,accountEnabled,mail,userType,createdDateTime
$filter=createdDateTime ge 2023-01-01T00:00:00Z


Regards,
Rushikesh Vartak
If you find the response useful, kindly consider selecting Accept As Solution and clicking on the kudos button.

marco
Saviynt Employee
Saviynt Employee

You can do this in ImportUserJSON REST connector.

{
"connection": "userAuth",
"url": "https://graph.microsoft.com/v1.0/users?\\$select=accountEnabled,displayName,id,userPrincipalName,userType,givenName,surname,mailNickname,createdDateTime&\\$filter=createdDateTime+ge+${java.time.format.DateTimeFormatter dtf = java.time.format.DateTimeFormatter.ofPattern(\"yyyy-MM-dd'T'HH:mm:ss'Z'\");java.time.LocalDateTime now = java.time.LocalDateTime.now();return dtf.format(now.minusDays(1))}",
"httpMethod": "GET",
"httpHeaders": {
"contentType": "application/json",
"Authorization": "${access_token}"
},
"colsToPropsMap": {
"username": "userPrincipalName~#~char"
},
"errorCode": "401",
"errorCodePath": "errorCode",
"userResponsePath": "",
"successResponses": {
"statusCode": [
200
]
}
}