PHP API Address book usage examples

  1. <?php
  2. /* Include PanaceaApi class */
  3. require_once("sms_api.php");
  4. $api = new PanaceaApi();
  5. $api->setUsername("demouser");
  6. $api->setPassword("demouser");
  7. $groups = $api->address_book_groups_get_list();
  8. if($api->ok($groups)) {
  9.     foreach($groups['details'] as $group) {
  10.         echo "Group {$group['name']} has ID {$group['id']}\n";
  11.     }
  12. }
  13. /* Let's add a new group */
  14. $result = $api->address_book_group_add("Api demo group");
  15. if($api->ok($result)) {
  16.     echo "Group added! ID = {$result['details']}\n";
  17.     /* Now let's add some contacts to our group */
  18.     $contact1 = $api->address_book_contact_add($result['details'], "441234567"); /* Remember to specify the group ID, first name and last name are optional parameters */
  19.     $contact2 = $api->address_book_contact_add($result['details'], "441234568", "Donald");
  20.     if($api->ok($contact1) && $api->ok($contact2)) {
  21.         echo "Both contacts added successfully, IDs {$contact1['details']} and {$contact2['details']}\n";
  22.         /* Let's set the surname for contact2 */
  23.         $api->address_book_contact_update($contact2['details'], null, null, "Jackson"); /* Specify null to not change */
  24.     }
  25.     /* Let's list all the contacts now */
  26.     $contacts = $api->address_book_contacts_get_list($result['details']);
  27.     /* Let's delete this group now */
  28.     $api->address_book_group_delete($result['details']);
  29. }
  30. ?>