0
votes

Basically, I have something like this:

https://company.crm.dynamics.com/api/data/v9.0/accounts?$select=accountid,accountnumber,name&$expand=crm_productbuyer($select=name)

I'd like to be able to just get a count of the number of records returned in the $expand instead of deserializing it in C# and doing a count on it. Just one lest thing to iterate over.

This didn't work for my case:

API $expand and &count

EDIT:

There are a number of things here that indicate this isn't doable:

https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/webapi/retrieve-entity-using-web-api#retrieve-related-entities-for-an-entity-by-expanding-navigation-properties

You can’t use the /$ref or /$count path segments to return only the URI for the related entity or a count of the number of related entities.


This is a subset of the system query options described in the “11.2.4.2.1 Expand Options” section of OData Version 4.0 Part 1: Protocol Plus Errata 02. The options $skip, $count, $search, $expand and $levels aren’t supported for the Web API.

Will mark this an answer unless someone else chimes in to demonstrate otherwise.

1
I tried asking the same thing a while ago (stackoverflow.com/questions/49747018/api-expand-and-count). Sadly I don't think this is possiblejasonscript

1 Answers

0
votes

Doesn't sound like it is doable:

https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/webapi/retrieve-entity-using-web-api#retrieve-related-entities-for-an-entity-by-expanding-navigation-properties

You can’t use the /$ref or /$count path segments to return only the URI for the related entity or a count of the number of related entities.


This is a subset of the system query options described in the “11.2.4.2.1 Expand Options” section of OData Version 4.0 Part 1: Protocol Plus Errata 02. The options $skip, $count, $search, $expand and $levels aren’t supported for the Web API.