{"id":18656607,"url":"https://github.com/zendesk/basecrm-php","last_synced_at":"2025-05-06T18:08:16.640Z","repository":{"id":26717504,"uuid":"30174888","full_name":"zendesk/basecrm-php","owner":"zendesk","description":"Base CRM API client, PHP edition","archived":false,"fork":false,"pushed_at":"2023-06-25T17:13:30.000Z","size":124,"stargazers_count":23,"open_issues_count":7,"forks_count":20,"subscribers_count":104,"default_branch":"master","last_synced_at":"2025-05-06T18:08:08.822Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zendesk.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-02-02T06:50:43.000Z","updated_at":"2025-01-20T05:58:08.000Z","dependencies_parsed_at":"2024-06-19T01:50:36.616Z","dependency_job_id":"a8f40e83-3c95-4c07-a549-bccf6e193c6d","html_url":"https://github.com/zendesk/basecrm-php","commit_stats":{"total_commits":77,"total_committers":17,"mean_commits":4.529411764705882,"dds":0.6623376623376623,"last_synced_commit":"ffa390eacb3721a435cf88b2c484139b402be4bf"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zendesk%2Fbasecrm-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zendesk%2Fbasecrm-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zendesk%2Fbasecrm-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zendesk%2Fbasecrm-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zendesk","download_url":"https://codeload.github.com/zendesk/basecrm-php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252741369,"owners_count":21797027,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T07:24:19.803Z","updated_at":"2025-05-06T18:08:16.618Z","avatar_url":"https://github.com/zendesk.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# basecrm-php\n\nBaseCRM Official API V2 library client for PHP\n\n## Installation\n\nThe recommended way to install the client is through\n[Composer](http://getcomposer.org).\n\n```bash\n# Install Composer\ncurl -sS https://getcomposer.org/installer | php\n```\n\nNext, run the Composer command to install the latest stable version :\n\n```bash\ncomposer require basecrm/basecrm-php\n```\n\nAfter installing, you need to require Composer's autoloader:\n\n```php\nrequire 'vendor/autoload.php';\n```\n\n## Usage\n\n```php\nrequire 'vendor/autoload.php';\n\n// Then we instantiate a client (as shown below)\n```\n\n### Build a client\n__Using this api without authentication gives an error__\n\n```php\n$client = new \\BaseCRM\\Client(['accessToken' =\u003e '\u003cYOUR_PERSONAL_ACCESS_TOKEN\u003e']);\n```\n\n### Client Options\n\nThe following options are available while instantiating a client:\n\n * __accessToken__: Personal access token\n * __baseUrl__: Base url for the api\n * __userAgent__: Default user-agent for all requests\n * __timeout__: Request timeout\n * __verbose__: Verbose/debug mode\n * __verifySSL__: Whether to verify SSL or not. Default: true\n\n### Architecture\n\nThe library follows few architectural principles you should understand before digging deeper.\n1. Interactions with resources are done via service objects.\n2. Service objects are exposed as properties on client instances.\n3. Service objects expose resource-oriented actions.\n4. Actions return associative arrays.\n\nFor example, to interact with deals API you will use `\\BaseCRM\\DealsService`, which you can get if you call:\n\n```php\n$client = new \\BaseCRM\\Client(['accessToken' =\u003e '\u003cYOUR_PERSONAL_ACCESS_TOKEN\u003e']);\n$client-\u003edeals; // \\BaseCRM\\DealsService\n```\n\nTo retrieve list of resources and use filtering you will call `#all` method:\n\n```php\n$client = new \\BaseCRM\\Client(['accessToken' =\u003e '\u003cYOUR_PERSONAL_ACCESS_TOKEN\u003e']);\n$client-\u003edeals-\u003eall(['organization_id' =\u003e google['id'], 'hot' =\u003e true]);\n```\n\nTo find a resource by it's unique identifier use `#get` method:\n\n```php\n$client = new \\BaseCRM\\Client(['accessToken' =\u003e '\u003cYOUR_PERSONAL_ACCESS_TOKEN\u003e']);\n$client-\u003edeals-\u003eget($id) # =\u003e array\n```\n\nWhen 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:\n\n```php\n$client = new \\BaseCRM\\Client(['accessToken' =\u003e '\u003cYOUR_PERSONAL_ACCESS_TOKEN\u003e']);\n$deal = $client-\u003edeals-\u003ecreate(['name' =\u003e 'Website redesign', 'contact_id' =\u003e $id]);\n```\n\nTo destroy a resource use `#destroy` method:\n\n```php\n$client = new \\BaseCRM\\Client(['accessToken' =\u003e '\u003cYOUR_PERSONAL_ACCESS_TOKEN\u003e']);\n$client-\u003edeals-\u003edestroy($id) // =\u003e true\n```\n\nThere other non-CRUD operations supported as well. Please contact corresponding service files for in-depth documentation.\n\n### Full example\n\nCreate a new organization and after that change it's attributes (website).\n\n```php\n$client = new \\BaseCRM\\Client(['accessToken' =\u003e '\u003cYOUR_PERSONAL_ACCESS_TOKEN\u003e']);\n$lead = $client-\u003eleads-\u003ecreate(['organization_name' =\u003e 'Design service company']);\n\n$lead['website'] = \"http://www.designservices.com\"\n$client-\u003eleads-\u003eupdate($lead['id'], $lead);\n```\n\n### Error handling\n\nWhen you instantiate a client or make any request via service objects, exceptions can be raised for multiple\nof reasons e.g. a network error, an authentication error, an invalid param error etc.\n\nSample below shows how to properly handle exceptions:\n\n```php\ntry\n{\n  // Instantiate a client.\n  $client = new \\BaseCRM\\Client(['accessToken' =\u003e getenv('BASECRM_ACCESS_TOKEN')]);\n  $lead = $client-\u003eleads-\u003ecreate(['organization_name' =\u003e 'Design service company']);\n\n  print_r($lead);\n}\ncatch (\\BaseCRM\\Errors\\ConfigurationError $e)\n{\n  // Invalid client configuration option\n}\ncatch (\\BaseCRM\\Errors\\ResourceError $e)\n{\n  // Resource related error\n  print('Http status = ' . $e-\u003egetHttpStatusCode() . \"\\n\");\n  print('Request ID = ' . $e-\u003egetRequestId() . \"\\n\");\n  foreach ($e-\u003eerrors as $error)\n  {\n    print('field = ' . $error['field'] . \"\\n\");\n    print('code = ' . $error['code'] . \"\\n\");\n    print('message = ' . $error['message'] . \"\\n\");\n    print('details = ' . $error['details'] . \"\\n\");\n  }\n}\ncatch (\\BaseCRM\\Errors\\RequestError $e)\n{\n  // Invalid query parameters, authentication error etc.\n}\ncatch (\\BaseCRM\\Errors\\Connectionerror $e)\n{\n  // Network communication error, curl error is returned\n  print('Errno = ' . $e-\u003egetErrno() . \"\\n\");\n  print('Error message = ' . $e-\u003egetErrorMessage() . \"\\n\");\n}\ncatch (Exception $e)\n{\n  // Other kind of exception\n}\n```\n\n## Sync API\n\nThe following sample code shows how to perform a full synchronization flow using high-level wrapper.\n\nFirst of all you need an instance of `\\BaseCRM\\Client`. High-level `\\BaseCRM\\Sync` wrapper uses `\\BaseCRM\\SyncService` to interact with the Sync API.\nIn 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.\n\n```php\n$client = new \\BaseCRM\\Client(['access_token' =\u003e '\u003cYOUR_PERSONAL_ACCESS_TOKEN\u003e']);\n$sync = new \\BaseCRM\\Sync($client, '\u003cYOUR_DEVICES_UUID');\n```\n\nNow all you have to do is to call `fetch` method and pass a block that you might use to store fetched data to a database.\n\n```php\n$sync-\u003efetch(function ($meta, $data) {\n  $options = [\n    'table' =\u003e $meta['type'],\n    'statement' =\u003e $meta['sync']['event_type'],\n    'properties' =\u003e $data\n  ];\n  return \\DAO::execute($options) ? \\BaseCRM\\Sync::ACK : \\BaseCRM\\Sync::NACK;\n});\n```\n\nNotice that you must call either `#ack` or `#nack` method.\n\n## Resources and actions\n\nDocumentation for every action can be found in corresponding service files under `lib/` directory.\n\n### Account\n\n```php\n$client = new \\BaseCRM\\Client(['accessToken' =\u003e '\u003cYOUR_PERSONAL_ACCESS_TOKEN\u003e');\n$client-\u003eaccounts // =\u003e \\BaseCRM\\AccountsService\n```\n\nActions:\n* Retrieve account details - `client-\u003eaccounts-\u003eself`\n\n### AssociatedContact\n\n```php\n$client = new \\BaseCRM\\Client(['accessToken' =\u003e '\u003cYOUR_PERSONAL_ACCESS_TOKEN\u003e');\n$client-\u003eassociatedContacts // =\u003e \\BaseCRM\\AssociatedContactsService\n```\n\nActions:\n* Retrieve deal's associated contacts - `client-\u003eassociatedContacts-\u003eall`\n* Create an associated contact - `client-\u003eassociatedContacts-\u003ecreate`\n* Remove an associated contact - `client-\u003eassociatedContacts-\u003edestroy`\n\n### Contact\n\n```php\n$client = new \\BaseCRM\\Client(['accessToken' =\u003e '\u003cYOUR_PERSONAL_ACCESS_TOKEN\u003e');\n$client-\u003econtacts // =\u003e \\BaseCRM\\ContactsService\n```\n\nActions:\n* Retrieve all contacts - `client-\u003econtacts-\u003eall`\n* Create a contact - `client-\u003econtacts-\u003ecreate`\n* Retrieve a single contact - `client-\u003econtacts-\u003eget`\n* Update a contact - `client-\u003econtacts-\u003eupdate`\n* Delete a contact - `client-\u003econtacts-\u003edestroy`\n\n### Deal\n\n```php\n$client = new \\BaseCRM\\Client(['accessToken' =\u003e '\u003cYOUR_PERSONAL_ACCESS_TOKEN\u003e');\n$client-\u003edeals // =\u003e \\BaseCRM\\DealsService\n```\n\nActions:\n* Retrieve all deals - `client-\u003edeals-\u003eall`\n* Create a deal - `client-\u003edeals-\u003ecreate`\n* Retrieve a single deal - `client-\u003edeals-\u003eget`\n* Update a deal - `client-\u003edeals-\u003eupdate`\n* Delete a deal - `client-\u003edeals-\u003edestroy`\n\n**Note about deal value**\n\nYou can use either a string or numerical deal value when modifying a deal.\n```php\n$deal['value'] = 10;\n$deal['value'] = 10.10;\n$deal['value'] = \"10.10\";\n```\n\n### Deal Source\n\n```php\n$client = new \\BaseCRM\\Client(['accessToken' =\u003e '\u003cYOUR_PERSONAL_ACCESS_TOKEN\u003e');\n$client-\u003edealSources // =\u003e \\BaseCRM\\DealSourcesService\n```\n\nActions:\n* Retrieve all deal sources - `client-\u003edealSources-\u003eall`\n* Create a deal source - `client-\u003edealSources-\u003ecreate`\n* Retrieve a single deal source - `client-\u003edealSources-\u003eget`\n* Update a deal source - `client-\u003edealSources-\u003eupdate`\n* Delete a deal source - `client-\u003edealSources-\u003edestroy`\n\n### Lead\n\n```php\n$client = new \\BaseCRM\\Client(['accessToken' =\u003e '\u003cYOUR_PERSONAL_ACCESS_TOKEN\u003e');\n$client-\u003eleads // =\u003e \\BaseCRM\\LeadsService\n```\n\nActions:\n* Retrieve all leads - `client-\u003eleads-\u003eall`\n* Create a lead - `client-\u003eleads-\u003ecreate`\n* Retrieve a single lead - `client-\u003eleads-\u003eget`\n* Update a lead - `client-\u003eleads-\u003eupdate`\n* Delete a lead - `client-\u003eleads-\u003edestroy`\n\n### Lead Source\n\n```php\n$client = new \\BaseCRM\\Client(['accessToken' =\u003e '\u003cYOUR_PERSONAL_ACCESS_TOKEN\u003e');\n$client-\u003eleadSources // =\u003e \\BaseCRM\\LeadSourcesService\n```\n\nActions:\n* Retrieve all lead sources - `client-\u003eleadSources-\u003eall`\n* Create a lead source - `client-\u003eleadSources-\u003ecreate`\n* Retrieve a single lead source - `client-\u003eleadSources-\u003eget`\n* Update a lead source - `client-\u003eleadSources-\u003eupdate`\n* Delete a lead source - `client-\u003eleadSources-\u003edestroy`\n\n### Line Item\n\n```php\n$client = new \\BaseCRM\\Client(['accessToken' =\u003e '\u003cYOUR_PERSONAL_ACCESS_TOKEN\u003e');\n$client-\u003elineItems // =\u003e \\BaseCRM\\LineItemsService\n```\n\nActions:\n* Retrieve all line items - `client-\u003elineItems-\u003eall`\n* Create a line item - `client-\u003elineItems-\u003ecreate`\n* Retrieve a single line item- `client-\u003elineItems-\u003eget`\n* Update a line item - `client-\u003elineItems-\u003eupdate`\n* Delete a line item - `client-\u003elineItems-\u003edestroy`\n\n\n### LossReason\n\n```php\n$client = new \\BaseCRM\\Client(['accessToken' =\u003e '\u003cYOUR_PERSONAL_ACCESS_TOKEN\u003e');\n$client-\u003elossReasons // =\u003e \\BaseCRM\\LossReasonsService\n```\n\nActions:\n* Retrieve all reasons - `client-\u003elossReasons-\u003eall`\n* Create a loss reason - `client-\u003elossReasons-\u003ecreate`\n* Retrieve a single reason - `client-\u003elossReasons-\u003eget`\n* Update a loss reason - `client-\u003elossReasons-\u003eupdate`\n* Delete a reason - `client-\u003elossReasons-\u003edestroy`\n\n### Note\n\n```php\n$client = new \\BaseCRM\\Client(['accessToken' =\u003e '\u003cYOUR_PERSONAL_ACCESS_TOKEN\u003e');\n$client-\u003enotes // =\u003e \\BaseCRM\\NotesService\n```\n\nActions:\n* Retrieve all notes - `client-\u003enotes-\u003eall`\n* Create a note - `client-\u003enotes-\u003ecreate`\n* Retrieve a single note - `client-\u003enotes-\u003eget`\n* Update a note - `client-\u003enotes-\u003eupdate`\n* Delete a note - `client-\u003enotes-\u003edestroy`\n\n### Order\n\n```php\n$client = new \\BaseCRM\\Client(['accessToken' =\u003e '\u003cYOUR_PERSONAL_ACCESS_TOKEN\u003e');\n$client-\u003eorders // =\u003e \\BaseCRM\\OrdersService\n```\n\nActions:\n* Retrieve all orders - `client-\u003eorders-\u003eall`\n* Create an order - `client-\u003eorders-\u003ecreate`\n* Retrieve a single order - `client-\u003eorders-\u003eget`\n* Update an order - `client-\u003eorders-\u003eupdate`\n* Delete an order - `client-\u003eorders-\u003edestroy`\n\n### Pipeline\n\n```php\n$client = new \\BaseCRM\\Client(['accessToken' =\u003e '\u003cYOUR_PERSONAL_ACCESS_TOKEN\u003e');\n$client-\u003epipelines // =\u003e \\BaseCRM\\PipelinesService\n```\n\nActions:\n* Retrieve all pipelines - `client-\u003epipelines-\u003eall`\n\n### Product\n\n```php\n$client = new \\BaseCRM\\Client(['accessToken' =\u003e '\u003cYOUR_PERSONAL_ACCESS_TOKEN\u003e');\n$client-\u003eproducts // =\u003e \\BaseCRM\\ProductsService\n```\n\nActions:\n* Retrieve all products - `client-\u003eproducts-\u003eall`\n* Create a product - `client-\u003eproducts-\u003ecreate`\n* Retrieve a single product - `client-\u003eproducts-\u003eget`\n* Update a product - `client-\u003eproducts-\u003eupdate`\n* Delete a product - `client-\u003eproducts-\u003edestroy`\n\n### Source (Deprecated! Use Lead Source, Deal Source instead)\n\n```php\n$client = new \\BaseCRM\\Client(['accessToken' =\u003e '\u003cYOUR_PERSONAL_ACCESS_TOKEN\u003e');\n$client-\u003esources // =\u003e \\BaseCRM\\SourcesService\n```\n\nActions:\n* Retrieve all sources - `client-\u003esources-\u003eall`\n* Create a source - `client-\u003esources-\u003ecreate`\n* Retrieve a single source - `client-\u003esources-\u003eget`\n* Update a source - `client-\u003esources-\u003eupdate`\n* Delete a source - `client-\u003esources-\u003edestroy`\n\n### Stage\n\n```php\n$client = new \\BaseCRM\\Client(['accessToken' =\u003e '\u003cYOUR_PERSONAL_ACCESS_TOKEN\u003e');\n$client-\u003estages // =\u003e \\BaseCRM\\StagesService\n```\n\nActions:\n* Retrieve all stages - `client-\u003estages-\u003eall`\n\n### Tag\n\n```php\n$client = new \\BaseCRM\\Client(['accessToken' =\u003e '\u003cYOUR_PERSONAL_ACCESS_TOKEN\u003e');\n$client-\u003etags // =\u003e \\BaseCRM\\TagsService\n```\n\nActions:\n* Retrieve all tags - `client-\u003etags-\u003eall`\n* Create a tag - `client-\u003etags-\u003ecreate`\n* Retrieve a single tag - `client-\u003etags-\u003eget`\n* Update a tag - `client-\u003etags-\u003eupdate`\n* Delete a tag - `client-\u003etags-\u003edestroy`\n\n### Task\n\n```php\n$client = new \\BaseCRM\\Client(['accessToken' =\u003e '\u003cYOUR_PERSONAL_ACCESS_TOKEN\u003e');\n$client-\u003etasks // =\u003e \\BaseCRM\\TasksService\n```\n\nActions:\n* Retrieve all tasks - `client-\u003etasks-\u003eall`\n* Create a task - `client-\u003etasks-\u003ecreate`\n* Retrieve a single task - `client-\u003etasks-\u003eget`\n* Update a task - `client-\u003etasks-\u003eupdate`\n* Delete a task - `client-\u003etasks-\u003edestroy`\n\n### TextMessage\n\n```php\n$client = new \\BaseCRM\\Client(['accessToken' =\u003e '\u003cYOUR_PERSONAL_ACCESS_TOKEN\u003e');\n$client-\u003etextMessages // =\u003e \\BaseCRM\\TextMessagesService\n```\n\nActions:\n* Retrieve text messages - `client-\u003etextMessages-\u003eall`\n* Retrieve a single text message - `client-\u003etextMessages-\u003eget`\n\n### User\n\n```php\n$client = new \\BaseCRM\\Client(['accessToken' =\u003e '\u003cYOUR_PERSONAL_ACCESS_TOKEN\u003e');\n$client-\u003eusers // =\u003e \\BaseCRM\\UsersService\n```\n\nActions:\n* Retrieve all users - `client-\u003eusers-\u003eall`\n* Retrieve a single user - `client-\u003eusers-\u003eget`\n* Retrieve an authenticating user - `client-\u003eusers-\u003eself`\n\n### Visit\n\n```php\n$client = new \\BaseCRM\\Client(['accessToken' =\u003e '\u003cYOUR_PERSONAL_ACCESS_TOKEN\u003e');\n$client-\u003evisits // =\u003e \\BaseCRM\\VisitsService\n```\n\nActions:\n* Retrieve visits - `client-\u003evisits-\u003eall`\n\n### VisitOutcome\n\n```php\n$client = new \\BaseCRM\\Client(['accessToken' =\u003e '\u003cYOUR_PERSONAL_ACCESS_TOKEN\u003e');\n$client-\u003evisitOutcomes // =\u003e \\BaseCRM\\VisitOutcomesService\n```\n\nActions:\n* Retrieve visit outcomes - `client-\u003evisitOutcomes-\u003eall`\n\n\n## Tests\n\nInstall PHPUnit via Composer:\n\n```bash\n$ composer install\n```\n\nTo run all test suites:\n\n```bash\n$ BASECRM_ACCESS_TOKEN=\u003cyour-token-here\u003e ./vendor/bin/phpunit\n```\n\nAnd to run a single suite:\n\n```bash\n$ BASECRM_ACCESS_TOKEN=\u003cyour-token-here\u003e ./vendor/bin/phpunit --filter testUpdate tests/LeadsServiceTest.php\n```\n\n## Bug Reports\nReport [here](https://github.com/basecrm/basecrm-php/issues).\n\n## Copyright and license\n\nCopyright 2015 Zendesk\n\nLicensed under the [Apache License, Version 2.0](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzendesk%2Fbasecrm-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzendesk%2Fbasecrm-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzendesk%2Fbasecrm-php/lists"}