question

MartinBilda-7257 avatar image
0 Votes"
MartinBilda-7257 asked ·

To allow it, set the 'AllowedQueryOptions' property on EnableQueryAttribute or QueryValidationSettings

Hi,

every MicrosoftGraph call that i do, ends up with the exception in the title if i add query paramters to it.

My request: https://graph.microsoft.com/v1.0/teams/{team-id}/channels/{channel-id}?$count=true

Response: "message": "The query specified in the URI is not valid. Query option 'Select' is not allowed. To allow it, set the 'AllowedQueryOptions' property on EnableQueryAttribute or QueryValidationSettings."

It isn't only happening with count. I can't use select, count, top and so on. Everytime the same exception.

If u google 'AllowedQueryOptions' u get to this page: 'https://docs.microsoft.com/de-de/graph/query-parameters' but there is nothing explained about how u can set this QueryOptions. Is it even possible to set it now or is it not supported yet?

Best regards,

Martin

office-teams-windows-itpro
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

ValentinBeller avatar image
1 Vote"
ValentinBeller answered ·

The error looks like an exception on server side thrown by the OData provider: To allow the Count query, you would put the [AllowQuery("Count")] (?) before the ASP.NET action / controller.

Edit 2: Clarification: this attribute would be needed on Microsoft's server side, not on client's "server"-side.

So nothing you can do, besides raising a feature request ;) Workaround: download all and count locally.

Btw, requesting the number of channels should be:
https://graph.microsoft.com/v1.0/teams/{team-id}/channels?$count=true
shouldn't it? But you'll still get the same error.

Edit: The docs say it all:

Note: $count is not supported for collections of resources that derive from directoryObject like collections of users or groups.

https://docs.microsoft.com/de-de/graph/query-parameters#count-parameter


· 3 · Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

First of all thank you for your answer.

I dont unterstand your first sentance... where do i have to put it? Maybe I should provide you with more Information: I develop in Java and have downloaded the GraphAPI via Maven.
I have a GraphServiceClient and provided it with an authentication provider, which signs the request with the auth token in the header.

 OAuth2AuthenticationProvider authProvider = new OAuth2AuthenticationProvider(clientId, tenantId, clientSecret);
         graphApplicationClient = GraphServiceClient.builder().authenticationProvider(authProvider).buildClient();

Then I make a call like this:

 graphApplicationClient.teams("teamId").channels().buildRequest().top(5).get())

Thats the only thing i do. Nothing else..

Where do I have to put the [AllowQuery("Count")] now?

Sure.. I'm using this workaround already but it would be much better when u can prepare the right results on the first call.



0 Votes 0 · ·

Have to start a new comment because there were no characters left.

For example I want to get all messages as well and you can imagine how long this response could be. So i want to use the parameter "$top" for getting the first 100 messages or something like that. But it doesn't work...

And yes, u are right i copied the wrong call.. your link is correct. But u are also right. U getting the same error.. :(

0 Votes 0 · ·

Nevermind dude. Saw your note right now. Thank u very much for your help...

1 Vote 1 · ·
SharonZhao-MSFT avatar image
0 Votes"
SharonZhao-MSFT answered ·

Hi MartinBilda-7257,

I’m not familiar with the codes. However, I searched the error message and found a similar thread. Hope it will be helpful to you.

The link is: https://stackoverflow.com/questions/25874020/query-option-format-is-not-allowed-to-allow-it-set-the-allowedqueryoptions.

· Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.