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) »
  • Chained api.phone.create Generates 25 new phone number records
Pages: [1]

Author Topic: Chained api.phone.create Generates 25 new phone number records  (Read 823 times)

jeffmikels

  • I’m new here
  • *
  • Posts: 26
  • Karma: 0
Chained api.phone.create Generates 25 new phone number records
August 20, 2013, 01:56:23 pm
I have written a simplified front end for contact data entry in our church. Everything was working well until I updated civicrm to 4.3.5 from 4.2.6. Now, my frontend code generates multiple distinct phone number entries.

Currently, I'm assembling household data, contact data, and location data in one large array using api chaining syntax. I send all the data using the civicrm_api() wrapper. I combine it all so that there are fewer server hits, and because I want to trust the api to do it's job.

However, chaining always seemed to create duplicates with activities and certain custom fields, so I separated them out. Now, however, it's creating MANY duplicates of the phone records. Here's some sample data just before calling civicrm_api(). Note that the Household exists in the database already (it has a contact id) as does the Individual (also has a contact id), but in this case, the Individual Home Phone number is new:

Full code is posted to pastebin... what follows has been abridged.

Code: [Select]
Array
(
    [contact_id] => 8481
    [household_name] => Household 1
    [contact_type] => Household
    [api.phone.create] => Array
        (
            [0] => Array
                (
                    [phone] => 111-111-1111
                    [id] => 4705
                    [location_type_id] => 1
                    [phone_type_id] => 1
                    [contact_id] => 8481
                )
 
            [1] => Array
                (
                    [phone] => 222-222-2222
                    [id] => 4706
                    [location_type_id] => 1
                    [phone_type_id] => 2
                    [contact_id] => 8481
                )
 
        )
 
    [api.email.create] => Array
        (
            [0] => Array
                (
                    [email] => a@b.c
                    [id] => 3663
                    [location_type_id] => 1
                    [contact_id] => 8481
                )
        )
    [api.contact.create] => Array
        (
            [0] => Array
                (
                    [contact_type] => Individual
                    [first_name] => Person
                    [last_name] => Household 1
                    [contact_id] => 8482
                    [api.phone.create] => Array
                        (
                            [0] => Array
                                (
                                    [phone] => 333-333-3333
                                    [location_type_id] => 1
                                    [phone_type_id] => 1
                                    [contact_id] => 8482
                                    [is_primary] => 1
                                )
                        )
                    [api.note.create] => Array
                        (
                            [entity_table] => civicrm_contact
                            [note] => MODIFIED WITH API ON Tue, 20 Aug 2013 15:43:55 -0400
                            [entity_id] => 8482
                            [contact_id] => 1
                            [subject] => API NOTE
                        )
                    [api.relationship.create] => Array
                        (
                            [contact_id_a] => 8482
                            [contact_id_b] => 8481
                            [relationship_type_id] => 7
                            [is_active] => 1
                            [is_permission_a_b] => 0
                            [is_permission_b_a] => 1
                            [id] => 3207
                        )
                )
        )
    [version] => 3
)
http://pastebin.com/kuqpZW1P


Then immediately after calling civicrm_api() with this array, I get the following response:

