Uploaded image for project: 'CiviCRM'
  1. CiviCRM
  2. CRM-7125

Location API does not always select the correct state when given a two-letter state abbreviation

    Details

    • Type: Bug
    • Status: Done/Fixed
    • Priority: Trivial
    • Resolution: Cannot Reproduce
    • Affects Version/s: 3.1.6
    • Fix Version/s: 3.2.6
    • Component/s: CiviCRM API
    • Labels:
      None

      Description

      When creating a location via the API, the API will occasionally associate a contact with the incorrect state when passing it a two-letter state abbreviation.

      Using the following code to generate the location results in an incorrect state association:

      // Insert the location record
      $address = array(
      'contact_id' => $contact['id'],
      'location_type' => 'Home',
      'street_address' => '123 test lane',
      'supplemental_address_1' => '',
      'city' => 'San Francisco',
      'state_province' => 'CA',
      'postal_code' => '94104',
      'country' => 'US',
      'is_primary' => 1,
      'is_billing' => 1,
      'email' =>'test@example.com'
      );
      $location_result = &civicrm_location_add( $address );

      This results in the state being marked as 'Ciego de Avila' - which incidentally has the same state abbreviation as California.

      We discovered this when changing Civi to display states as full state names rather than abbreviations.

      Also, if you do NOT include the country as a param (or pass a non-existent country as a param) to the location api, the result will be the country associated with the state Civi has selected for you. In the above case, if we had not passed in 'US' as the country, the API would set the contact's country as Cuba.

      The work-around solution is to determine the full state name and correct country independently of the API, and then pass those correct, full values to the API.

        Attachments

          Activity

            People

            • Assignee:
              kurund Kurund Jalmi
              Reporter:
              awjrichards Arthur Richards
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: