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) »
  • Unable to add phone with civicrm_contact_update() API call, what might be amiss,
Pages: [1]

Author Topic: Unable to add phone with civicrm_contact_update() API call, what might be amiss,  (Read 950 times)

hesco

  • Guest
Unable to add phone with civicrm_contact_update() API call, what might be amiss,
September 08, 2010, 05:37:03 pm
The code below yields the following output:

Code: [Select]
8580: Hugh Esco
Array
(
    [contact_id] => 8580
    [is_error] => 0
)
Array
(
    [contact_id] => 8580
    [is_error] => 0
)
Array
(
    [contact_id] => 8580
    [is_error] => 0
)
8580: Hugh Esco

and now the database still says:
Code: [Select]
mysql> select * from civicrm_phone WHERE contact_id = 8580 ;
+------+------------+------------------+------------+------------+--------------------+--------------+---------------+
| id   | contact_id | location_type_id | is_primary | is_billing | mobile_provider_id | phone        | phone_type_id |
+------+------------+------------------+------------+------------+--------------------+--------------+---------------+
| 2074 |       8580 |                2 |          1 |          0 |               NULL | 678-921-8186 |             1 |
+------+------------+------------------+------------+------------+--------------------+--------------+---------------+
1 row in set (0.00 sec)

Can anyone here please advise me how to add these phone numbers to my database using the API?

Code: [Select]
#!/usr/bin/php

<?php

require_once 'civicrm.config.php';
require_once 
'CRM/Core/Config.php';
require_once 
'api/v2/Contact.php';

$param = array("first_name" => 'Hugh',
             
'contact_type' => 'Individual',
                
'last_name' => 'Esco' );

$contacts = civicrm_contact_search( $param );

if (
civicrm_error( $contacts ))
  die (
"Unable to find contact Hugh.");

foreach (
$contacts as $contact){
  echo 
$contact['contact_id'] . ': ' . $contact['display_name'] . "\n";
  
// print_r($contact);

  // Home phone
  
$param = array(
          
'contact_id' => $contact['contact_id'],
        
'contact_type' => 'Individual',
       
'phone_type_id' => 1,
    
'location_type_id' => 2,
               
'phone' => '404-424-8701'
  
);

  
$result = civicrm_contact_update($param);
  
print_r($result);

  
// Cell phone
  
$param = array(
          
'contact_id' => $contact['contact_id'],
        
'contact_type' => 'Individual',
       
'phone_type_id' => 2,
    
'location_type_id' => 1,
               
'phone' => ''
  
);

  
$result = civicrm_contact_update($param);
  
print_r($result);

  
// Work phone
  
$param = array(
          
'contact_id' => $contact['contact_id'],
        
'contact_type' => 'Individual',
       
'phone_type_id' => 1,
    
'location_type_id' => 1,
               
'phone' => '678-921-8186'
  
);

  
$result = civicrm_contact_update($param);
  
print_r($result);

}

?>


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: Unable to add phone with civicrm_contact_update() API call, what might be amiss,
September 09, 2010, 12:04:11 am
You need to use the location API for phones, see:
http://wiki.civicrm.org/confluence/display/CRMDOC32/Location+APIs
Erik
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) »
  • Unable to add phone with civicrm_contact_update() API call, what might be amiss,

This forum was archived on 2017-11-26.