API Wrappers
Some of our users have kindly provided links to wrappers they have created around the Capsule API for their favourite programming languages.
- PHP - http://github.com/davidcoallier/Services_Capsule
- Ruby - https://github.com/mattbeedle/capsule_crm
- Ruby - https://github.com/ahmedrb/capsulecrm
- PlayFramework 2.1 (Java) - http://coenrecruitment.github.io/capsulecrm-java/
These are provided by third parties; we do not provide support for these libraries.
PHP Example
If you prefer to call the Capsule API directly from PHP rather than using the wrapper (below), here’s an example kindly provided by Samantha Crane.
The example requires PHP 5+ and the client URL library (cURL) installed. Use phpinfo() function to view your PHPconfig to make sure that you have cURL module installed on your server.
Note: Replace sample as appropriate. You’ll probably be dynamically generating $myxml
<?php
$myxml="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n
<person>\n
<title>Mr</title>\n
<firstName>Test12</firstName>\n
<lastName>Tester12</lastName>\n
<jobTitle>Chairman</jobTitle>\n
<organisationName>Big Company</organisationName>\n
<about>Testing</about>\n
</person>";
// The URL to connect with (note the /api/ that's needed and note it's person rather than party)
// SEE: http://capsulecrm.com/help/page/api_gettingstarted/
$capsulepage = 'https://sample.capsulecrm.com/api/person';
// Initialise the session and return a cURL handle to pass to other cURL functions.
$ch = curl_init($capsulepage);
// set appropriate options NB these are the minimum necessary to achieve a post with a useful response
// ...can and should add more in a real application such as
// timeout CURLOPT_CONNECTTIMEOUT
// and useragent CURLOPT_USERAGENT
// replace 1234567890123456789 with your own API token from your user preferences page
$options = array(CURLOPT_USERPWD => '1234567890123456789:x',
CURLOPT_HTTPHEADER => array('Content-Type: application/xml'),
CURLOPT_HEADER => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $myxml
);
curl_setopt_array($ch, $options);
// Do the POST and collect the response for future printing etc then close the session
$response = curl_exec($ch);
$responseInfo = curl_getinfo($ch);
curl_close($ch);
?>
