Update Customer Attributes Value via Magento 2 REST API

I am explaining to you to update customer attributes value based on the customer id through rest API in Magento 2.

When a customer orders a product in the Magento store, then payment status get changes, and if the customer has come after registering, then his account status also changes.

So to change the value of the attributes of the customer through Magento 2 REST API it is necessary to hit its correct endpoint.

The customer needs to send their payload details to update the custom attribute value.

The status is updated only by the correct value in the body which is given below.

The same API is also used to add or change the data of the attribute of the customer based on the customer id.

Admin > Customer > Customer Account > Account Information

Update Customer Attributes Value
Customer Attributes Change Status

 

 

Change Customer Account Status in Magento 2

If you want to change any value of a customer's account information like want to change the name, want to change the last name, change email id, change the date of birth, change gender or change address, change order status.

To change all these data through Magento 2 default rest api you can get detailed information by add/update customer data by rest api.

 

Update Customer Attributes Value REST API

The customer attribute whose value is to be changed can be changed by the endpoint given below.

First of all, by entering that attribute in the body, you have to hit it. Then you will get the changed value in the response.

store_url://domin_name/rest/V1/customers/customerID

Endpoint:

https://wishusucess.com/rest/V1/customers/111

Method: PUT

Header:

  • Authorization: Bearer admin_token
  • Content-Type: Application/Json

Body:

{ "customer": {
"custom_attributes": [
{
"attribute_code": "customer_account_status",
"value": "1"
},
{
"attribute_code": "payment_status",
"value": "1"
}
]
}
}

Update Attributes API
Update Attributes on Postman

 

Response:

{
"id": 111,
"group_id": 4,
"default_billing": "281",
"default_shipping": "281",
"created_at": "2021-12-24 12:03:06",
"updated_at": "2022-02-22 13:19:30",
"created_in": "Default Store View",
"email": "cs.hemantsingh@gmail.com",
"firstname": "Hemant",
"lastname": "Singh",
"middlename": "Singh",
"gender": 0,
"store_id": 1,
"website_id": 1,
"addresses": [
{
"id": 217,
"customer_id": 111,
"region": {
"region_code": "UP",
"region": "Uttar Pradesh",
"region_id": 566
},
"region_id": 56,
"country_id": "IN",
"street": [
"Noida",
"Noida"
],
"telephone": "1234567890",
"postcode": "201301",
"city": "Noida",
"firstname": "Hemant",
"lastname": "Singh"
},
{
"id": 281,
"customer_id": 111,
"region": {
"region_code": "UP",
"region": "Uttar Pradesh",
"region_id": 566
},
"region_id": 566,
"country_id": "IN",
"street": [
"PMO Apartment"
],
"telephone": "08197565002",
"postcode": "201301",
"city": "Noida",
"firstname": "Hemant",
"lastname": "Singh",
"default_shipping": true,
"default_billing": true
}
],
"disable_auto_group_change": 0,
"extension_attributes": {
"is_subscribed": false
},
"custom_attributes": [
{
"attribute_code": "customer_account_status",
"value": "1"
},
{
"attribute_code": "payment_status",
"value": "1"
}
]
}

 

Read more: Magento 2.4 Installation Guide: How to Install Magento 2.4.2

 

Conclusion:

You can use this magento 2 rest api to update any kind of customer-related details or value of the custom attributes.

Through this, you can change the payment status, if you want, you can change the account status for the customer.

To update its name, email id, etc. details, by this you can update the value of any customer parameter.

 

Recommended Posts:

Add/Update Many Customer Address REST API in Magento 2

Add Multiple Customer Address via Magento 2 REST API