A PHP client for the Base REST API.
Current state:
First release, Contacts and Leads API covered.
The recommended way to install the client is through Composer.
# Install Composer
curl -sS https://getcomposer.org/installer | php
Next, run the Composer command to install the latest stable version of BaseCrm:
composer require basecrm/basecrm-php
After installing, you need to require Composer's autoloader:
require 'vendor/autoload.php';
In the dist/
folder, there's a drop-in version, that you can just download and require.
To use the client, you need to instantiate a \BaseCrm\Client
object.
$client = new \BaseCrm\Client(['token' => 'YOUR API TOKEN']);
Afterwards, you call methods on a client to use the API.
Every call returns a \BaseCrm\Response
object, which holds two properties:
code
- the response HTTP status code
data
- parsed JSON of the response, returnes as stdObject or array of stdObjects.
To access contacts, access the contacts
property on the client, which will return a \BaseCrm\Scope
connected to Contacts.
$scope = $client->contacts
To access deals, access the leads
property on the client, which will return a \BaseCrm\Scope
connected to Leads.
$scope = $client->leads
Every time you have a scope, you can perform the following methods on it:
Retrieve a list of resources
$scope->all()
This returns a \BaseCrm\Response
with an array of Resource stdObjects in the data
property.
Retrieve a single resource.
$scope->get($id)
$id
is the id of the resource.
This returns a \BaseCrm\Response
with a Resource stdObject in the $data
property.
Create a single resource.
$scope->create($params)
$params
is an associative array with fields of the resource.
This returns a \BaseCrm\Response
with a newly created Resource stdObject in the $data
property.
Update a single resource.
$scope->update($id, $params)
$id
is the id of the resource to update.
$params
is an associative array with fields of the resource.
This returns a \BaseCrm\Response
with an update Resource stdObject in the $data
property.
Destroy a single resource.
$scope->destroy($id)
$id
is the id of the resource.
This returns a \BaseCrm\Response
with a 200 response code in the $code
property.
$client->leads->create([
"last_name" => "Johnson",
"first_name" => "Mark",
"company_name" => "Acme"
]);
$client->contacts->create([
"last_name" => "Johnson",
"first_name" => "Mark"
]);
Copyright (c) 2015 Marcin Bunsch, Base CRM. See LICENSE for details.