Retrieving multiple content types with the deliver...
# help-with-umbraco
u
TLDR; is there a content delivery api cheatsheet (not the docs) like Seb did back in the Razor days? I'm struggling how to find the best way to get a page and it's children (for a listing page) in a single api call. I can see how to get the children on their own. In my case I have a content type for the listing page and one for the child types, so I thought I'd try that way, but I can't figure out how to pass in multiple types. I've tried reading the docs and tried several ways to do this in Swagger, but with no success. My last resort will be to get all content and restrict the fields I return, but I thought I'd check for a 'better' way of doing this. Thanks
s
I came across the same issue and never found a way to do it in a single API call. I did resort to just pulling down all content which was fine for my use case. If you want to query for multiple content types you could create a custom filter: https://docs.umbraco.com/umbraco-cms/reference/content-delivery-api/extension-api-for-querying#custom-filter Based on that example, I came up with this (no need to implement
IContentIndexHandler
in this case as the contentType is already indexed):
Copy code
using Umbraco.Cms.Core.DeliveryApi;

namespace Umbraco.Docs.Samples;

public class ContentTypesFilter : IFilterHandler
{
    private const string ContentTypesSpecifier = "contentTypes:";
    private const string FieldName = "contentType";

    // Querying
    public bool CanHandle(string query)
        => query.StartsWith(ContentTypesSpecifier, StringComparison.OrdinalIgnoreCase);

    public FilterOption BuildFilterOption(string filter)
    {
        var fieldValue = filter.Substring(ContentTypesSpecifier.Length);

        // There might be several values for the filter
        var values = fieldValue.Split(',');

        return new FilterOption
        {
            FieldName = FieldName,
            Values = values,
            Operator = FilterOperation.Is
        };
    }
}
And then the API can be queried as such:
/umbraco/delivery/api/v2/content?filter=contentTypes:blog,blogPost
But tbh I think querying multiple types should be supported OOTB, unless we've both missed something
b
I was looking for this as well. It would be great if it was supported OOTB 🥳
89 Views