CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Address API issue
Pages: [1]

Author Topic: Address API issue  (Read 826 times)

David L

  • I post occasionally
  • **
  • Posts: 55
  • Karma: 2
Address API issue
September 07, 2011, 01:40:07 pm
With API 3, using 'create' has the effect of creating a new record/instance and not modifying an existing one (unless an id is specified).

I am finding though that the Address API is updating rather than creating.


For example, my location_type_id of 1 = 'Home'

Using the code below has the effect of overriding the contact's current Home address and replacing it with this new one, when what I really want to do is add an additional Home address.

Is this a bug or am I doing something wrong?


Code: [Select]

$params = array(
  'contact_id' => $contact_id,
  'location_type_id' => 1,
  'street_address' => $street_address,
  'postal_code' => $postal_code,
  'city' => $city,
  'state_province_id' => $st,
  'version' => 3,
);

if (isset($supplemental_address_1) && strlen($supplemental_address_1)) $params['supplemental_address_1'] = $supplemental_address_1;

$address_create = civicrm_api('address', 'create', $params);

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Address API issue
September 07, 2011, 04:19:45 pm
I don't think the model allows to have to addresses at the same location. Can you really do it with the UI? (at least the dedupe seems to have the same constraint): you can't have 2 home locations, only one home and one "other"

This being said, if it's really not allowed to have two addresses for the same location, it should return an error instead of silently update (or at least handle a filter param to choose if it needs to update or error).

Would be create if you could investigate and submit a patch.

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

David L

  • I post occasionally
  • **
  • Posts: 55
  • Karma: 2
Re: Address API issue
September 08, 2011, 08:12:12 am
xavier, you are spot on, it can't be done via the UI either. My mistake.

Thanks for the clarification.

I'll look into it further when I have a chance.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Address API issue

This forum was archived on 2017-11-26.