Web App Development - Systems Architecture - API Building - Security Audits

The Capsule CRM API and PHP

Posted by David in API, PEAR, PHP
Thursday, April 1st, 2010 at 15:02

Introduction

At echolibre we’ve been trying to organize our sales and customer relationship in a more efficient way as the company customer base is getting larger and larger. That’s natural process for any growing company. In order to help us organize how we do everything related to customers (Sales, Leads, Relationships, etc) we are giving Capsule CRM a good run.

Capsule CRM is basically a nice CRM tool that takes the boring part out of CRM’ing. Moreover (And the whole reason of this blog post), it has an API and as you all know, we LOVE APIs.

Therefore, we realized that we needed to integrate Capsule with some online services we have and so we built a PHP wrapper for their API to give developers the ability to place requests and use the web service as they wish using PHP

Services_Capsule is now being proposed to PEAR however you can already get the code from http://github.com/davidcoallier/Services_Capsule and start using it. The lack of end-user documentation may be the greatest lack in the package right now so I figured it might be good to post a few usage examples in a post.

Meat

So once you installed the Services_Capsule (Or for now cloned the repo and pointed your include_path to the repo-checkout) you’ll probably want to see how to use it. Even though the code has a list of examples, it might be best to show you a real world example:

Be sure to watch the examples directory as examples will make their way through there in the coming days.

You can leave a response, or trackback from your own site.

Comments (16 Responses)

[...] This post was mentioned on Twitter by Eamon Leonard, Planet PHP, David Coallier, topsy_top20k, topsy_top20k_en and others. topsy_top20k_en said: Woo just put up Services_Capsule on github and wrote a quick post about it: http://short.ie/x09dog #pear #php #capsulecrm [...]

[...] echolibre blog » Blog Archive » The Capsule CRM API and PHP [...]

ahamed

Hi,
i tried using this service, i am getting follwing error.

Fatal error: Class ‘HTTP_Request2′ not found in C:\wamp\www

FYI - I have Pear installed in my pc.
thanks in advance,
ahamed

[...] a post talking about their CRM tool of choice, Capsule CRM, and some of the things they’re doing to create an API interface to interact with it (including a proposed PEAR package). we realized that we needed to integrate [...]

This is awesome lads, and quite a coincidence too.

Last night I stumbled upon Capsule CRM completely on my own whilst looking for a suitable CRM for a side project I’ve got on.

I signed up there and then and today (with slightly blurry eyes from the late night last night setting it all up!) we’re ready to use Capsule properly for the first time.

I was happy with my decision last night, but now with this PHP wrapper I’m even happier. Especially since it’ll come as a PEAR package, which as you know, I’m a huge fan of.

I’ll be writing some code soon to integrate Capsule with Campaign Monitor (and a few other web services) so this wrapper will come in really really handy.

Great work!

All you have to do in order to do this is install HTTP2_Request using PEAR. IE: pear install HTTP2_Request-beta

The package.xml file has the dependency so as soon as this gets into PEAR, the package will validate and let you know that HTTP2_Request is a required dependency.

Thanks for your feedback

David thanks for your reply,

I have installed HTTP_REQUEST2 and checked from command line

c:\wamp\bin\php\php5.2.5\PEAR>pear run-scripts http_request2
Install scripts complete

I even cleared cache….
no progress

include_path .;c:\wamp\php\includes => also uncommented; restarted all systems, even my PC; Browser cache, hository everything cleared…..

Cheers,
Ahamed

[...] rest is here: echolibre blog » Blog Archive » The Capsule CRM API and PHP If you enjoyed this article please consider sharing [...]

@ahamed Do you get an exception from HTTP_Request2 or anything?

What I would suggest you do is go to http://pear.php.net/HTTP_Request2, go to documentation -> end user documentation and try to get the basic HTTP_Request2 example running.

From thereon, once it works, you’ll be able to run with it :)

I’ll also investigate see if there’s be a problem on windows with HTTP_Request2.

Mark

How would someone add a case?

Hey @Mark,

If you look at the API documentation, the cases are added by parties.

Thus using the PHP Package you would do:

$this->party->cases->add(…);

Then you could access the cases as such:

$this->kase->… (Refer to the docs for the access methods)

I can’t seem to find the task methods in your api. am I missing something?

