2

I wan't to make a "classic" API without IRI. I just want the ID in return, not an IRI nor the object/entity.

I already allow plain identifiers:

// config/packages/api_platform.yml
api_platform:
allow_plain_identifiers: true

If I make any request with Header Accept: application/json, it's still the same.

I I try to cheat and replace my getter of my linked entity by a getId()

    public function getStatus(): AngelRelationshipStatus
    {
        return $this->status;
    }

by

    public function getStatus(): int
    {
        return $this->status->getId();
    }

I'm getting the Following error : "Warning: get_class() expects parameter 1 to be object, integer given"

Why can't I just get a simple ID?

Environment:

  • PHP 7.2
  • API Platform 2.3
matll42
  • 21
  • 1
  • 5

1 Answers1

0

My recommendation is to not change too much under the hood with these hacky attempts to do unintended things (e.g. returning id for status).

Instead, simply customise your output during the Serialisation process.

See Api-Platform Serialisation Process.

Mundi
  • 79,884
  • 17
  • 117
  • 140
  • So let's take the bookshop example, how would one retrieve a list of review ids instead of a list of review IRIs? – Elias Jan 18 '22 at 08:44