Address API incorrectly sets state_province_id if multiple countries have same state name / abbreviation
Replicable on dmaster.demo
The Address API is not taking into account the country_id when figuring the state_province_id when given the state name or state abbreviation, even if country_id is provided...
Example:
$result = civicrm_api3('Address', 'create', [
'contact_id' => 206,
'location_type_id' => "Main",
'city' => "Baltimore",
'state_province_id' => "Maryland",
'country_id' => 1228,
]);
Output:
{
"is_error": 0,
"version": 3,
"count": 1,
"id": 193,
"values": {
"193": {
"id": "193",
"contact_id": "206",
"location_type_id": "3",
"is_primary": "1",
"is_billing": "0",
"city": "Baltimore",
"state_province_id": "3497",
"country_id": "1228",
"manual_geo_code": "0"
}
}
}
Notice the state_province_id is 3497, which is Maryland, Liberia. It should be 1019.
This happens regardless of which countries are enabled in the Localization settings. It also does not respect the "default country" setting, if the country_id is not provided.