HTTP 500 nach API POST request auf Customer

Hallo zusammen,

ich benötige Unterstützung um eine erfolgreiche API Post request auf:
https://xxxxxxxx.com/api/customer

zu machen.

Der Body von der Request sieht wie folgt aus:

{
"customerNumber": "TestUser1",
"groupId": "PlatzhalterGroupId", 
"salesChannelId": "PlatzhalterSalesChannelId",
"email": "test2@xxxxxx.com",
"firstName":"TestVorname",
"lastName":"TestName",
"defaultPaymentMethodId": "PlatzhalterPaymentMethodId",
"defaultBillingAddress": [
    {
    "firstName": "TestVorname",
    "lastName":"TestName",
    "street": "Teststraße 11",
    "zipcode": "12345",
    "city": "Teststadt",
    "countryId": "PlatzhalterCountryID"
    }
],
"defaultShippingAddress": [
   {
    "firstName": "TestVorname",
    "lastName":"TestName",
    "street": "Teststraße 111",
    "zipcode": "12345",
    "city": "Teststadt",
    "countryId": "PlatzhalterCountryID"
    }
],
"guest": true
}

Bei der Request bekomme ich aktuell folgenden Fehler:

„code“: „0“,
„status“: „500“,
„title“: „Internal Server Error“,
„detail“: „Shopware\Core\Framework\DataAbstractionLayer\Write\DataStack\KeyValuePair::__construct(): Argument #1 ($key) must be of type string, int given, called in xxxxxxxx/vendor/shopware/core/Framework/DataAbstractionLayer/Write/DataStack/DataStack.php on line 47“

Ich bin noch sehr neu was die shopware APIs angeht, vielleicht habe ich irgendetwas essentielles vergessen (Die Doku zu Admin API, hat mir nicht alle Fragen beantworten können).

Vielen Dank & Viele Grüße

@ayti, hast du dir mal den Stacktrace angeguckt?
Da wird irgendwo ein int als key verwendet. Leider ist es ohne weitere Informationen schwierig aus der Ferne zu helfen.

@abdullah stehe gerade etwas auf dem schlauch. Wie kann ich das einsehen :slight_smile: ? Weil im Shopware Log und Server Log steht es nicht drin. In der response welche ich in Postman sehe steht nur das was ich schon geschrieben habe. In Postman sehe ich auch keine weiteren Infos. Danke!

@ayti, die Fehlermeldung müsstest du im PHP Error Log finden. Ich kenne jetzt dein System um zu sagen wo die Log Datei liegt.
Ggf. musst du den dev Modus aktivieren.

Wie sehen denn die Params und Headers des Requests aus?

@abdullah, den Body der Request siehst du oben.
Der Header sieht wie folgt aus:

Authorization: Bearer Platzhaltertoken
Accept: application/json
Content-Type: application/json
User-Agent: Testing1

Folgendes wird nun als Fehler angezeigt:

{
    "errors": [
        {
            "code": "0",
            "status": "500",
            "title": "Internal Server Error",
            "detail": "Shopware\\Core\\Framework\\DataAbstractionLayer\\Write\\DataStack\\KeyValuePair::__construct(): Argument #1 ($key) must be of type string, int given, called in /xxxxxx/vendor/shopware/core/Framework/DataAbstractionLayer/Write/DataStack/DataStack.php on line 47",
            "meta": {
                "trace": [
                    {
                        "file": "/xxxxxxx/vendor/shopware/core/Framework/DataAbstractionLayer/Write/DataStack/DataStack.php",
                        "line": 47,
                        "function": "__construct",
                        "class": "Shopware\\Core\\Framework\\DataAbstractionLayer\\Write\\DataStack\\KeyValuePair",
                        "type": "->"
                    },
                    {
                        "file": "/xxxxxxxx/vendor/shopware/core/Framework/DataAbstractionLayer/Write/WriteCommandExtractor.php",
                        "line": 303,
                        "function": "__construct",
                        "class": "Shopware\\Core\\Framework\\DataAbstractionLayer\\Write\\DataStack\\DataStack",
                        "type": "->"
                    },
                    {
                        "file": "/xxxxxxxx/vendor/shopware/core/Framework/DataAbstractionLayer/Write/WriteCommandExtractor.php",
                        "line": 209,
                        "function": "map",
                        "class": "Shopware\\Core\\Framework\\DataAbstractionLayer\\Write\\WriteCommandExtractor",
                        "type": "->"
                    },
                    {
                        "file": "/xxxxxxxxx/vendor/shopware/core/Framework/DataAbstractionLayer/FieldSerializer/ManyToOneAssociationFieldSerializer.php",
                        "line": 115,
                        "function": "extract",
                        "class": "Shopware\\Core\\Framework\\DataAbstractionLayer\\Write\\WriteCommandExtractor",
                        "type": "->"
                    },
                    {
                        "file": "/xxxxxxxx/vendor/shopware/core/Framework/DataAbstractionLayer/Write/WriteCommandExtractor.php",
                        "line": 318,
                        "function": "encode",
                        "class": "Shopware\\Core\\Framework\\DataAbstractionLayer\\FieldSerializer\\ManyToOneAssociationFieldSerializer",
                        "type": "->"
                    },
                    {
                        "file": "/xxxxxxxx/vendor/shopware/core/Framework/DataAbstractionLayer/Write/WriteCommandExtractor.php",
                        "line": 209,
                        "function": "map",
                        "class": "Shopware\\Core\\Framework\\DataAbstractionLayer\\Write\\WriteCommandExtractor",
                        "type": "->"
                    },
                    {
                        "file": "/xxxxxxxxx/vendor/shopware/core/Framework/DataAbstractionLayer/Write/EntityWriter.php",
                        "line": 195,
                        "function": "extract",
                        "class": "Shopware\\Core\\Framework\\DataAbstractionLayer\\Write\\WriteCommandExtractor",
                        "type": "->"
                    },
                    {
                        "file": "/xxxxxxxxx/vendor/shopware/core/Framework/DataAbstractionLayer/Write/EntityWriter.php",
                        "line": 140,
                        "function": "write",
                        "class": "Shopware\\Core\\Framework\\DataAbstractionLayer\\Write\\EntityWriter",
                        "type": "->"
                    },
                    {
                        "file": "/xxxxxxxxxx/vendor/shopware/core/Framework/DataAbstractionLayer/VersionManager.php",
                        "line": 118,
                        "function": "insert",
                        "class": "Shopware\\Core\\Framework\\DataAbstractionLayer\\Write\\EntityWriter",
                        "type": "->"
                    },
                    {
                        "file": "/xxxxxxxxxx/vendor/shopware/core/Framework/DataAbstractionLayer/EntityRepository.php",
                        "line": 154,
                        "function": "insert",
                        "class": "Shopware\\Core\\Framework\\DataAbstractionLayer\\VersionManager",
                        "type": "->"
                    },
                    {
                        "file": "/xxxxxxxxxx/vendor/shopware/core/Framework/Api/Controller/ApiController.php",
                        "line": 916,
                        "function": "create",
                        "class": "Shopware\\Core\\Framework\\DataAbstractionLayer\\EntityRepository",
                        "type": "->"
                    },
                    {
                        "file": "/xxxxxxxxxxxx/vendor/shopware/core/Framework/Context.php",
                        "line": 207,
                        "function": "Shopware\\Core\\Framework\\Api\\Controller\\{closure}",
                        "class": "Shopware\\Core\\Framework\\Api\\Controller\\ApiController",
                        "type": "->"
                    },
                    {
                        "file": "/vxxxxxxxxxxx/vendor/shopware/core/Framework/Api/Controller/ApiController.php",
                        "line": 934,
                        "function": "scope",
                        "class": "Shopware\\Core\\Framework\\Context",
                        "type": "->"
                    },
                    {
                        "file": "/xxxxxxx/vendor/shopware/core/Framework/Api/Controller/ApiController.php",
                        "line": 778,
                        "function": "executeWriteOperation",
                        "class": "Shopware\\Core\\Framework\\Api\\Controller\\ApiController",
                        "type": "->"
                    },
                    {
                        "file": "/xxxxxxx/vendor/shopware/core/Framework/Api/Controller/ApiController.php",
                        "line": 454,
                        "function": "write",
                        "class": "Shopware\\Core\\Framework\\Api\\Controller\\ApiController",
                        "type": "->"
                    },
                    {
                        "file": "/xxxxxx/vendor/symfony/http-kernel/HttpKernel.php",
                        "line": 152,
                        "function": "create",
                        "class": "Shopware\\Core\\Framework\\Api\\Controller\\ApiController",
                        "type": "->"
                    },
                    {
                        "file": "/xxxx/vendor/symfony/http-kernel/HttpKernel.php",
                        "line": 74,
                        "function": "handleRaw",
                        "class": "Symfony\\Component\\HttpKernel\\HttpKernel",
                        "type": "->"
                    },
                    {
                        "file": "/xxxx/vendor/symfony/http-kernel/Kernel.php",
                        "line": 202,
                        "function": "handle",
                        "class": "Symfony\\Component\\HttpKernel\\HttpKernel",
                        "type": "->"
                    },
                    {
                        "file": "/xxxx/vendor/symfony/http-kernel/HttpCache/SubRequestHandler.php",
                        "line": 86,
                        "function": "handle",
                        "class": "Symfony\\Component\\HttpKernel\\Kernel",
                        "type": "->"
                    },
                    {
                        "file": "/xxx/vendor/symfony/http-kernel/HttpCache/HttpCache.php",
                        "line": 479,
                        "function": "handle",
                        "class": "Symfony\\Component\\HttpKernel\\HttpCache\\SubRequestHandler",
                        "type": "::"
                    },
                    {
                        "file": "/xxxxxx/vendor/symfony/http-kernel/HttpCache/HttpCache.php",
                        "line": 269,
                        "function": "forward",
                        "class": "Symfony\\Component\\HttpKernel\\HttpCache\\HttpCache",
                        "type": "->"
                    },
                    {
                        "file": "/xxxxxxx/vendor/symfony/http-kernel/HttpCache/HttpCache.php",
                        "line": 285,
                        "function": "pass",
                        "class": "Symfony\\Component\\HttpKernel\\HttpCache\\HttpCache",
                        "type": "->"
                    },
                    {
                        "file": "/xxxxxxx/vendor/symfony/http-kernel/HttpCache/HttpCache.php",
                        "line": 213,
                        "function": "invalidate",
                        "class": "Symfony\\Component\\HttpKernel\\HttpCache\\HttpCache",
                        "type": "->"
                    },
                    {
                        "file": "/xxxxxx/vendor/shopware/core/HttpKernel.php",
                        "line": 153,
                        "function": "handle",
                        "class": "Symfony\\Component\\HttpKernel\\HttpCache\\HttpCache",
                        "type": "->"
                    },
                    {
                        "file": "/xxxxxx/vendor/shopware/core/HttpKernel.php",
                        "line": 79,
                        "function": "doHandle",
                        "class": "Shopware\\Core\\HttpKernel",
                        "type": "->"
                    },
                    {
                        "file": "/xxxxx/public/index.php",
                        "line": 74,
                        "function": "handle",
                        "class": "Shopware\\Core\\HttpKernel",
                        "type": "->"
                    }
                ],
                "file": "xxx/vendor/shopware/core/Framework/DataAbstractionLayer/Write/DataStack/KeyValuePair.php",
                "line": 22
            }
        }
    ]
}

Cache habe ich geleert beim umstellen auf dev.
Danke!

@ayti, der Fehler wird durch ein ManyToOneAssociationField verursacht.
Bei dir kommen da die Adressen in Frage.

Sehe gerade auch, dass du den Adressen ein Array mit gibst. Die defaultBillingAddress und defaultShippingAddress sind keine Arrays sondern Entitäten.
Hier sollte es ausreichen die eckigen Klammern zu entfernen.

vg

@abdullah, danke! Genau daran hats gelegen, total vergessen das es eine Entität ist. Danke!