Why I am getting 400 Bad Request with Api Plateform? [duplicate]

I installed API Plateform in my Symfony4 Project using composer require api.
After that, I added * @ApiResource annotation to my customer entity.

That’s all I have done. When I start the server and I go to http://127.0.0.1:8000/api and I attempt to test the GET method

enter image description here

I get 400 error bad request.
The problem is I haven’t write any code yet. I just added * @ApiResource annotation to the customer entity.

When I check the profiler(debug bar) I find

Exception:

A circular reference has been detected when serializing the object of
class "Proxies_CG_AppEntityUser" (configured limit: 1).

Log Messages:

Uncaught PHP Exception
SymfonyComponentSerializerExceptionCircularReferenceException: "A
circular reference has been detected when serializing the object of
class "Proxies_CG_AppEntityUser" (configured limit: 1)." at
C:wampwwwsymfony-reactvendorsymfonyserializerNormalizerAbstractNormalizer.php
line 330
Here is the code of my composer.json:

{
    "type": "project",
    "license": "proprietary",
    "require": {
        "php": ">=7.1.3",
        "ext-ctype": "*",
        "ext-iconv": "*",
        "api-platform/core": "^2.5",
        "composer/package-versions-deprecated": "^1.11",
        "doctrine/annotations": "^1.0",
        "doctrine/doctrine-bundle": "^2.2",
        "doctrine/doctrine-migrations-bundle": "^3.0",
        "doctrine/orm": "^2.7",
        "nelmio/cors-bundle": "^2.1",
        "phpdocumentor/reflection-docblock": "^5.2",
        "sensio/framework-extra-bundle": "^5.1",
        "symfony/asset": "4.4.*",
        "symfony/console": "4.4.*",
        "symfony/dotenv": "4.4.*",
        "symfony/expression-language": "4.4.*",
        "symfony/flex": "^1.3.1",
        "symfony/form": "4.4.*",
        "symfony/framework-bundle": "4.4.*",
        "symfony/http-client": "4.4.*",
        "symfony/intl": "4.4.*",
        "symfony/mailer": "4.4.*",
        "symfony/monolog-bundle": "^3.1",
        "symfony/process": "4.4.*",
        "symfony/property-access": "4.4.*",
        "symfony/property-info": "4.4.*",
        "symfony/security-bundle": "4.4.*",
        "symfony/serializer": "4.4.*",
        "symfony/translation": "4.4.*",
        "symfony/twig-bundle": "^4.4",
        "symfony/validator": "4.4.*",
        "symfony/web-link": "4.4.*",
        "symfony/yaml": "4.4.*",
        "twig/extra-bundle": "^2.12|^3.0",
        "twig/twig": "^2.12|^3.0"
    },
    "require-dev": {
        "symfony/browser-kit": "^4.4",
        "symfony/css-selector": "^4.4",
        "symfony/debug-bundle": "^4.4",
        "symfony/maker-bundle": "^1.0",
        "symfony/phpunit-bridge": "^5.1",
        "symfony/stopwatch": "^4.4",
        "symfony/var-dumper": "^4.4",
        "symfony/web-profiler-bundle": "^4.4"
    },
    "config": {
        "preferred-install": {
            "*": "dist"
        },
        "sort-packages": true
    },
    "autoload": {
        "psr-4": {
            "App": "src/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "AppTests": "tests/"
        }
    },
    "replace": {
        "paragonie/random_compat": "2.*",
        "symfony/polyfill-ctype": "*",
        "symfony/polyfill-iconv": "*",
        "symfony/polyfill-php71": "*",
        "symfony/polyfill-php70": "*",
        "symfony/polyfill-php56": "*"
    },
    "scripts": {
        "auto-scripts": {
            "cache:clear": "symfony-cmd",
            "assets:install %PUBLIC_DIR%": "symfony-cmd"
        },
        "post-install-cmd": [
            "@auto-scripts"
        ],
        "post-update-cmd": [
            "@auto-scripts"
        ]
    },
    "conflict": {
        "symfony/symfony": "*"
    },
    "extra": {
        "symfony": {
            "allow-contrib": false,
            "require": "4.4.*"
        }
    }
}

Here is the code of Customer.php:

<?php

namespace AppEntity;

use DoctrineORMMapping as ORM;
use AppRepositoryCustomerRepository;
use DoctrineCommonCollectionsCollection;
use ApiPlatformCoreAnnotationApiResource;
use DoctrineCommonCollectionsArrayCollection;

/**
 * @ORMEntity(repositoryClass=CustomerRepository::class)
 * @ApiResource
 */
class Customer
{
    /**
     * @ORMId
     * @ORMGeneratedValue
     * @ORMColumn(type="integer")
     */
    private $id;

    /**
     * @ORMColumn(type="string", length=255)
     */
    private $fullName;

    /**
     * @ORMColumn(type="string", length=255)
     */
    private $email;

    /**
     * @ORMColumn(type="string", length=255, nullable=true)
     */
    private $company;

    /**
     * @ORMOneToMany(targetEntity=Invoice::class, mappedBy="customer")
     */
    private $invoices;

    /**
     * @ORMManyToOne(targetEntity=User::class, inversedBy="customers")
     */
    private $user;

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *