API | Eigenschaften die unter Spezifikationen gelistet sind auf weiteren Artikel anwenden

Wie füge ich bestehende Spezifikationen zu einem anderen Artikel über die API hinzu?

Hier mein Versuch:

       {
            "name": "TESTARTICLEV1",
            "productNumber": "TESTV1",
            "stock": 500,
            "taxId": "7b5b2d226c7b4b7bb5239027680b3b1b",
            "price": [
                {
                    "currencyId": "b7d2554b0ce847cd82f3ac9bd1c0dfca",
                    "net": 199.0,
                    "gross": 245.0,
                    "linked": false,
                    "listPrice": null,
                    "extensions": []
                }
            ],
            "propertyIds": [
                    "07bfb0010ddb43d085e3d163f925676a",
                    "09107202790b455b97524749166fd529",
                    "0bdac2157b4e433b9c9b236331c959f7",
                    "4dff80702390448f87b3b5dec4aa8e22",
                    "5903671c791f46d3b1d1a8c3d42f04d4",
                    "6c3f900e0d3b44e6a292cca291adb595",
                    "866b146f88134088b1c62b3cef892bb7",
                    "8b16a3e8c0314598b7285ec30ffc836a",
                    "94110b6d560b49aa9af7cc6926934f55",
                    "9b976738889a4e8281a1d2e0aa252d38",
                    "a577a6d1dbb2435c8d2ec255aa590ad2",
                    "a598c0c6209e4d60bc8895b55eb9f279",
                    "a5c0fe66368b4ddda523950d28a6275a",
                    "afb86ff47810467bba49d559a78fdbc5",
                    "c0adb2e05ffa4926be09c5c077682410",
                    "db35dcd5ec954f6f9d08a3602d318d8e",
                    "f261eee97fae4120a00f6d6a9e7c8327"
                ]
                
        }

Ich bekomme folgenden Fehler wenn ich den API Call durchführe:

{
    "errors": [
        {
            "code": "FRAMEWORK__WRITE_CONSTRAINT_VIOLATION",
            "status": "400",
            "detail": "This field is write-protected.",
            "template": "This field is write-protected.",
            "meta": {
                "parameters": [
                    "crud",
                    ""
                ]
            },
            "source": {
                "pointer": "/0/propertyIdspropertyIds"
            }
        }
    ]
}

Freue mich über jede Antwort.

Meinst du die Eigenschaften unter Inhalt => Eigenschaften und dann eine Ausprägung davon?
Ich meine „propertyIds“ ist falsch, es müsste nur „properties“ heißen.

@joerg.luebbe Ich meine wenn du im webinterace unter Produkte dann den Reiter Spezifikationen auswählt und dann weiter unten bei Eigenschaften.

Ich habe den Code abgeändert aus „propertyIds“ habe ich „properties“ gemacht. Erhalte jedoch folgenden Fehler:

