Skip to main content

Notifications

Dynamics 365 general forum

filter on expand in web API query?

Posted on by 150

So I have an API GET that looks like the following:

https://company.crm.dynamics.com/api/data/v9.0/accounts?$select=accountid,accountnumber,name&$expand=account_productbuyer($select=productbuyerid,status)&$filter=status code eq 1

I'd like to only return records in the expand from the account_productbuyer where the status equals a certain value. I've tried adding filter into the expand, but it is the incorrect syntax.

Is this possible to do via the web API? I'm trying to avoid iterating through the records returned in the expand to check for a certain status value.

  • Saad Kabarousse Profile Picture
    Saad Kabarousse 732 on at
    RE: filter on expand in web API query?

    Hello,

    I am facing the same problem i'm trying to add a filter on a field on an expanded entity , i tried your example abouve but i'm getting the following error:

    xxxxxxxx/.../accounts eq 1;$select=contactid)

    Only $select clause can be provided while doing a $expand on entitysets

  • ishraqiyun77 Profile Picture
    ishraqiyun77 150 on at
    RE: filter on expand in web API query?

    That did the trick. Thanks for the help!

  • Verified answer
    LeoAlt Profile Picture
    LeoAlt 16,329 on at
    RE: filter on expand in web API query?

    Hi partner,

    You could try this url:

    company.crm.dynamics.com/.../accounts$filter=statuscode eq 1&;$select=productbuyerid,statuscode)

    You need to put the condition "statuscode" in the expand.For examle, I tried to search for the contacts from account entity with statuscode = 1,and here are my url and response.

    https://xxxxx.crm.dynamics.com/api/data/v9.0/accounts?$select=accountid,accountnumber,name&$expand=primarycontactid($filter=statuscode%20eq%201;$select=contactid)

    121.jpg

    You could also refer to this doc for more detals about how to use expand.

    https://docs.microsoft.com/en-us/powerapps/developer/common-data-service/webapi/retrieve-entity-using-web-api#options-to-apply-to-expanded-entities

    Hope it helps.

    Best Regards,

    Leo

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans