2

When am getting some entity using API, it's returning id reference only not the actual value.

eg: $result = civicrm_api3('Address', 'get', array( 'sequential' => 1, 'conatct_id' => 10 )); Output:

enter preformatted text here
{
   "is_error":0,
   "version":3,
   "count":1,
   "id":6601,
   "values":[{
      "id":"6601",
      "contact_id":"1",
      "location_type_id":"1",
      "is_primary":"1",
      "is_billing":"0",
      "street_address":"#275, xyz",
      "city":"abcd",
      "state_province_id":"9300",
      "postal_code":"560082",
      "country_id":"1101",
      "geo_code_1":"12.7930129",
      "geo_code_2":"77.5051501",
      "manual_geo_code":"0"
   }]
}

In this example, state_province_id,country_id is returned. Is it possible to get state name and country name in the result?

Thanks in advance

3

This is possible in the "trunk" version of CiviCRM, and will be available in CiviCRM 4.7.15, releasing January 4, 2017. Earlier versions of CiviCRM don't have a StateProvince API.

Using the "Join" feature of the API, you can pull in fields from related tables. See my screenshot for how I would construct an address pulling in actual state/province names (and/or state abbreviations) as well as country:

    $result = civicrm_api3('Address', 'get', array(
  'sequential' => 1,
  'return' => array("street_address", "supplemental_address_1", "supplemental_address_2", "city", "state_province_id.name", "state_province_id.abbreviation", "country_id.name"),
));

enter image description here

Before 4.7.0, API joins didn't exist - and before 4.7.15 there was no StateProvince API. So in the past, developers would either implement their own StateProvince API or use a hybrid of API and BAO calls.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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