---
title: "How to use event only in Web API Rest and Web API Soap?"
url: "https://dolphinwebsolution.com/how-to-use-event-only-in-web-api-rest-and-web-api-soap"
date: "2021-03-26T04:43:25+05:30"
modified: "2023-08-24T09:31:43+05:30"
author:
  name: "Jigar Patel"
categories:
  - "Magento"
word_count: 318
reading_time: "2 min read"
summary: "While SOAP and REST share similarities over the HTTP protocol. In this article, we will discuss Web API REST and Web API SOAP.





webapi_rest
&lt;module-dir&gt;/etc/webapi_rest/events.xml..."
description: "While SOAP and REST share similarities over the HTTP protocol. In this article, we will discuss Web API REST and Web API SOAP."
keywords: "Web API Rest,Web API Soap,events,extension_attributes, Magento"
language: "en"
schema_type: "Article"
related_posts:
  - title: "Magento: How to implement custom indexing within flash time?"
    url: "https://dolphinwebsolution.com/magento-how-to-implement-custom-indexing-within-flash-time"
  - title: "How to Customize Product Page Layout in Magento 2"
    url: "https://dolphinwebsolution.com/how-to-customize-product-page-layout-in-magento-2"
  - title: "How Much Ecommerce Website Development Cost in India?"
    url: "https://dolphinwebsolution.com/blog/cost-to-develop-ecommerce-website-in-india/"
---

# How to use event only in Web API Rest and Web API Soap?

_Published: March 26, 2021_  
_Author: Jigar Patel_  

![](https://dolphinwebsolution.com/wp-content/uploads/2023/02/webapi_rest-and-webapi_soap-1024x512.jpg)

While SOAP and REST share similarities over the HTTP protocol. In this article, we will discuss Web API REST and Web API SOAP.

| webapi\_rest | <module-dir>/etc/webapi\_rest/events.xml | An observer will be executed in the Web API REST area only. |
|---|---|---|
| webapi\_soap | <module-dir>/etc/webapi\_soap/events.xml | An observer will be executed in the web API SOAP area only. |

**Step 1:** You need to create a file in your [custom module](https://dolphinwebsolution.com/add-custom-css-js-to-custom-page-layout-magento-2) **app/code/{vendor}/{module}/etc/extension\_attributes.xml**

```
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
<extension_attributes for="Magento\Sales\Api\Data\OrderInterface">
     <attribute code="seller" type="string" />
</extension_attributes>
</config>
```

**Step 2:** Create observe.In this step, you need to create observer for event ‘sales\_order\_load\_after’ through the file **{vendor}/{module}/etc/webapi\_rest/events.xml**

```
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="sales_order_load_after">
    <observer name="sales_order_load_order_attribute" instance="{Vendor}\{Module}\Observer\Sales\OrderLoadAfter" />
</event>
</config>
```

**Step 3:** Create a file to handle this event.Create a file **{vendor}/{module}/Observer/Sales/OrderLoadAfter.php** to handle the event ‘**sales\_order\_load\_after**’ which is declared above

```
<?php
namespace {Vendor}\{Module}\Observer\Sales;
use Magento\Framework\Event\ObserverInterface;
class OrderLoadAfter implements ObserverInterface
{
public function execute(\Magento\Framework\Event\Observer $observer)
{
    $order = $observer->getOrder();
    $extensionAttributes = $order->getExtensionAttributes();
    if ($extensionAttributes === null) {
        $extensionAttributes = $this->getOrderExtensionDependency();
    }

    $seller='test';//add your custom logic for seller.
    $extensionAttributes->setSeller($seller);
    $order->setExtensionAttributes($extensionAttributes);
}
private function getOrderExtensionDependency()
{
    $orderExtension = \Magento\Framework\App\ObjectManager::getInstance()->get(
        '\Magento\Sales\Api\Data\OrderExtension'
    );
    return $orderExtension;
}
}
```


---

_View the original post at: [https://dolphinwebsolution.com/how-to-use-event-only-in-web-api-rest-and-web-api-soap](https://dolphinwebsolution.com/how-to-use-event-only-in-web-api-rest-and-web-api-soap)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-08-26 06:54:28 UTC_  
