OData REST Filter for deeply nested data

2019-07-23 07:06发布

I have a working REST request that returns a large results collection. (trimmed here)

The original URL is:

http://intranet.domain.com//_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='domain\kens'&$select=AccountName,DisplayName,Email,Title,UserProfileProperties

The response is:

{
"d": {
    "__metadata": {
        "id": "stuff",
        "uri": "morestuff",
        "type": "SP.UserProfiles.PersonProperties"
    },
    "AccountName": "domain\\KenS",
    "DisplayName": "Ken Sanchez",
    "Email": "KenS@domain.com",
    "Title": "Research Assistant",
    "UserProfileProperties": {
        "results": [
            {
                "__metadata": {
                    "type": "SP.KeyValue"
                },
                "Key": "UserProfile_GUID",
                "Value": "1c419284-604e-41a8-906f-ac34fd4068ab",
                "ValueType": "Edm.String"
            },
            {
                "__metadata": {
                    "type": "SP.KeyValue"
                },
                "Key": "SID",
                "Value": "S-1-5-21-2740942301-4273591597-3258045437-1132",
                "ValueType": "Edm.String"
            },
            {
                "__metadata": {
                    "type": "SP.KeyValue"
                },
                "Key": "ADGuid",
                "Value": "",
                "ValueType": "Edm.String"
            },
            {
                "__metadata": {
                    "type": "SP.KeyValue"
                },
                "Key": "AccountName",
                "Value": "domain\\KenS",
                "ValueType": "Edm.String"
            }...

Is it possible to change the REST request with a $filter that only returns the Key Values from the results collection where Key=SID OR Key= other values?

I only need about 3 values from the results collection by name.

1条回答
Root(大扎)
2楼-- · 2019-07-23 07:48

In OData, you can't filter an inner feed.

Instead you could try to query the entity set that UserProfileProperties comes from and expand the associated SP.UserProfiles.PersonProperties entity.

The syntax will need to be adjusted for your scenario, but I'm thinking something along these lines:

service.svc/UserProfileProperties?$filter=Key eq 'SID' and RelatedPersonProperties/AccountName eq 'domain\kens'&$expand=RelatedPersonProperties

That assumes you have a top-level entity set of UserProfileProperties and each is tied back to a single SP.UserProfiles.PersonProperties entity via a navigation property called (in my example) RelatedPersonProperties.

查看更多
登录 后发表回答