Answers.Body: <p>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.</p>
  
  <p>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 &lt;> 1228, ignoring state/province for non-us records, then recombined them both, now with proper country and state/province ids. </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-04T14:49:09.820Z
Answers.LastActivityDate: 2017-10-04T14:49:09.820Z
Answers.UserDisplayName: Derek
Answers.Body: <p>Try this:</p>
  
  <pre><code>$result = civicrm_api3('StateProvince', 'get', array(
    'sequential' =&gt; 1,
    'abbreviation' =&gt; array('IN' =&gt; array("AL", "MD", "FL")),
    'country_id' =&gt; 1228,
  ));
  </code></pre>
  
  <p>Note that you should specify <code>country_id</code> as state abbreviations are not globally unique.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-28T14:19:46.223Z
Answers.LastActivityDate: 2017-09-28T14:19:46.223Z
Answers.UserDisplayName: Aidan
Body: <p>I'm using civimigrate for a pretty intense migration into CiviCRM and I have hit something of a puzzler. </p>
  
  <p>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. </p>
  
  <p>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. </p>
  
  <p>Any ideas?</p>
  
Tags: <import><data-import>
Title: CiviCRM API V3 : Translate Two Digit State to State_Province_id?
ThreadText: # CiviCRM API V3 : Translate Two Digit State to State_Province_id?
  
  (Asked by: username_0 on 2017-09-26)
  
  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?
  
  **Tags:** import, data-import
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2017-10-04. Score: 0 | Accepted answer
  
  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.
  
  
  ---
  
  ### Answer by username_1 on 2017-09-28. Score: 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.
  
  
  ---
  
  