{
    "errors": [
        {
            "code": "0",
            "status": "500",
            "title": "Internal Server Error",
            "detail": "Argument 2 passed to Shopware\\Core\\Framework\\Api\\Converter\\ApiVersionConverter::convertPayload() must be of the type array, string given, called in /var/www/clients/client1/web2/web/vendor/shopware/core/Framework/Api/Converter/ApiVersionConverter.php on line 66",
            "meta": {
                "trace": [
                    {
                        "file": "/var/www/clients/client1/web2/web/vendor/shopware/core/Framework/Api/Converter/ApiVersionConverter.php",
                        "line": 66,
                        "function": "convertPayload",
                        "class": "Shopware\\Core\\Framework\\Api\\Converter\\ApiVersionConverter",
                        "type": "->"
                    },
                    {
                        "file": "/var/www/clients/client1/web2/web/vendor/shopware/core/Framework/Api/Controller/ApiController.php",
                        "line": 905,
                        "function": "convertPayload",
                        "class": "Shopware\\Core\\Framework\\Api\\Converter\\ApiVersionConverter",
                        "type": "->"
                    },
                    {
                        "file": "/var/www/clients/client1/web2/web/vendor/shopware/core/Framework/Api/Controller/ApiController.php",
                        "line": 776,
                        "function": "executeWriteOperation",
                        "class": "Shopware\\Core\\Framework\\Api\\Controller\\ApiController",
                        "type": "->"
                    },
                    {
                        "file": "/var/www/clients/client1/web2/web/vendor/shopware/core/Framework/Api/Controller/ApiController.php",
                        "line": 452,
                        "function": "write",
                        "class": "Shopware\\Core\\Framework\\Api\\Controller\\ApiController",
                        "type": "->"
                    },
                    {
                        "file": "/var/www/clients/client1/web2/web/vendor/symfony/http-kernel/HttpKernel.php",
                        "line": 157,
                        "function": "create",
                        "class": "Shopware\\Core\\Framework\\Api\\Controller\\ApiController",
                        "type": "->"
                    },
                    {
                        "file": "/var/www/clients/client1/web2/web/vendor/symfony/http-kernel/HttpKernel.php",
                        "line": 79,
                        "function": "handleRaw",
                        "class": "Symfony\\Component\\HttpKernel\\HttpKernel",
                        "type": "->"
                    },
                    {
                        "file": "/var/www/clients/client1/web2/web/vendor/symfony/http-kernel/Kernel.php",
                        "line": 199,
                        "function": "handle",
                        "class": "Symfony\\Component\\HttpKernel\\HttpKernel",
                        "type": "->"
                    },
                    {
                        "file": "/var/www/clients/client1/web2/web/vendor/symfony/http-kernel/HttpCache/SubRequestHandler.php",
                        "line": 85,
                        "function": "handle",
                        "class": "Symfony\\Component\\HttpKernel\\Kernel",
                        "type": "->"
                    },
                    {
                        "file": "/var/www/clients/client1/web2/web/vendor/symfony/http-kernel/HttpCache/HttpCache.php",
                        "line": 477,
                        "function": "handle",
                        "class": "Symfony\\Component\\HttpKernel\\HttpCache\\SubRequestHandler",
                        "type": "::"
                    },
                    {
                        "file": "/var/www/clients/client1/web2/web/vendor/symfony/http-kernel/HttpCache/HttpCache.php",
                        "line": 267,
                        "function": "forward",
                        "class": "Symfony\\Component\\HttpKernel\\HttpCache\\HttpCache",
                        "type": "->"
                    },
                    {
                        "file": "/var/www/clients/client1/web2/web/vendor/symfony/http-kernel/HttpCache/HttpCache.php",
                        "line": 283,
                        "function": "pass",
                        "class": "Symfony\\Component\\HttpKernel\\HttpCache\\HttpCache",
                        "type": "->"
                    },
                    {
                        "file": "/var/www/clients/client1/web2/web/vendor/symfony/http-kernel/HttpCache/HttpCache.php",
                        "line": 211,
                        "function": "invalidate",
                        "class": "Symfony\\Component\\HttpKernel\\HttpCache\\HttpCache",
                        "type": "->"
                    },
                    {
                        "file": "/var/www/clients/client1/web2/web/vendor/shopware/core/HttpKernel.php",
                        "line": 178,
                        "function": "handle",
                        "class": "Symfony\\Component\\HttpKernel\\HttpCache\\HttpCache",
                        "type": "->"
                    },
                    {
                        "file": "/var/www/clients/client1/web2/web/vendor/shopware/core/HttpKernel.php",
                        "line": 81,
                        "function": "doHandle",
                        "class": "Shopware\\Core\\HttpKernel",
                        "type": "->"
                    },
                    {
                        "file": "/var/www/clients/client1/web2/web/public/index.php",
                        "line": 77,
                        "function": "handle",
                        "class": "Shopware\\Core\\HttpKernel",
                        "type": "->"
                    }
                ],
                "file": "/var/www/clients/client1/web2/web/vendor/shopware/core/Framework/Api/Converter/ApiVersionConverter.php",
                "line": 31
            }
        }
    ]
}

Das ist schon mal besser, und der Fehler den er dir gibt besagt dass er ein Array erwartet, er aber Strings bekommt. Dementsprechend müsste jede ID die du in dem Properties Array übergibst wiederrum ein Array sein. Also so:

properties: [
// Assoz. Array für erste ID 
 {"id" : "dh39d9s99d...."}, 
// Assoz. Array für zweite ID
 {"id" : "d33999aa9a9a..."}
]

Probiers mal so und guck dir hier mal bei Many To Many Associations den 3. Punkt an wo ein Produkt mit Categories verknüpft wird.

@joerg.luebbe Wow, vielen vielen Dank. Es funktioniert.

Schön, guck dir die API Doku gern mal weiter an, da kann man viel lernen. Auch die Bulk Operationen über den action/sync Endpoint sind sehr gut und performant. Dort könntest du z.B. mehreren Produkten gleichzeitig mehrere Eigenschaften zuweisen.