REST API PHP Library

Published
2008-08-04 11:45
Written by
acrosman - member of the CiviCRM community - view blog guidelines
The American Friends Service Committee, where I work, needs to sync some information between our CMS (which isn’t Drupal or Joomla for various reasons) and CiviCRM. The vendor we’re working with is writing custom additions to the CMS to handle our needs, and part of that process is creating a PHP library to connect to the REST API of CiviCRM. When we asked, the vendor was very willing to open source that library. The initial version will cover the API parts that we need to access. Once that is complete, I plan to add in the other API functions. This dovetails with a patch that I wrote, that is included in 2.1, that gave the REST interface access to all functions in the API. As someone who has a professional interest in making sure the REST API thrives and gets attention from the development team, I really want to find ways to make this useful to others. If anyone has thoughts about a library for the REST API, please feel free to speak up. Aaron Crosman American Friends Service Committee
Filed under

Comments

Hi,

Is there a doc about the rest api and or some example code ?

Would the rest api covers this (non too far away from something I'd need):
from a (non drupal/joomla CMS) displays the list of organisations in the group "members", and display them

The goal would be to retrieve as well images and other custom tags associated with my members. Would it works ?

In that case, I'd love to hear more about your REST API !

X+

I don't have sample code that I can post easily at the moment, but I can try to get something together in a few days. There are some oddities about working with the API that do require some attention to detail (session cookie has to be maintained by the client application, something I'll probably take up with the dev team after I get the library fully on its feet).

As for documentation, as of 2.1 the REST API supports all the functions of the main API, so all the documentation applies (http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs).

To call the API with a browser just use:
http://www.example.org/path/to/civi/codebase/civicrm/extern/rest.php?q=civicrm/login&name=user&pass=password
That generates the key, that you will need to feed into all other commands:
http://www.example.org/path/to/civi/codebase/civicrm/extern/rest.php?q=civicrm/contact/search&key=hash_key_given_after_login_command

Sorry it took so long to answer.