Skip to content

Instantly share code, notes, and snippets.

@iaintshine
Created June 18, 2015 20:57
Show Gist options
  • Save iaintshine/0daa8fbfa890682d956d to your computer and use it in GitHub Desktop.
Save iaintshine/0daa8fbfa890682d956d to your computer and use it in GitHub Desktop.
Base PHP wrapper samples related to leads
<?php
require 'vendor/autoload.php';
function getAccessToken()
{
$token = getenv("BASECRM_ACCESS_TOKEN");
if (!$token) throw new Exception('"BASECRM_ACCESS_TOKEN" environment variable has not been found.');
return $token;
}
// an access token is required
$accessToken = getAccessToken();
// create a new base client instance
$client = new \BaseCRM\Client([
'accessToken' => $accessToken,
'verbose' => true,
]);
// lead attributes
$attributes = [
'first_name' => 'John',
'last_name' => 'Doe',
'email' => '[email protected]',
];
// create a new lead
$lead = $client->leads->create($attributes);
print_r($lead);
// retrieve a lead by an id
$foundLead = $client->leads->get($lead['id']);
print_r($lead);
// retrieve a lead by an email address
// we're using all method because it supports rich filtering options
$foundLeads = $client->leads->all(['email' => $lead['email']]);
$searchedLead = $foundLeads[0]['data'];
print_r($searchedLead);
// update a lead
$lead['title'] = 'CEO';
$lead['website'] = 'company.com';
$updatedLead = $client->leads->update($lead['id'], $lead);
print_r($updatedLead);
// delete a lead
$client->leads->destroy($lead['id']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment