Shopware /api/propertyGroups 500 status

Hello,

I am Java developer. I would like to ask about /propertyGroups endpoint returning status 500 Internal Server Error.

The request is {ShopwareAddress}/api/propertyGroups/  POST  with header application/json

and request body in JSON format - never empty, always at least name parameter e.g.

{

    “name”: “shops”

}

The library I use to create the request in Java is com.sun.jersey

The problem appears only for Shopware version 5.6.2, for Shopware version 5.2.16 it works fine - request sent to both is the same.

Moreover, I used POSTMAN for testing and the same request works fine and returns status 201 Created.

Example entries in log file:

{IP} - - [15/Jun/2020:13:56:28 +0200] “POST /api/propertyGroups/ HTTP/1.1” 500 - “-” “Java/11.0.3”

{IP} - user [15/Jun/2020:13:35:28 +0200] “POST /api/propertyGroups/ HTTP/1.1” 201 90 “-” “PostmanRuntime/7.25.0”

I would appreciate any help since I cannot resolve this myself.

Thanks in advance.

 

Best regards,

Michael

 

Hallo @ShopProgrammerWare‍,

can you post the php error entries from the log Datei with the full stack trace, so we can help you.

VG,

image

Tel.: +49 755 - 183 990 00 | E-Mail: info@enbit.de | Web: http://enbit.de/

Hallo @ahmadsaad‍

Thanks for quick answer.

I think you are referring to error logs I can find in var/www/html/shopware{version}/shopware_error.log

 

This is example:

[Mon Jun 15 13:56:28.257277 2020] [php7:error] [pid 23555] [client HIDDEN IP] PHP Fatal error:  Uncaught TypeError: Argument 1 passed to Shopware\Models\Property\Group::setOptions() must be of the type array, null given, called in /var/www/html/shopwarece/engine/Shopware/Components/Model/ModelEntity.php on line 53 and defined in /var/www/html/shopwarece/engine/Shopware/Models/Property/Group.php:245
Stack trace:
#0 /var/www/html/shopwarece/engine/Shopware/Components/Model/ModelEntity.php(53): Shopware\Models\Property\Group->setOptions(NULL)
#1 /var/www/html/shopwarece/engine/Shopware/Components/Api/Resource/PropertyGroup.php(108): Shopware\Components\Model\ModelEntity->fromArray(Array)
#2 /var/www/html/shopwarece/engine/Shopware/Controllers/Api/PropertyGroups.php(80): Shopware\Components\Api\Resource\PropertyGroup->create(Array)
#3 /var/www/html/shopwarece/engine/Library/Enlight/Controller/Action.php(192): Shopware_Controllers_Api_PropertyGroups->postAction()
#4 /var/www/html/shopwarece/engine/Library/Enlight/Controller/Dispatcher/Default.php(478): Enlight_Controller_Action->dispatch(‘postAction’)
#5 /va in /var/www/html/shopwarece/engine/Shopware/Models/Property/Group.php on line 245

 

Best Regards,

Michael
 

Hallo @ShopProgrammerWare‍,

by your example Request you have just ‚name‘ key there are no ‚options‘ key , is this correct??

the function fromArry call only the set functions for the request array keys.

so the Q hier, from where came this ‚options‘ key??

VG,

image

Tel.: +49 755 - 183 990 00 | E-Mail: info@enbit.de | Web: http://enbit.de/

You need to pass an empty array with name “options”

Hello,

Thanks for your help!

You are right, the cause is NULL parameter as “options”.

My mistake is caused by the fact that this worked for shopware version 5.2.16 (NULL as “options”), so I was just straight up serializing object to JSON and sending.
And as you say in 5.6.2 version in shopware it ends with status 500.

All is clear now.

Best Regards,

Michael

Ich möchte API aufrufen zum Erstellen/update [POST / PUT] von propertygroup mit Optionsarray aufrufen, aber ich habe 500 Fehler. Mein error log sagt

"PHP message: PHP Fatal error: Uncaught TypeError: Argument 1 passed to Shopware\Models\Property\Group::addOption() must be an instance of Shopware\Models\Property\Option, array given, called in /var/www/domain/engine/Shopware/Models/Property/Group.php on line 267 and defined in /var/www/domain/engine/Shopware/Models/Property/Group.php:250

und mein api params ist folgendes:-

www.localhost/api/propertyGroups/5

{

    "id": 5,

    "name": "test property",

    "position": 0,

    "comparable": false,

    "sortMode": 0,

    "options": [

        {

            "name": "testPropertyOption",

            "filterable": true

        }

    ],

    "attribute": null

}

wie ist die richtige api call für herstellen oder actulizieren die propertyGroupeOptions