Code: [Select]
Array
(
    [is_error] => 0
    [version] => 3
    [count] => 1
    [id] => 8481
    [values] => Array
        (
            [8481] => Array
                (
                    [id] => 8481
                    [contact_type] => Household

...

                    [api.contact.create] => Array
                        (
                            [0] => Array
                                (
                                    [is_error] => 0
                                    [undefined_fields] => Array
                                        (
                                            [0] => api.has_parent
                                            [1] => contact_type
                                            [2] => first_name
                                            [3] => last_name
                                            [4] => api.phone.create
                                            [5] => api.note.create
                                            [6] => api.relationship.create
                                            [7] => id
                                            [8] => contact_sub_type
                                        )

                                    [version] => 3
                                    [count] => 1
                                    [id] => 8482
                                    [values] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [id] => 8482
                                                    [contact_type] => Individual
                                                    [contact_sub_type] =>
                                                    [do_not_email] => 0
                                                    [do_not_phone] => 0
                                                    [do_not_mail] => 0
                                                    [do_not_sms] => 0
                                                    [do_not_trade] => 0
                                                    [is_opt_out] => 0
                                                    [legal_identifier] =>
                                                    [external_identifier] =>
                                                    [sort_name] => Household 1, Person
                                                    [display_name] => Person Household 1
                                                    [nick_name] =>
                                                    [legal_name] =>
                                                    [image_URL] =>
                                                    [preferred_communication_method] =>
                                                    [preferred_language] => en_US
                                                    [preferred_mail_format] => Both
                                                    [hash] => 07b9ccbc5c20771fe4c871852cc60d7f
                                                    [api_key] =>
                                                    [first_name] => Person
                                                    [middle_name] =>
                                                    [last_name] => Household 1
                                                    [prefix_id] =>
                                                    [suffix_id] =>
                                                    [email_greeting_id] => 1
                                                    [email_greeting_custom] =>
                                                    [email_greeting_display] => Dear Person
                                                    [postal_greeting_id] => 1
                                                    [postal_greeting_custom] =>
                                                    [postal_greeting_display] => Dear Person
                                                    [addressee_id] => 1
                                                    [addressee_custom] =>
                                                    [addressee_display] => Person Household 1
                                                    [job_title] =>
                                                    [gender_id] =>
                                                    [birth_date] =>
                                                    [is_deceased] => 0
                                                    [deceased_date] =>
                                                    [household_name] =>
                                                    [primary_contact_id] =>
                                                    [organization_name] =>
                                                    [sic_code] =>
                                                    [user_unique_id] =>
                                                    [created_date] => 2013-08-20 15:43:02
                                                    [modified_date] => 2013-08-20 15:43:02
...


                                            [8482] => Array
                                                (
                                                    [api.phone.create] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [is_error] => 0
                                                                    [undefined_fields] => Array
                                                                        (
                                                                            [0] => is_primary
                                                                            [1] => entity_id
                                                                            [2] => entity_table
                                                                            [3] => contact_id
                                                                            [4] => api.has_parent
                                                                            [5] => phone
                                                                            [6] => location_type_id
                                                                            [7] => phone_type_id
                                                                        )

                                                                    [version] => 3
                                                                    [count] => 1
                                                                    [id] => 4785
                                                                    [values] => Array
                                                                        (
                                                                            [0] => Array
                                                                                (
                                                                                    [id] => 4785
                                                                                    [contact_id] => 8482
                                                                                    [location_type_id] => 1
                                                                                    [is_primary] => 1
                                                                                    [is_billing] =>
                                                                                    [mobile_provider_id] =>
                                                                                    [phone] => 333-333-3333
                                                                                    [phone_ext] =>
                                                                                    [phone_numeric] =>
                                                                                    [phone_type_id] => 1

...

http://pastebin.com/1KcpLV9i


Everything looks good right?

Well, if I do a Contact get, civicrm returns this data:

Code: [Select]
Array
(
    [contacts] => Array
        (
            [8482] => Array
                (
                    [contact_id] => 8482
                    [contact_type] => Individual
                    [display_name] => Person Household 1
                    [first_name] => Person
                    [last_name] => Household 1

...
                            [phones] => Array
                                (
                                    [by_index] => Array
                                        (
                                            [4707] => Array
                                                (
                                                    [id] => 4707
                                                    [contact_id] => 8482
                                                    [location_type_id] => 1
                                                    [is_primary] => 0
                                                    [is_billing] => 0
                                                    [phone] => 333-333-3333
                                                    [phone_numeric] => 3333333333
                                                    [phone_type_id] => 1
                                                    [location] => Home
                                                    [type] => Phone
                                                )

                                            [4708] => Array
                                                (
                                                    [id] => 4708
                                                    [contact_id] => 8482
                                                    [location_type_id] => 1
                                                    [is_primary] => 0
                                                    [is_billing] => 0
                                                    [phone] => 333-333-3333
                                                    [phone_numeric] => 3333333333
                                                    [phone_type_id] => 1
                                                    [location] => Home
                                                    [type] => Phone
                                                )

...

                                            [4731] => Array
                                                (
                                                    [id] => 4731
                                                    [contact_id] => 8482
                                                    [location_type_id] => 1
                                                    [is_primary] => 0
                                                    [is_billing] => 0
                                                    [phone] => 333-333-3333
                                                    [phone_numeric] => 3333333333
                                                    [phone_type_id] => 1
                                                    [location] => Home
                                                    [type] => Phone
                                                )

                                        )

                                    [home] => Array
                                        (
                                            [mobile] => Array
                                                (
                                                )

                                            [phone] => Array
                                                (
                                                    [id] => 4731
                                                    [contact_id] => 8482
                                                    [location_type_id] => 1
                                                    [is_primary] => 0
                                                    [is_billing] => 0
                                                    [phone] => 333-333-3333
                                                    [phone_numeric] => 3333333333
                                                    [phone_type_id] => 1
                                                    [location] => Home
                                                    [type] => Phone
                                                )

                                        )


...

)
http://pastebin.com/nfSmcvXG

Notice the 25 Phone number entries.

Can anyone give me advice on this? I'll file a bug report, but I want to make sure I'm not doing something stupid in my API call.

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: Chained api.phone.create Generates 25 new phone number records
August 20, 2013, 11:31:45 pm
I do not see anything obvious in your code. Are you using Drupal as a CMS? If you are, have you tried building your UI with the WebForm - CiviCRM module?
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Chained api.phone.create Generates 25 new phone number records

This forum was archived on 2017-11-26.