1

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.

Attribute:

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);
        $attribute->setData(
            'used_in_forms',
            ['adminhtml_customer_address', 'customer_address_edit', 'customer_register_address']
        );
        $attribute->save();
    }
}

How to do this?

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/

| improve this answer | |
  • This tutorial is about extension attributes. How can I do that for an attribute outside of extension attributes ? – Gustavo Ulyssea Jul 6 at 15:07

Your Answer

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

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