Alan Hart

Hey David

Awesome that you put this wrapper out there. I’m trying it out on a web server of my own.

It works great for me with GET requests but hangs for a while and then generates an exception with a PUT request to update the “about” record of a person. Oddly enough if I debug it to discover what the curl request was, I can make it work by making a similar curl request on the command line, so the problem I guess lies in the wrapper’s construction of the curl request.

The lines that cause the problem are:
$personUpdate = array(’about’ =>”Sheryl”);
$personUpdated = $capsule->person->update($person->id, $personUpdate );

And the exception is below.

Any thoughts?

Thanks again…

Alan

Services_Capsule_RuntimeException Object
(
[message:protected] =>
HTTP_Request2_Exception: Error sending request: #52 Empty reply from server in /[censored]/php/HTTP/Request2.php on line 816
Exception trace
# Function Location
0 HTTP_Request2_Adapter_Curl->sendRequest(Object(HTTP_Request2)) /[censored]/php/HTTP/Request2.php:816
1 HTTP_Request2->send() /[censored]/Services/Capsule/Common.php:259
2 Services_Capsule_Common->sendRequest(’/4837621′, ‘PUT’, ‘{”person”:{”abou…’) /[censored]/Services/Capsule/Person.php:129
3 Services_Capsule_Person->update(’4837621′, Array) /[censored]/fix.php:502
4 {main}

[string:private] =>
[code:protected] => 0
[file:protected] => /[censored]/Services/Capsule/Common.php
[line:protected] => 261
[trace:private] => Array
(
[0] => Array
(
[file] => /[censored]/Services/Capsule/Person.php
[line] => 129
[function] => sendRequest
[class] => Services_Capsule_Common
[type] => ->
[args] => Array
(
[0] => /4837621
[1] => PUT
[2] => {”person”:{”about”:”Sheryl”}}
)

)

[1] => Array
(
[file] => /[censored]/fix.php
[line] => 502
[function] => update
[class] => Services_Capsule_Person
[type] => ->
[args] => Array
(
[0] => 4837621
[1] => Array
(
[about] => Sheryl
)

)

)

)

)

Nice work on the wrapper.

Confirming what Alan mentioned above, seems like HTTP_Request2 is unable to properly handle the PUT requests coming from the wrapper. I’m getting curl #52 errors, too.

For my situation, I was able to workaround the issue by deleting and re-adding my custom fields instead of updating them. Probably won’t work with other entity types, and by no means a great solution since it’s calling the API twice when it should only be calling it once. But it’s getting the job done for now.

I did update Customfield.php, as there were a few typos and a method that didn’t match up to the API as of today (12/1/2010) that kept it from working properly.

Interested in the patch?

Ali Ajellu

Thanks a lot for putting this together guys!

Had a simple question:
How can I add organizations instead of persons? I tried

$capsule->organization->add($org);

but I get a 405 Method Not Allowed response! Thanks for your help :)

Ali Ajellu

I think I’ve figured out the problem. There are a number of places in the PHP wrapper where “organisation” is spelled with Z (organization) while it’s spelled with an S in the API. Here are the lines that I had to correct for the code to start working properly:

Services_Capsule_Organization

(line 79):

$org = array(’organisation’ => $fields);

(line 115):

$organization = array(’organisation’ => $fields);

I also had to manually set the ModuleName for the Organization class to the correct spelling since I didn’t want to rename the classes, etc.:

$orgClient = $this->_capsule->organization;

$orgClient->setModuleName(’organisation’);

$response = $orgClient->add($org);

Hope this helps someone else as well!

Leave a comment




About this blog

We like to blog about things we're passionate about. We love PHP, MySQL, CouchDB, Linux, Apache - web development standards. We also like writing about building web apps and working with web technology.
You can email us on freedom@echolibre.com

Follow us on Twitter

Eamon Leonard - @EamonLeonard
David Coallier - @DavidCoallier
Helgi Þormar Þorbjörnsson - @h
J.D Fitz.Gerald - @jdfitzgerald
Noah Slater - @nslater
Court Ewing - @courtewing

 

 

 

echolibre limited is registered in Ireland, company number 451576. Directors: Eamon Leonard, J.D Fitz.Gerald. Registered Office: 64 Dame Street, Dublin 2, Ireland.