Created
June 18, 2015 20:57
-
-
Save iaintshine/0daa8fbfa890682d956d to your computer and use it in GitHub Desktop.
Base PHP wrapper samples related to leads
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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