简体   繁体   中英

Trouble with filter in Microsoft Graph query using C#

I'm having trouble converting the following Microsoft Graph rest query to C#. The following works in the graph explorer:

https://graph.microsoft.com/v1.0/sites/{siteid}/lists/{listid}/items?$expand=fields&$filter=fields/Recruit_x0020_Status eq 'Initial Discussion'

So far I have the following which doesn't work:

    var options = new List<QueryOption>()
    {
        new QueryOption("expand", "fields"),
        new QueryOption("filter", "startswith(Recruit_x0020_Status', 'Initial')")
    };

    var list = await _client
        .Sites[siteId]
        .Lists[listId]
        .Items
        .Request(options)
        .Header("Prefer", "HonorNonIndexedQueriesWarningMayFailRandomly")
        .GetAsync();

The error returned is very generic and not helpful:

ServiceException: Code: generalException
Message: General exception while processing

I tried adding the filter directly into the chained fluent query via .Filter("startswith(Recruit_x0020_Status,'Initial')") , but I receive an error about a bad filter clause.

What am I missing here? Any help would be appreciated.

Your QueryOption is missing fields property name in startswith and there is also a typo in Recruit_x0020_Status' . The char ' .

new QueryOption("filter", "startswith(Recruit_x0020_Status', 'Initial')")

It should be

new QueryOption("filter", "startswith(fields/Recruit_x0020_Status, 'Initial')")

Generally the url will looks like this

GET https://graph.microsoft.com/v1.0/sites/{siteid}/lists/{listid}/items?$expand=fields&filter=startswith(fields/Recruit_x0020_Status,'Initial')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM