PHPackages                             basecrm/basecrm-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. basecrm/basecrm-php

ActiveLibrary[HTTP &amp; Networking](/categories/http)

basecrm/basecrm-php
===================

BaseCRM Official API V2 library client for PHP

v1.4.4(4y ago)221.0M↓16.9%18[3 PRs](https://github.com/zendesk/basecrm-php/pulls)Apache License 2.0PHPPHP &gt;=5.4.0

Since Feb 2Pushed 5mo ago94 watchersCompare

[ Source](https://github.com/zendesk/basecrm-php)[ Packagist](https://packagist.org/packages/basecrm/basecrm-php)[ Docs](http://developers.getbase.com/)[ RSS](/packages/basecrm-basecrm-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (31)Used By (0)

basecrm-php
===========

[](#basecrm-php)

BaseCRM Official API V2 library client for PHP

Installation
------------

[](#installation)

The recommended way to install the client is through [Composer](http://getcomposer.org).

```
# Install Composer
curl -sS https://getcomposer.org/installer | php
```

Next, run the Composer command to install the latest stable version :

```
composer require basecrm/basecrm-php
```

After installing, you need to require Composer's autoloader:

```
require 'vendor/autoload.php';
```

Usage
-----

[](#usage)

```
require 'vendor/autoload.php';

// Then we instantiate a client (as shown below)
```

### Build a client

[](#build-a-client)

**Using this api without authentication gives an error**

```
$client = new \BaseCRM\Client(['accessToken' => '']);
```

### Client Options

[](#client-options)

The following options are available while instantiating a client:

- **accessToken**: Personal access token
- **baseUrl**: Base url for the api
- **userAgent**: Default user-agent for all requests
- **timeout**: Request timeout
- **verbose**: Verbose/debug mode
- **verifySSL**: Whether to verify SSL or not. Default: true

### Architecture

[](#architecture)

The library follows few architectural principles you should understand before digging deeper.

1. Interactions with resources are done via service objects.
2. Service objects are exposed as properties on client instances.
3. Service objects expose resource-oriented actions.
4. Actions return associative arrays.

For example, to interact with deals API you will use `\BaseCRM\DealsService`, which you can get if you call:

```
$client = new \BaseCRM\Client(['accessToken' => '']);
$client->deals; // \BaseCRM\DealsService
```

To retrieve list of resources and use filtering you will call `#all` method:

```
$client = new \BaseCRM\Client(['accessToken' => '']);
$client->deals->all(['organization_id' => google['id'], 'hot' => true]);
```

To find a resource by it's unique identifier use `#get` method:

```
$client = new \BaseCRM\Client(['accessToken' => '']);
$client->deals->get($id) # => array
```

When you'd like to create a resource, or update it's attributes you want to use either `#create` or `#update` methods. For example if you want to create a new deal you will call:

```
$client = new \BaseCRM\Client(['accessToken' => '']);
$deal = $client->deals->create(['name' => 'Website redesign', 'contact_id' => $id]);
```

To destroy a resource use `#destroy` method:

```
$client = new \BaseCRM\Client(['accessToken' => '']);
$client->deals->destroy($id) // => true
```

There other non-CRUD operations supported as well. Please contact corresponding service files for in-depth documentation.

### Full example

[](#full-example)

Create a new organization and after that change it's attributes (website).

```
$client = new \BaseCRM\Client(['accessToken' => '']);
$lead = $client->leads->create(['organization_name' => 'Design service company']);

$lead['website'] = "http://www.designservices.com"
$client->leads->update($lead['id'], $lead);
```

### Error handling

[](#error-handling)

When you instantiate a client or make any request via service objects, exceptions can be raised for multiple of reasons e.g. a network error, an authentication error, an invalid param error etc.

Sample below shows how to properly handle exceptions:

```
try
{
  // Instantiate a client.
  $client = new \BaseCRM\Client(['accessToken' => getenv('BASECRM_ACCESS_TOKEN')]);
  $lead = $client->leads->create(['organization_name' => 'Design service company']);

  print_r($lead);
}
catch (\BaseCRM\Errors\ConfigurationError $e)
{
  // Invalid client configuration option
}
catch (\BaseCRM\Errors\ResourceError $e)
{
  // Resource related error
  print('Http status = ' . $e->getHttpStatusCode() . "\n");
  print('Request ID = ' . $e->getRequestId() . "\n");
  foreach ($e->errors as $error)
  {
    print('field = ' . $error['field'] . "\n");
    print('code = ' . $error['code'] . "\n");
    print('message = ' . $error['message'] . "\n");
    print('details = ' . $error['details'] . "\n");
  }
}
catch (\BaseCRM\Errors\RequestError $e)
{
  // Invalid query parameters, authentication error etc.
}
catch (\BaseCRM\Errors\Connectionerror $e)
{
  // Network communication error, curl error is returned
  print('Errno = ' . $e->getErrno() . "\n");
  print('Error message = ' . $e->getErrorMessage() . "\n");
}
catch (Exception $e)
{
  // Other kind of exception
}
```

Sync API
--------

[](#sync-api)

The following sample code shows how to perform a full synchronization flow using high-level wrapper.

First of all you need an instance of `\BaseCRM\Client`. High-level `\BaseCRM\Sync` wrapper uses `\BaseCRM\SyncService` to interact with the Sync API. In addition to the client instance, you must provide a device’s UUID within `$deviceUUID` parameter. The device’s UUID must not change between synchronization sessions, otherwise the sync service will not recognize the device and will send all the data again.

```
$client = new \BaseCRM\Client(['access_token' => '']);
$sync = new \BaseCRM\Sync($client, 'associatedContacts->all`
- Create an associated contact - `client->associatedContacts->create`
- Remove an associated contact - `client->associatedContacts->destroy`

### Contact

[](#contact)

```
$client = new \BaseCRM\Client(['accessToken' => '');
$client->contacts // => \BaseCRM\ContactsService
```

Actions:

- Retrieve all contacts - `client->contacts->all`
- Create a contact - `client->contacts->create`
- Retrieve a single contact - `client->contacts->get`
- Update a contact - `client->contacts->update`
- Delete a contact - `client->contacts->destroy`

### Deal

[](#deal)

```
$client = new \BaseCRM\Client(['accessToken' => '');
$client->deals // => \BaseCRM\DealsService
```

Actions:

- Retrieve all deals - `client->deals->all`
- Create a deal - `client->deals->create`
- Retrieve a single deal - `client->deals->get`
- Update a deal - `client->deals->update`
- Delete a deal - `client->deals->destroy`

**Note about deal value**

You can use either a string or numerical deal value when modifying a deal.

```
$deal['value'] = 10;
$deal['value'] = 10.10;
$deal['value'] = "10.10";
```

### Deal Source

[](#deal-source)

```
$client = new \BaseCRM\Client(['accessToken' => '');
$client->dealSources // => \BaseCRM\DealSourcesService
```

Actions:

- Retrieve all deal sources - `client->dealSources->all`
- Create a deal source - `client->dealSources->create`
- Retrieve a single deal source - `client->dealSources->get`
- Update a deal source - `client->dealSources->update`
- Delete a deal source - `client->dealSources->destroy`

### Lead

[](#lead)

```
$client = new \BaseCRM\Client(['accessToken' => '');
$client->leads // => \BaseCRM\LeadsService
```

Actions:

- Retrieve all leads - `client->leads->all`
- Create a lead - `client->leads->create`
- Retrieve a single lead - `client->leads->get`
- Update a lead - `client->leads->update`
- Delete a lead - `client->leads->destroy`

### Lead Source

[](#lead-source)

```
$client = new \BaseCRM\Client(['accessToken' => '');
$client->leadSources // => \BaseCRM\LeadSourcesService
```

Actions:

- Retrieve all lead sources - `client->leadSources->all`
- Create a lead source - `client->leadSources->create`
- Retrieve a single lead source - `client->leadSources->get`
- Update a lead source - `client->leadSources->update`
- Delete a lead source - `client->leadSources->destroy`

### Line Item

[](#line-item)

```
$client = new \BaseCRM\Client(['accessToken' => '');
$client->lineItems // => \BaseCRM\LineItemsService
```

Actions:

- Retrieve all line items - `client->lineItems->all`
- Create a line item - `client->lineItems->create`
- Retrieve a single line item- `client->lineItems->get`
- Update a line item - `client->lineItems->update`
- Delete a line item - `client->lineItems->destroy`

### LossReason

[](#lossreason)

```
$client = new \BaseCRM\Client(['accessToken' => '');
$client->lossReasons // => \BaseCRM\LossReasonsService
```

Actions:

- Retrieve all reasons - `client->lossReasons->all`
- Create a loss reason - `client->lossReasons->create`
- Retrieve a single reason - `client->lossReasons->get`
- Update a loss reason - `client->lossReasons->update`
- Delete a reason - `client->lossReasons->destroy`

### Note

[](#note)

```
$client = new \BaseCRM\Client(['accessToken' => '');
$client->notes // => \BaseCRM\NotesService
```

Actions:

- Retrieve all notes - `client->notes->all`
- Create a note - `client->notes->create`
- Retrieve a single note - `client->notes->get`
- Update a note - `client->notes->update`
- Delete a note - `client->notes->destroy`

### Order

[](#order)

```
$client = new \BaseCRM\Client(['accessToken' => '');
$client->orders // => \BaseCRM\OrdersService
```

Actions:

- Retrieve all orders - `client->orders->all`
- Create an order - `client->orders->create`
- Retrieve a single order - `client->orders->get`
- Update an order - `client->orders->update`
- Delete an order - `client->orders->destroy`

### Pipeline

[](#pipeline)

```
$client = new \BaseCRM\Client(['accessToken' => '');
$client->pipelines // => \BaseCRM\PipelinesService
```

Actions:

- Retrieve all pipelines - `client->pipelines->all`

### Product

[](#product)

```
$client = new \BaseCRM\Client(['accessToken' => '');
$client->products // => \BaseCRM\ProductsService
```

Actions:

- Retrieve all products - `client->products->all`
- Create a product - `client->products->create`
- Retrieve a single product - `client->products->get`
- Update a product - `client->products->update`
- Delete a product - `client->products->destroy`

### Source (Deprecated! Use Lead Source, Deal Source instead)

[](#source-deprecated-use-lead-source-deal-source-instead)

```
$client = new \BaseCRM\Client(['accessToken' => '');
$client->sources // => \BaseCRM\SourcesService
```

Actions:

- Retrieve all sources - `client->sources->all`
- Create a source - `client->sources->create`
- Retrieve a single source - `client->sources->get`
- Update a source - `client->sources->update`
- Delete a source - `client->sources->destroy`

### Stage

[](#stage)

```
$client = new \BaseCRM\Client(['accessToken' => '');
$client->stages // => \BaseCRM\StagesService
```

Actions:

- Retrieve all stages - `client->stages->all`

### Tag

[](#tag)

```
$client = new \BaseCRM\Client(['accessToken' => '');
$client->tags // => \BaseCRM\TagsService
```

Actions:

- Retrieve all tags - `client->tags->all`
- Create a tag - `client->tags->create`
- Retrieve a single tag - `client->tags->get`
- Update a tag - `client->tags->update`
- Delete a tag - `client->tags->destroy`

### Task

[](#task)

```
$client = new \BaseCRM\Client(['accessToken' => '');
$client->tasks // => \BaseCRM\TasksService
```

Actions:

- Retrieve all tasks - `client->tasks->all`
- Create a task - `client->tasks->create`
- Retrieve a single task - `client->tasks->get`
- Update a task - `client->tasks->update`
- Delete a task - `client->tasks->destroy`

### TextMessage

[](#textmessage)

```
$client = new \BaseCRM\Client(['accessToken' => '');
$client->textMessages // => \BaseCRM\TextMessagesService
```

Actions:

- Retrieve text messages - `client->textMessages->all`
- Retrieve a single text message - `client->textMessages->get`

### User

[](#user)

```
$client = new \BaseCRM\Client(['accessToken' => '');
$client->users // => \BaseCRM\UsersService
```

Actions:

- Retrieve all users - `client->users->all`
- Retrieve a single user - `client->users->get`
- Retrieve an authenticating user - `client->users->self`

### Visit

[](#visit)

```
$client = new \BaseCRM\Client(['accessToken' => '');
$client->visits // => \BaseCRM\VisitsService
```

Actions:

- Retrieve visits - `client->visits->all`

### VisitOutcome

[](#visitoutcome)

```
$client = new \BaseCRM\Client(['accessToken' => '');
$client->visitOutcomes // => \BaseCRM\VisitOutcomesService
```

Actions:

- Retrieve visit outcomes - `client->visitOutcomes->all`

Tests
-----

[](#tests)

Install PHPUnit via Composer:

```
$ composer install
```

To run all test suites:

```
$ BASECRM_ACCESS_TOKEN= ./vendor/bin/phpunit
```

And to run a single suite:

```
$ BASECRM_ACCESS_TOKEN= ./vendor/bin/phpunit --filter testUpdate tests/LeadsServiceTest.php
```

Bug Reports
-----------

[](#bug-reports)

Report [here](https://github.com/basecrm/basecrm-php/issues).

Copyright and license
---------------------

[](#copyright-and-license)

Copyright 2015 Zendesk

Licensed under the [Apache License, Version 2.0](LICENSE)

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance49

Moderate activity, may be stable

Popularity49

Moderate usage in the ecosystem

Community28

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~156 days

Recently: every ~248 days

Total

16

Last Release

1785d ago

Major Versions

v0.1.0 → v1.0.02015-04-22

### Community

Maintainers

![](https://www.gravatar.com/avatar/2b3496d0ce8afc093a7e61dc859d72cbf9ae7fa136c17808a9111d411f1542fa?d=identicon)[zendesk-sell](/maintainers/zendesk-sell)

---

Top Contributors

[![bmista](https://avatars.githubusercontent.com/u/1944347?v=4)](https://github.com/bmista "bmista (32 commits)")[![efedasz](https://avatars.githubusercontent.com/u/8776846?v=4)](https://github.com/efedasz "efedasz (14 commits)")[![grzegorz-mysliwiec](https://avatars.githubusercontent.com/u/17003548?v=4)](https://github.com/grzegorz-mysliwiec "grzegorz-mysliwiec (6 commits)")[![marcinbunsch](https://avatars.githubusercontent.com/u/65431?v=4)](https://github.com/marcinbunsch "marcinbunsch (4 commits)")[![DocX](https://avatars.githubusercontent.com/u/132277?v=4)](https://github.com/DocX "DocX (4 commits)")[![struniu](https://avatars.githubusercontent.com/u/5517437?v=4)](https://github.com/struniu "struniu (3 commits)")[![jdabrowa](https://avatars.githubusercontent.com/u/17768929?v=4)](https://github.com/jdabrowa "jdabrowa (2 commits)")[![Frederick888](https://avatars.githubusercontent.com/u/4507647?v=4)](https://github.com/Frederick888 "Frederick888 (2 commits)")[![MaciekLesiczka](https://avatars.githubusercontent.com/u/2060635?v=4)](https://github.com/MaciekLesiczka "MaciekLesiczka (1 commits)")[![pbuchman](https://avatars.githubusercontent.com/u/368465?v=4)](https://github.com/pbuchman "pbuchman (1 commits)")[![fnwbr](https://avatars.githubusercontent.com/u/706419?v=4)](https://github.com/fnwbr "fnwbr (1 commits)")[![webresh](https://avatars.githubusercontent.com/u/3670174?v=4)](https://github.com/webresh "webresh (1 commits)")[![zd-svc-gha-ci-platform](https://avatars.githubusercontent.com/u/246241693?v=4)](https://github.com/zd-svc-gha-ci-platform "zd-svc-gha-ci-platform (1 commits)")

---

Tags

httpapiclienthttp clientv2base crm

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/basecrm-basecrm-php/health.svg)

```
[![Health](https://phpackages.com/badges/basecrm-basecrm-php/health.svg)](https://phpackages.com/packages/basecrm-basecrm-php)
```

###  Alternatives

[aplus/http-client

Aplus Framework HTTP Client Library

2161.6M1](/packages/aplus-http-client)[e-moe/guzzle6-bundle

Integrates Guzzle 6 into your Symfony application

11259.2k](/packages/e-moe-guzzle6-bundle)[jsor/hal-client

A lightweight client for consuming and manipulating Hypertext Application Language (HAL) resources.

2425.9k1](/packages/jsor-hal-client)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
