I have created a custom attribute of type customer_address and I would like to have the API to return me the value as an attribute when I call the API to receive an order.


private function upgradeExternalKeyAddressCustomer($customerSetup)
    $attributesInfo = [
        'mod_external_key'  => [
            'label' => __('External Key'),
            'type' => 'varchar',
            'input' => 'text',
            'position' => 200,
            'visible' => 1,
            'required' => 0,
            'system' => 0,

    foreach ($attributesInfo as $attributeCode => $attributeParams) {
        $customerSetup->addAttribute('customer_address', $attributeCode, $attributeParams);

    foreach ($attributesInfo as $attributeCode => $attributeParams) {

        $attribute = $customerSetup->getEavConfig()->getAttribute('customer_address', $attributeCode);
            ['adminhtml_customer_address', 'customer_address_edit', 'customer_register_address']

How to do this?

1 Answer 1


try this blog it will return your custom attribute in order api response https://www.atwix.com/development/adding-custom-attribute-to-api-response-in-magento-2/

  • 1
    This tutorial is about extension attributes. How can I do that for an attribute outside of extension attributes ? Jul 6, 2020 at 15:07

Your Answer

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

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