ApiManagementProductCollection.GetAllAsync Method expandGroups flag doesn't work, should it?

David 40 Reputation points
2025-08-19T16:40:04.05+00:00

In my application using the Azure.ResourceManager.ApiManagement nuget package version 1.3, I'm retrieving all products and I want to get the groups for those products in a single call instead of having to later query product by product,

The documentation indicates setting the expandGroups flag as true in the request will add this as a property in the response but this is not working for me. On particular LLM claimed that "The parameter exists for parity with older SDKs, but the Azure.ResourceManager SDK models (ApiManagementProductData) do not expose a Groups property at all. So you can’t rely on expandGroups in this SDK to populate group relationships." is this true?

My code

var results = await _cache.GetOrCreateAsync(AllProductsCacheKey, async entry =>
   {
         entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(AbsoluteInMemoryCacheExpirationInMinutes);
         var result = new List<ApiManagementProductResource>();
         await foreach (var item in productCollection.GetAllAsync(
         filter: "state eq 'published'",
         expandGroups: true,
         top: ApimCallMaximumRecordsCount, 
         cancellationToken: cancellationToken))
         {
            result.Add(item);
         }
      return result;
   });
}
return results;

The results Data property doesn't include any property with the groups

User's image

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
{count} votes

1 answer

Sort by: Most helpful
  1. Harish Badijana 40 Reputation points Microsoft External Staff Moderator
    2025-08-19T20:06:07.0733333+00:00

    @David

    Thank you for using Q&A platform,

    The ExpandGroups parameter exists for parity with older SDKs but does not populate group relationships in the current SDK—is accurate.The ApiManagementProductData model does not expose a Groups property. So even if you set ExpandGroup as true, the response will not include group data for each product

    The expandGroups flag is a legacy parameter retained for compatibility with older SDKs and REST API behavior. However, the newer Azure.ResourceManager SDK does not map this expanded data into the ApiManagementProductData model.

    To retrieve group relationships for products, you’ll need to Query products individually using productCollection.GetAllAsync(...).

    For each product, query its associated groups using a separate call

    await foreach (var group in product.GetGroupsAsync())

    {

    // process group

    }

    This is currently the only reliable way to get group data per product using SDK v1.3.

    I hope this helps in resolving the issue, do let me know if you have any further questions on this

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.