I followed below link to update address using address id
Update customer address using address id in magento 2
I am getting this error upon executing this code
protected $addressRepository;
public function __construct(
\Magento\Customer\Api\AddressRepositoryInterface $addressRepository
) {
$this->addressRepository = $addressRepository;
}
public function changeAddress($addressId)
{
$AddressId = 381993;
if(isset($AddressId) && $AddressId !=''){
try{
$address = $this->addressRepository->getById($AddressId);
$address->setFirstname('test');
$address->setLastname('test');
$address->setCountryId('GB');
$address->setRegion()->setData(array('region' => 'test'));
$address->setPostcode('t9 1rd');
$address->setCity('test');
$this->addressRepository->save($address);
}catch(\Exception $e){
print_r($e->getMessage());
}
}
}
I am getting this error upon using this code
"message": "Invalid value of \"1\" provided for the regionId field.",
I tried
$address->setRegion(); also same error again
What is the mistake in above code? Please anyone help me.