-1

First of all sorry for my english.

I am trying with API Platform and Symfony to do a POST on my customer entity. (the get works fine)

At the time of doing the POST I find myself with this error :

"Unable to generate an IRI for "App\Entity\Customer"."

Here is my entity I think the problem comes from here but I can't find the reason.

<?php

namespace App\Entity;

use ....


/**
 * @ORM\Entity(repositoryClass=CustomerRepository::class)
 */
#[ApiResource(
    collectionOperations: [
        'get' => ['method' => 'get'],
        'post' => ['method' => 'post'],
    ],
    itemOperations: [
        'get' => ['method' => 'get'],
        'put' => ['method' => 'put'],
        'delete' => ['method' => 'delete'],
    ],
    denormalizationContext: ['groups' => ['write_customer']],
    normalizationContext: ['groups' => ['read_customer']],
)]

class Customer
{
......
Mickkit
  • 31
  • 4
  • You have not provided enough code. Errors like this may be related to the way you've defined you entity class and in particular the ID column. More context is needed. Please provide the entire Customer class. – David Feb 16 '22 at 15:51

1 Answers1

0

Generating the IRI needs visibility on the ID if you have serialization Groups you have to add this groups to id (primKey).

First make sure you have a getId function thats works well. Then you can add you searialisation groups to the id.

Here you can find an example in the dokumetation: https://api-platform.com/docs/core/serialization/#calculated-field

....
    denormalizationContext: ['groups' => ['write_customer']],
    normalizationContext: ['groups' => ['read_customer']],
....




/**
 * @var int The entity Id
 *
 * @ORM\Id
 * @ORM\GeneratedValue
 * @ORM\Column(type="integer")
 */
#[Groups("write_customer", read_customer)]
private $id;
episch
  • 388
  • 2
  • 19