I am using Api platform and Symfony 5.4, ManyTomany relation on category and I have this error

I found the solution: by adding @ApiResource on the Category entity.

1

There are 1 best solutions below

0
On

It's because the Category is not marked with @ApiResource, so it's not handled by the API Platform (it is by the Symfony one), and as there is a circular reference, an error is thrown. If Category where an API resource, the circular reference would be handled automatically. If you don't want to make it a resource, you need to register a circular reference handler by yourself: https://symfony.com/doc/current/components/serializer.html#handling-circular-references

Source : https://github.com/api-platform/api-platform/issues/501