πŸ“£ The forum has moved to GitHub

We’ve switched to GitHub Discussions as the hub for our community. This will improve the experience of collaborating for everyone, sharing what you’re working on, and discussing ideas for how Swell can be improved. Existing threads will remain open, but new posts are disabled.

Go to GitHub β†’

Not getting category_index property in the products list on frontend

I am fetching the products list by using swell front-end APIs - https://developers.swell.is/frontend-api/products

In the developer console, I checked that product model contains a category_index key which contains a list of category ids. I was getting this field earlier, but since yesterday, the frontend-API has been returning my error saying that I don't have permission to expand this field.

I'm attaching console error log and my code that I've been using below.



Answers

  • Hey @Gaurav Pandey I consulted one of our engineers and was advised that we do not allow to expand category_index.

    Instead, what should you do is to expand the categories.

    Additionally, you can only access category_index from the developer console or backend API, or explicitly grant access to it.

    Or you can collect the product category IDs from the response:

    Β Β const ids = (product.categories || []).map(category => category.id);


    Lastly, what you should do is to remove query.expand = ['category_index'] from your code to make it working again.

  • Gaurav Pandey
    edited September 8

    Hi Jesse, thanks for your reply.

    I was indeed getting this category_index in some of the responses while using frontend sdk. So, I guess some issue with the swell. Please check that with your engineering team.

  • @Gaurav Pandey can you share which request gets the category_index in the response and which response doesn't? Or was it intermittent?

  • Jesse B
    edited October 19

    Hey @Gaurav Pandey ! Our engineers checked our permissions and they don't see any changes for category_index last year. I understand that you confirmed it's intermittent, but again, different from the backend API, we have some security in the frontend API to restrict field access. We have been allowed to view fields, allowed to edit fields and available expands for each model. By default, we allow only variants and categories to be expanded for the product model. So you shouldn't be allowed to expand on category_index. Otherwise, this is a bug.

    Again, we can get our engineers to investigate this further but being intermittent, this will be hard to reproduce (unless we have the steps to reproduce this)

    I highly recommend following the standard path and using query.expand = ['categories'] to get categories for each product.

Sign In or Register to comment.