api-platform / core

The server component of API Platform: hypermedia and GraphQL APIs in minutes
https://api-platform.com
MIT License
2.45k stars 878 forks source link

POST and PUT return null instead of resource #6771

Closed Cruiser13 closed 2 weeks ago

Cruiser13 commented 2 weeks ago

API Platform version(s) affected: 3.4.5

Description
In 3.1 any POST or PUT with json returned the created object in json to the browser, same as the GET endpoint. We updated to 3.4.5 recently and now we only get null as response on a POST / PUT, status code is 200 and object is created though. We looked through the changelog of api platform and did not see a breaking change like that. We even tried to set use_symfony_listeners: true but it did not have any effect.

Here is a related stack overflow issue: https://stackoverflow.com/questions/79061122/api-platform-post-put-request-return-body-is-null

How to reproduce
Setup api platform 3.4.5 with a demo entity and call the POST or PUT endpoint using jsonld or json.

Additional Context
Our api_platform.yaml looks like this:

api_platform:
    mapping:
        paths: ['%kernel.project_dir%/src/Entity']
    patch_formats:
        json: ['application/merge-patch+json']
    swagger:
        versions: [3]
        api_keys:
            apiKey:
                name: Authorization
                type: header
    title: 'API'
    description: 'Work in progress'
    version: '0.0.1'
    use_symfony_listeners: true
    formats:
        #defaults:
        jsonld: [ 'application/ld+json' ]
        json: [ 'application/json' ]
        html: [ 'text/html' ]
        #more:
        #jsonhal:  ['application/hal+json']
        #jsonapi:  ['application/vnd.api+json']
        #yaml:     ['application/x-yaml']
        xml: [ 'application/xml', 'text/xml' ]
        csv: [ 'text/csv' ]
        thumb: ['image/webp']
        #custom:
    defaults:
        pagination_items_per_page: 25  # Default value
        pagination_maximum_items_per_page: 1000
        pagination_client_items_per_page: true
        collection:
            pagination:
                items_per_page_parameter_name: itemsPerPage # Default value
soyuka commented 2 weeks ago

Do you have a custom processor and/or custom event listeners? that are called on this route?

Cruiser13 commented 2 weeks ago

Thank you for your reply - not on this route, no. This affects all entities for us. Attached are the events at POST.

symfony-profiler
Cruiser13 commented 2 weeks ago

We found the issue thanks to @soyuka - we had to return the processor in the process function of our state processor (has been void before). Solved!