i need to understand following situation:

An external systems need to send a JSON Structure ( nearly similar than the magento default structure ) by using the web-api to import / update (POST/PULL) products.

The Structure differs to the default structure, cause the custom attributes are flat in the JSON and not in an array (custom_attributes).

So the default endpoint: (PUT) /rest/V1/products/:sku and the Interface for the method "save" \Magento\Catalog\Api\Data\ProductInterface can not understand the attributes.

Is it possible to reformat/normalize the JSON Structure before the Request reaches the initialisation of the \Magento\Catalog\Api\Data\ProductInterface ?

I also try the solution to create a custom endpoint:

<route url="/V1/itc-api/products" method="PUT">
        <service class="Itc\Api\Api\ProductsManagementInterface" method="save"/>
            <resource ref="Magento_Catalog::products" />

with a custom save Method:

public function save(\Itc\Api\Api\Data\ProductInterface $product, $saveOptions = false);

This Interface \Itc\Api\Api\Data\ProductInterface has all the flat get/set Methods like the custom JSON needs.

The Endpoint generally works, but magento throws an error:

Fatal error: Uncaught Error: Cannot instantiate interface Itc\Api\Api\Data\ProductInterface in /app/web/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:50

I think the better way is, to reformat the structure and use the original endpoint.

Thanks for help, Andre

  • Your question itself has an answer reformat the structure and use the original endpoint. :-) – Bilal Usean Feb 24 '19 at 4:55
  • I know :) ;) --- But do you know the point where i can do this ( which method to overwrite with a plugin ? ) – Andre Bubner Feb 24 '19 at 17:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.