Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Suggested answer

How to combine $expand with savedQuery parameter in Web API

Posted on by 5

We are using system views to filter which entity records to return from the Web API. The filtering works great, but it messes up the way the data is returned when used in conjunction with $expand.

Searching contacts with an $expand AND a savedQuery:


/contacts?$select=firstname,createdon&$expand=parentcustomerid_account($select=name;$expand=primarycontactid($select=fullname))&savedQuery=5da27be3-1da1-ea11-a812-000d3a1b88d8
{
"@odata.etag": "W/\"4984909\"",
"contactid": "49a0e5b9-88df-e311-b8e5-6c3be5a8b200",
"createdon": "2017-01-20T22:39:39Z",
"fullname": "a tester",
"firstname": "a",
"_LinkEntityAliasPrefixparentcustomerid_account_x002e_name": "Adventure Works"
}

parentcustomerid_account.name does come back in a predictable (albeit unusual) format, but the nested $expand of primarycontactid doesn't come back at all.


If I drop the savedQuery parameter, the $expand data comes back as expected:

/contacts?$select=firstname,createdon&$expand=parentcustomerid_account($select=name;$expand=primarycontactid($select=fullname))
{
"@odata.etag": "W/\"4984909\"",
"contactid": "49a0e5b9-88df-e311-b8e5-6c3be5a8b200",
"createdon": "2017-01-20T22:39:39Z",
"fullname": "a tester",
"firstname": "a",
"parentcustomerid_account": {
"name": "A Datum Corporation",
"accountid": "a16b3f4b-1be7-e611-8101-e0071b6af231",
"primarycontactid": {
"fullname": "Yvonne McKay (sample)",
"contactid": "7f264114-298e-ea11-a811-000d3a569af5"
}
}
}


Is this a bug?

Is there a way to use a savedQuery in conjunction with $expand (and nested $expand) and get the data returned in the proper format?

Thanks,
Chris

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: How to combine $expand with savedQuery parameter in Web API

    Hello,

    I don't think it's doable. My recommendation - use ?fetchXml querying to get the data you need - docs.microsoft.com/.../retrieve-and-execute-predefined-queries

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

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