1

I have a content model "category" that contains products (also a content model). Now I have to get the category in which a product is linked. For this I got the product url_name (unique).

I searched in the kentico-delivery-sdk (JS) docs for a filter, that can go deeply inside an object/linked content model.

       categoryByProduct: async (
          _,
          { product, limit = 1,depth, order, language }
        ) => {
          const query = deliveryClient.items();
          language && query.languageParameter(getKcCodeFromLang(language));
          limit && query.limitParameter(limit);
          depth && query.depthParameter(depth);
          order && query.orderParameter(order);
          query.containsFilter("elements.produkte[].url_name", product)

          const response = await query.getPromise();
          return response.items;
        },

With this approach I never get a response from GraphQL. Is this the wrong filter?

rocky
  • 7,506
  • 3
  • 33
  • 48
emma93
  • 177
  • 2
  • 12

2 Answers2

0

Filtering for Kentico Cloud API does not currently allow you to specify filters on nested properties and thefore filter such as elements.produkte[].url_name gives this exception when run against Delivery API directly:

Operator '[].produkte' was not recognized as a valid operator.

What you are trying to do is perfectly valid scenario, though currently you will have to make additional request on your products, filter it and combine results of your queries to give one final result.

Enn
  • 2,137
  • 15
  • 24
0

It's possible to query for a parent which has the current item as a subpage with the following query;

let items = (
  await kontent
    .items<IContentItem>
    .containsFilter('elements.subpages', [currentItem.system.codename])
    .toPromise()).data.items;

Where currentItem is the one I want to find the parent for.

Thor
  • 737
  • 7
  • 15