I'm trying to add a new customer address using Magento 2 REST API in C#. I'm using POST /V1/customers/:id. I keep getting the below error. Where do I find the regionId? Is there another API I can use to get it because I can't easily query the Magento database everytime.
{
"message":"%fieldName is a required field.",
"parameters":{
"fieldName":"regionId"
}
}
Here is the JSON request:
{
"customer":{
"email":"customer@example.com",
"firstname":"John",
"lastname":"Doe",
"websiteId":"1",
"addresses":[
{
"customer_id":"1",
"firstname":"John",
"lastname":"Doe",
"company":"ABC Manufacturing",
"telephone":"555-555-5555",
"city":"Boston",
"region":"Massachusetts",
"postcode":"02115",
"country_id":"US",
"street":[
"123 Main Street",
"PO Box 321"
]
}
]
}
}
Best Answer
You will get all the customer address related attributes by calling below url :
You will get the all the address related attributes name and its values like state , country etc.
Their you will find RegionId for your region ( Example : Massachusetts = 32) Where 32 is region Id.
At last pass below parameters to add customer address with same url.
It will update address of customer and your error will resolved.
Refer this link for all api details - http://devdocs.magento.com/guides/v2.0/rest/list.html or https://r-martins.github.io/m1docs/guides/v2.4/rest/list.html