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) »
  • REST API Has Serious Limitations?
Pages: [1]

Author Topic: REST API Has Serious Limitations?  (Read 1298 times)

joshbenner

  • Guest
REST API Has Serious Limitations?
November 11, 2010, 06:45:51 am
I've begun using the CiviCRM REST API to integrate with another application -- however, I'm encountering serious limitations to the REST API, seemingly at every turn. Some examples:

1. I cannot find a way to distinguish between deleted and non-deleted contacts. Deleted contacts are returned by civicrm/Contact/Get, the is_deleted field is not part of the returned contact info, I cannot specify &return[is_deleted]=1 (nothing is returned then??), and I cannot filter using &is_deleted=0.

2. There is no way to access non-primary phone numbers (or email addresses, I think).

Is this really the case? Or am I missing something huge here? These are simple things, but are fundamentally critical to being able to access CRM data via API.

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: REST API Has Serious Limitations?
November 11, 2010, 12:49:30 pm
Hello Josh,
I use the REST API's extensively in my project, and I hope I can help you.
Question 1: that is correct, I have encountered the same issue. The API needs to be fixed, at the moment you get all the information. Are you able (time and knowledgewise) to undertake that change?
2. I have found a number of issues with the location API so I have developed my own flavours, also because I need additional custom data. You can create your own API's, which if you put them in the API folder, are then available with REST. I use the following code which uses the standard location API to get phones for example:
Code: [Select]
civires = &civicrm_location_get($civiparms);
if (civicrm_error($civires)) {
   $message = $civires['error_message'];
   return civicrm_create_error("Fout is : ".$message);
} else {
   /*
    * array from location_get contains possibly many arrays. Therefore:
    * - read all arrays within result, this is a complete location
    * - read all items within a location. This can contain an address,
    *   emails or phones.
    * - If the item is an array it is either emails or phones
    * - If item['phone'] exists, it is a phone.
    */
   $i = 1;
   foreach ($civires as $location) {
        foreach ($location as $item) {
              if (is_array($item)) {
                 if (isset($item['phone'])) {
                      $outparms[$i]['contact_id'] = $item['contact_id'];
                      $outparms[$i]['phone_id'] = $item['id'];
                      /*
                       * retrieve label location_type_id
                       */
                      $loc_type = getLocationType($item['location_type_id']);
                      $outparms[$i]['location_type'] = strtolower($loc_type);
                      if (isset($item['is_primary'])) {
                           $outparms[$i]['is_primary'] = $item['is_primary'];
                      } else {
                           $outparms[$i]['is_primary'] = 0;
                      }
                      /*
                       * retrieve label phone_type_id
                       */
                     $phone_type = getOptionValue("", "phone_type", $item['phone_type_id']);
                     $outparms[$i]['phone_type'] = strtolower($phone_type);
                     $outparms[$i]['phone'] = $item['phone'];
                         
                     $i++;
                 }
             }
          }
     }
}

and the following code to retrieve a specific phone with a phone_id:
Code: [Select]
$phone_id = $inparms['phone_id'];
$query = "SELECT * FROM civicrm_phone WHERE id = $phone_id";
$daoPhone = CRM_Core_DAO::executeQuery($query);

while ($daoPhone->fetch()) {
                $outparms[1]['contact_id'] = $daoPhone->contact_id;
                $outparms[1]['phone_id'] = $daoPhone->id;
                $outparms[1]['location_type'] =
                    getLocationType($daoPhone->location_type_id);
                $outparms[1]['location_type'] = strtolower(
                        $outparms['location_type']);
                $outparms[1]['is_primary'] = $daoPhone->is_primary;
                $outparms[1]['phone_type'] = getOptionValue(
                        "", "phone_type", $daoPhone->phone_type_id);
                $outparms[1]['phone_type'] = strtolower(
                        $outparms[1]['phone_type']);
                $outparms[1]['phone'] = $daoPhone->phone;
}
Hope this helps a little!
Erik
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: REST API Has Serious Limitations?
November 16, 2010, 09:56:05 am
Quote from: joshbenner on November 11, 2010, 06:45:51 am
I've begun using the CiviCRM REST API to integrate with another application -- however, I'm encountering serious limitations to the REST API, seemingly at every turn. Some examples:

Agree, they are limitations and it needs some developments more. Mostly, if something is missing, that's because is hasn't been properly exposed to the api, or that it misses some glue with the BAO below.

We very much hope the developers bumping into these limitations take the time to discuss with us and improve them, it shouldn't be complicated to fix.

Quote from: joshbenner on November 11, 2010, 06:45:51 am
1. I cannot find a way to distinguish between deleted and non-deleted contacts. Deleted contacts are returned by civicrm/Contact/Get, the is_deleted field is not part of the returned contact info, I cannot specify &return[is_deleted]=1 (nothing is returned then??), and I cannot filter using &is_deleted=0.

This is because the REST interface skips the permissions, and that the is_deleted is handled by that.
CRM_Contact_BAO_Query:searchQuery (line 3208)

You are right, I think we shouldn't return the deleted contact, even if no DAO.

Piotr & Lobo, brilliant idea ? I don't think it'd be a big issue to ignore the deleted by default, that what was happening anyway before 3.2

should we inject the $this->_skipDeleteClause anyway even if _skipPermission ?



Quote from: joshbenner on November 11, 2010, 06:45:51 am
2. There is no way to access non-primary phone numbers (or email addresses, I think).

Is this really the case? Or am I missing something huge here? These are simple things, but are fundamentally critical to being able to access CRM data via API.

location api should help you getting it.

(agree, not the most obvious one).

It would be good to develop apis ContactPhone and ContactMail indeed. If you are willing to give it a go, jump on IRC and discuss it with us.

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

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

This forum was archived on 2017-11-26.