1

I'm using civimigrate for a pretty intense migration into CiviCRM and I have hit something of a puzzler.

I have a table with addresses that I am matching to contacts, but I cannot seem to find a way to map a state abbreviation (AL,MD,FL) to an id for the api.

I was hoping to find something in the API explorer to paste into my import, but I can't seem to find out where the API calls for translating state abbreviations into ids live.

Any ideas?

2 Answers 2

2

Try this:

$result = civicrm_api3('StateProvince', 'get', array(
  'sequential' => 1,
  'abbreviation' => array('IN' => array("AL", "MD", "FL")),
  'country_id' => 1228,
));

Note that you should specify country_id as state abbreviations are not globally unique.

0

Thanks for the response. I ended up doing something similar before seeing your response by creating a pre-processed source table with raw SQL queries. My actual use case involved a few thousand entries, not all of them US based.

I split up my address records into US/Non-US, then joined the US table on LIKE where country_id=1228, and the non-us table on LIKE where country_id <> 1228, ignoring state/province for non-us records, then recombined them both, now with proper country and state/province ids.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.