Claudiu Stoica
Claudiu Stoica

Reputation: 241

Shopware 6 custom entity fields are not updated via admin api

i have a custom entity defined in entities.xml:

<?xml version="1.0" encoding="utf-8" ?>
<entities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/shopware/platform/trunk/src/Core/System/CustomEntity/Xml/entity-1.0.xsd">
    <entity name="custom_entity_search">
        <fields>
            <string name="media_hash" store-api-aware="true" />
            <json name="data" store-api-aware="true" />
        </fields>
    </entity>
</entities>

when i use the admin api to insert a new custom entity i don't get all my fields updated.
request url:

http://localhost/api/custom-entity-search

request body:

{
    "name": "custom-entity-search",
    "fields": {
        "media_hash": "123hashmedia",
        "data": {"test": "1234"}
    }
}

The entity is created but fields "media_hash" and "data" remain null.
How can i update those fields ?

Upvotes: 0

Views: 424

Answers (1)

j_elfering
j_elfering

Reputation: 3190

You need to pass the fields directly in the payload there is no need to specify the entity name in the payload itself, the mapping to the concrete custom entity is done over the REST-API endpoint api/custom-entity-search

so the request body should look like this:

{
    "media_hash": "123hashmedia",
    "data": {"test": "1234"}
}

Edit (to many relations)

{
    "media_hash": "123hashmedia",
    "data": {"test": "1234"},
    "customer_to_many_field": [
        {
            "id": "my first customer id",
            "firstName": "The new name",
        },
        {
           ... // data for second customer if needed
        }
    ]

}

Upvotes: 2

Related Questions