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

Martin Bilda 171 Reputation points
2020-04-14T08:38:22.017+00:00

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://learn.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

Microsoft Teams
Microsoft Teams
A Microsoft customizable chat-based workspace.
9,071 questions
{count} vote

Accepted answer
  1. Valentin 81 Reputation points
    2020-04-14T10:30:14.553+00:00

    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://learn.microsoft.com/de-de/graph/query-parameters#count-parameter

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Sharon Zhao-MSFT 25,056 Reputation points Microsoft Vendor
    2020-04-15T03:00:32.843+00:00

    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.

    0 comments No comments