Taking too long to fetch 4k contacts
We using your node package "@microsoft/microsoft-graph-client" to access Graph API from node enviroment.
Actually the purpose is to fetch the user contacts (outlook,live,office, hotmail) into our system through API,
API "/me/contacts" by default fetching only 10 contacts per call, so in our system we iterating the API using "skip & @odata.nextLink" until all the contacts are received. While referencing Graph API document it says, by default each request will provide 10 contacts,
So to fetching 4k contacts from my account it takes 5+ minutes.
So here there are 2 questions from my side,
- Is there any query parameters to fetch maximum contacts in a single API request.
- To reduce the delay in fetching huge contact list say 8k contacts, is there any other API available to reduce the time delay. AB#7541
-
Change the page size with the $top parameter. I think the max is 100 - 200.
-
Use $select to only select the properties you are using.
-
I haven't tried this but you could parallelize the calls by having thread 1 get contacts 1-1000, thread 2 get 1001-2000 thread 3 get 2001-3000. You'd have to probe $skip to find out exactly how many users are in the result set since $count isn't enabled. Have thread 1 call
/users/id/contacts?$top=100until it hits contact 999, thread 2 calls/users/id/contacts?$skip=1000&$top=100until it hits contact 2000, thread 3/users/id/contacts?$skip=2000&$top=100 until it hits contact 3000, etc. Beware of throttling limits.
@michael, thanks. After getting the total contacts count, i am trying with parallel threads using skip parameter. Once completed let me update the time taken.
@ashokkumarjuly I change my mind about getting the count. It isn't important. As you spin up threads, you'll know when you've skipped more than max number of items when the result set is empty. That should save some calls.
@MIchaelMainer Now another strange issue, i have 28,000 contacts in my office account.
- If i give $top parameter greater than 99, endless waiting for the API response
- If i give $top=99 to fetch the contacts, endless waiting for the API response in the middle after fetching 5,000 contacts. I have searched for the documents related to this issue, but i can't able to figure out either it is problem with this npm package or Graph API.
FYI, i have attached the image.

In the image the last API call "url /me/contacts?$top=99&$skip=5792", is waiting more than 20 mins but no response from API.
@ashokkumarjuly I had an issue which might be similar to yours. I would have some requests pending, often dependent on what page size i specified for the response.
The issue was not with the API, but with the parsing of the API response. Try requesting the raw response, and parse on your own end. This solved the issue for me (but the root cause is probably a bug in the library). See https://github.com/microsoftgraph/msgraph-sdk-javascript/blob/dev/src/GraphResponseHandler.ts#L98 for the relevant code.
I posted on stack overflow about the issue and my solution: https://stackoverflow.com/questions/56936673/microsoft-graph-api-calendarview-delta-endpoint-does-not-respond-on-initial-requ/56941406#56941406
@evedal , thanks let me try.
Closing this issue as I am unable to reproduce this. Please reopen if this problem persists or for any related questions.