Good day to you, Amasty reader!

As everyone knows, to maintain fruitful business cooperation with your customers and promote the necessary products to them, you, as a business owner, should know more about your current clients.

The perfect way to gain these goals in your Magento 2 is to add Customer Attributes.

Today, I’m going to show you how to edit customer attributes programmatically and via our product – Customer Attributes for Magento 2 extension.

 Also, to improve your customer service try out this Magento 2 Order Number extension and reduce the risk of messing order numbering in a multi-language store.

This extension allows you to create a limitless number of attributes and get to know your customers better. To create a new attribute, go to Customers>Customer Attributes>Manage Attributes and click on the Add New Attribute button. Here is a list of 11 input types you may use for the purpose:

customer-attributes-magento-2-input-types-amasty

Each attribute, except the Single file Upload, can be added to the Registration and Checkout pages.
Moreover, every newly created characteristic can be shown on the Order View Page and Customer Information page, as well as in Customers and Orders grids in the backend:

customer-attributes-magento-2-customers-infromation-amasty

customer-attributes-magento-2-orders-information-amasty

Also, all the attributes are shown on a separate grid where you can find information on the type, sort order, as well as about the page where each of the labels is displayed. Moreover, you can edit attributes right from this grid:

customer-attributes-magento-2-separate-grid-amasty

The big advantage of the extension is a possibility to hide attribute fields that were filled in before. Say, a user is registered on your website and has filled out the extra info forms. Then this client won’t have to fill these fields again during the checkout process. This helps you make the shopping process more convenient and improve customer experience.

At the same time, we highly recommend using the Attributes extension together with Customer Group Catalog for Magento 2. Since there is a Customer group selector attribute type, this allows you separating clients during the registration automatically.

Another key feature of the module is a possibility to create attribute relations. It is a simple way to avoid overloading a website page, and at the same time, to collect useful information about buyers for future beneficial cooperation.

 Note: See the user guide to learn how to manage attribute relations correctly.

Get to know your clients better to meet their individual needs and increase revenue!

How to modify a created customer attribute programmatically in Magento 2?

As you know, Magento 2 supports REST (Representational State Transfer) and SOAP (Simple Object Access Protocol) like it was in previous Magento versions. Therefore, you can easily manage customer attributes programmatically via API to collect valuable buyer information.

Follow the 5 steps to manage a created customer attribute programmatically:

Step 1: Extend current permissions to administrative

  • Open Magento 2 frontend and put ‘swagger’ at the end of the URL line:

customer-attributes-magento-2-swagger-amasty

  • To widen permissions, please, find IntegrationAdminToken:

customer-attributes-magento-2-wide-permissions-amasty

Step 2: Enter the backend credentials

  • Open an example on the right side of the window:

customer-attributes-magento-2-example-blog

  • and fill in your username and password for the backend panel:

customer-attributes-magento-2-credentials-blog

Step 3: Get and use the API key

  • When everything’s ready, you will get the API key:

customer-attributes-magento-2-api-key-amasty

  • Enter the key here:

customer-attributes-magento-2-use-api-key-amasty

Step 4: Edit a customer attribute

  • As you have already received the admin permissions, you are able to edit customer attributes. To do this, please, find customerCustomerRepositoryV1:

customer-attributes-magento-2-customer-id-amasty

  • To find a client, please, open Get tab and enter the Customer ID:

customer-attributes-magento-2-customer-idjpg-amasty

  • and click on the Try it out button. For me, the ID is ‘1’:

customer-attributes-magento-2-1-amasty

  • As a result, you will receive a customer ‘Response body’. Just copy it and go to the next step:

customer-attributes-magento-2-response-body-amasty

Step 5: Fill in the customer ID and body

  • Open the /V1/customers/{customerId} tab and paste customer body here:

customer-attributes-magento-2-customer-body-amasty

  • Please, do not forget to enter “customer” in this area (it’s marked in green).

Bonus: Magento 2 ‘Test’ customer attribute as an example

Leave your email and we’ll send you a FREE instruction on editing a customer attribute with screenshots and comments. 

Wrap-up

By following the simple steps, you can edit your customer attributes in Magento 2 programmatically. I, in turn, hope this article will help you spend less time on updating created customer attributes and allow you to get more benefits from using our Magento 2 Customer Attributes.

Best of luck and stay tuned!