Query Option 'Count' Error in Microsoft Graph API

Prem Kumar Sharma 20 Reputation points
2023-09-26T09:49:52.64+00:00

Issue:
I am encountering an issue when using the Microsoft Graph API to fetch audit logs for sign-ins. I want to include a count of the results for pagination purposes, but I am receiving the following error:

"Query option 'Count' is not allowed. To allow it, set the 'AllowedQueryOptions' property on EnableQueryAttribute or QueryValidationSettings."

Code:

const headers = { 'Authorization': "Bearer " + token }; 
const url = `https://graph.microsoft.com/v1.0/auditLogs/signIns?$filter=startswith(appDisplayName,'Xyz')&$count=true`;  
axios
.get(nexturl ?? url, { headers })
.then(async (response) => {  
  	 console.log(response, 'log');   
  	const { headers, table } = formatAuditLogs(response.data);     
	resolve({ headers, table, nextLink: response.data['@odata.nextLink'] }); 
})
.catch((error) => {  
   	reject(error); 
});

Use of $count in My Case:
I am trying to implement pagination for the audit log results. To do this, I need to include a count of the results so that I can create page navigation (e.g., 1, 2, 3, 4...) for users to jump between pages and keep track of the current page. I have also attempted to use $skip and $select, but I encountered the same error regarding AllowedQueryOptions.

Request for Assistance:
I am seeking guidance on how to resolve this issue and enable the use of $count or other options for implementing pagination in the Microsoft Graph API. I am using ReactJS for my application and making API calls using Axios.

Any help or insights into how to address this issue would be greatly appreciated. Thank you in advance for your assistance.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,041 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
21,795 questions
0 comments No comments
{count} votes

Accepted answer
  1. 2023-10-01T01:53:38.5+00:00

    Hello @Prem Kumar Sharma , the $count query parameter is not supported by all Microsoft Graph resources. List signIns only supports the $top, $skiptoken, and $filter.

    Let us know if you need additional assistance. If the answer was helpful, please accept it and rate it so that others facing a similar issue can easily find a solution.

    2 people found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

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