PHP libraries & samples
People & Organisations (Party)
Party Custom Fields
Party History
Party Tags
Opportunities
Opportunity Additional Parties
Opportunity Custom Fields
Opportunity History
Opportunity Tags
Cases
Case Additional Parties
Case Custom Fields
Case History
Case Tags
Note: if you’re using Drupal, there is a capsule web form module available.
David at echolibre has very kindly created a PHP wrapper for the Capsule API and made it available on github. Examples and further details are available on the echolibre blog.
If you prefer to call the Capsule API directly from PHP rather than using the wrapper (above), 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
// The data you want to send to Capsule CRM in xml format
// SEE http://capsulecrm.com/help/page/javelin_api_party
$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: text/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);
?>
Capsule is a service of Zestia Ltd which is a company registered in England with company number 06418281. © 2008-2012 Zestia Ltd. All Rights Reserved.