I want to extend some core function via the plugin and it should work in only when function call via REST API so in short my override things are only for REST API scope not for the web.

is this possible in Magento 2 and how can I write a plugin using di.xml which only call when request form API

Any idea? any help appreciate

2 Answers 2


You need to create plugin in di.xml inside etc/webapi_rest folder to call plugin only in REST API.

Example :

app/code/Vendor/Module/etc/webapi_rest/di.xml :

<?xml version="1.0"?>
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Catalog\Api\ProductCustomOptionRepositoryInterface">
        <plugin name="updateProductCustomOptionsAttributes" type="Magento\Catalog\Plugin\Model\Product\Option\UpdateProductCustomOptionsAttributes"/>

Add your plugin based on your requirement in di.xml.

  • it should be etc/webapi_rest/di.xml . I have verified this
    – usman
    Commented Dec 2, 2020 at 5:43

It should be app/code/Vendor/Module/etc/webapi_rest/di.xml

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.