Can't fetch user count correctly after creating user with GraphAPI

Rohan Kumar 21 Reputation points
2022-07-07T10:30:06.55+00:00

request
GET https://graph.microsoft.com/v1.0/users?$filter=(userPrincipalName eq '******@xyz.com')&$count=true

header
ConsistencyLevel : eventual

As I was testing the graphAPI, I encountered this strange behavior. I was getting count : 0, seconds after creating user ******@xyz.com using the above given request. This is strange because user has been created but is not being reflected. After few seconds however, the same request is reflecting the user and user count correctly.

  • Why is there a time delay between creating and fetching user with count parameter?
  • How much is this time delay exactly?
  • Is this happening because of ConsistencyLevel : eventual ?

I have attached images of the same behavior below.

Created User
218495-created.png

Got Count after few seconds of creation
218523-count1.png

Works fine again after some time.
218478-count2.png

Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

Answer accepted by question author
  1. Vasil Michev 123.7K Reputation points MVP Volunteer Moderator
    2022-07-07T10:49:35.623+00:00

    That's very likely the reason, yes. "Eventual" consistency by design means that you will get a response before all the copies are updated with the latest changes, so the output is not always current. Even without the consistency header, replication can add some delay. This is usually noticeable in the UI, but direct Graph queries are not an exception, at least in my experience.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

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