Skip to content
Snippets Groups Projects
Commit 7132c09a authored by Sean Madsen's avatar Sean Madsen Committed by GitHub
Browse files

Merge pull request #55 from totten/master-api-class

api/usage.md - The OO example doesn't work. Fix it.
parents cb0a3151 791fd361
No related branches found
No related tags found
No related merge requests found
...@@ -91,19 +91,21 @@ before using the API. See the examples in [Bootstrap Reference]. ...@@ -91,19 +91,21 @@ before using the API. See the examples in [Bootstrap Reference].
## PHP (class.api.php) ## PHP (class.api.php)
CiviCRM v3.4 introduced an object-oriented API client, `class.api.php`. CiviCRM v3.4 introduced an object-oriented API client, `class.api.php`.
This class be used locally or remotely to invoke APIs, as in: This class can be used locally or remotely to invoke APIs, as in:
```php ```php
require_once 'your/civicrm/folder/api/class.api.php'; require_once 'your/civicrm/folder/api/class.api.php';
$api = new civicrm_api3(); $api = new civicrm_api3(array(
// Specify location of "civicrm.settings.php".
'conf_path' => 'your/sites/default',
));
$apiParams = array( $apiParams = array(
'first_name' => 'Alice', 'first_name' => 'Alice',
'last_name' => 'Roberts' 'last_name' => 'Roberts',
); );
if ($api->Contact->Get($apiParams)) { if ($api->Contact->Get($apiParams)) {
//each key of the result array is an attribute of the api //each key of the result array is an attribute of the api
echo "\n contacts found ".$api->count; echo "\n contacts found ".$api->count;
'contact_type'=>'Individual','return'=>'sort_name,current_employer')) {
} }
else { else {
echo $api->errorMsg(); echo $api->errorMsg();
...@@ -111,8 +113,11 @@ else { ...@@ -111,8 +113,11 @@ else {
``` ```
If you call the API in the object oriented fashion, you do not have to If you call the API in the object oriented fashion, you do not have to
specify 'version' as a parameter specify 'version' as a parameter.
The object-oriented client can connect to a local or remote CiviCRM
instance. For details about connection parameters, see the docblock in
[class.api.php](https://github.com/civicrm/civicrm-core/blob/master/api/class.api.php).
## REST ## REST
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment