---
title: "How to Get Custom Attribute Value Of Invoice Using Rest API?"
url: "https://magecomp.com/blog/custom-attribute-value-of-invoice-using-rest-api-in-magento-2/"
date: "2023-12-11T09:47:28+00:00"
modified: "2023-12-11T09:47:28+00:00"
author:
  name: "Dhiren Vasoya"
  url: "https://magecomp.com/"
categories:
  - "How To"
  - "Magento 2"
word_count: 529
reading_time: "3 min read"
summary: "Hello, Magento mates."
description: "Custom attributes help Magento admins collect valuable information from the invoice. Learn to get custom attribute values of invoice using REST API."
keywords: "How To, Magento 2"
language: "en"
schema_type: "Article"
related_posts:
  - title: "How to Add File in Shopify Store using Laravel?"
    url: "https://magecomp.com/blog/add-file-in-shopify-store-using-laravel/"
  - title: "Magento 2: How to Divide System Configuration Groups in Multiple .xml Files?"
    url: "https://magecomp.com/blog/magento-2-divide-system-configuration-groups-in-multiple-xml-files/"
  - title: "Magento 2: Show Out of Stock Product Price in Product Detail Page and Category Page"
    url: "https://magecomp.com/blog/magento-2-show-out-of-stock-product-price-in-product-detail-page-and-category-page/"
---

# How to Get Custom Attribute Value Of Invoice Using Rest API?

_Published: December 11, 2023_  
_Author: Dhiren Vasoya_  

![How to Get Custom Attribute Value Of Invoice Using Rest API in Magento 2](https://magecomp.com/blog/wp-content/uploads/2023/12/INVOICE-1024x512.webp)

Hello, Magento mates.

Welcome to MageComp’s [**Magento tutorials**](https://magecomp.com/blog/category/how-to-magento/).

Today, this tutorial is about getting a custom attribute value of an invoice for your Magento 2 store using REST API.

A custom attribute value of an invoice refers to additional, user-defined information that can be associated with an invoice. This feature allows you to extend the default set of attributes associated with an invoice by adding custom fields or values that meet specific business requirements.

## Steps to Get Custom Attribute Value
**Step 1 –**

First, we need to create an **extension_attributes.xml** file inside the etc folder ?

**app\code\Vendor\Extension\etc\**

Using the code given below ?

```
<?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="MagentoSalesApiDataInvoiceInterface">
        <attribute code="custom_attribute" type="string" />
         <attribute code="secondcustom_attribute" type="string" />
    </extension_attributes>
</config>
```

**Step 2 –**

Now, We need to create a **di.xml** file inside the etc folder.

**app\code\Vendor\Extension\etc\**

```
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="MagentoSalesApiInvoiceRepositoryInterface">
        <plugin name="invoiceInformationUpdate" type="VendorExtensionPluginApiInvoiceRepository" />
    </type>
</config>
```

**Step 3 –**

Then, we need to create the **InvoiceRepository.php** file inside the Plugin folder.

**app/code/Vendor/Extension/Plugin/Api/**

```
<?php
namespace VendorExtensionPluginApi;

use MagentoSalesApiDataInvoiceExtensionFactory;
use MagentoSalesApiDataInvoiceInterface;
use MagentoSalesApiDataInvoiceSearchResultInterface;

class InvoiceRepository
{
    /**
     * @var InvoiceExtensionFactory
     */

     private $feeDataFields = [
        'custom_attribute',
        'secondcustom_attribute'

    ];

    protected $extensionFactory;

    public function __construct(InvoiceExtensionFactory $extensionFactory)
    {
        $this->extensionFactory = $extensionFactory;
    }

    public function afterGet(
        MagentoSalesApiInvoiceRepositoryInterface $subject,
        InvoiceInterface $invoice
    ) {
        $extensionAttributes = $invoice->getExtensionAttributes();
        $extensionAttributes = $extensionAttributes ? $extensionAttributes : $this->extensionFactory->create();

        foreach ($this->feeDataFields as $key) {
            $data = $invoice->getData($key) ? $invoice->getData($key) : '0.0000';
            $extensionAttributes->setData($key, $data);
        }
            $invoice->setExtensionAttributes($extensionAttributes);


        return $invoice;
    }

    public function afterGetList(MagentoSalesApiInvoiceRepositoryInterface $subject, InvoiceSearchResultInterface $searchResult)
    {
        $invoices = $searchResult->getItems();

        foreach ($invoices as &$invoice) {
            $extensionAttributes = $invoice->getExtensionAttributes();
            $extensionAttributes = $extensionAttributes ? $extensionAttributes : $this->extensionFactory->create();

        foreach ($this->feeDataFields as $key) {

            $data = $invoice->getData($key) ? $invoice->getData($key) : '0.0000';
            $extensionAttributes->setData($key, $data);
        }
        $invoice->setExtensionAttributes($extensionAttributes);
        }

        return $searchResult;
    }
}
```

**Step 4 –**

Now, we need to run

```
php bin/magento setup:upgrade
```

You can see the values ​​of the custom attributes from the URL below.

**BASE_URL/rest/all/V1/invoices/increment_id**

## Conclusion
Custom attribute values of invoices can be beneficial for Magento 2 store admins to display extra information related to an invoice, providing a flexible added feature for multiple Magento store needs and business scenarios.

These attributes can be managed and configured through the Magento 2 admin panel, allowing merchants to tailor their invoicing system to suit their unique needs.

This was it. If you have any queries related to this tutorial or any other Magento feature, kindly [**contact us**](https://magecomp.com/contact), or hire our [**Magento developers**](https://magecomp.com/hire-magento-developer.html) to solve your queries.

[![MageComp Official Facebook Group](https://magecomp.com/blog/wp-content/uploads/2022/07/GIF-image-of-MageComp-Official-Group.gif)](https://www.facebook.com/groups/magecomp)

**Happy Coding!!!**


---

_View the original post at: [https://magecomp.com/blog/custom-attribute-value-of-invoice-using-rest-api-in-magento-2/](https://magecomp.com/blog/custom-attribute-value-of-invoice-using-rest-api-in-magento-2/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-07-07 14:36:32 UTC_  
