示例#1
0
#!/usr/bin/env php
<?php 
// Configuration:
$apiKey = 'YOUR API KEY HERE';
$username = '******';
// End of configuration
require_once '../NutshellApi.php';
$api = new NutshellApi($username, $apiKey);
/**
 * Example: editing a lead
 * 
 * We will add a contact and change the confidence for a lead.
 * To keep the existing contacts, we need to include them in our request.
 * 
 * Relevant documentation:
 * http://nutshell.com/api/retrieving-editing.html
 * http://www.nutshell.com/api/revs-etags.html
 */
// Get the lead so we have an up-to-date rev and the current contacts array
$leadId = 1600;
$params = array('leadId' => $leadId);
$oldLead = $api->call('getLead', $params);
$rev = $oldLead->rev;
$oldContacts = $oldLead->contacts;
// Build new contacts array containing the old contacts plus the one we want to add
$contacts = array();
foreach ($oldContacts as $contact) {
    $contacts[] = array('id' => $contact->id, 'relationship' => $contact->relationship, 'entityType' => 'Contacts');
}
$contacts[] = array('relationship' => 'additional contact', 'id' => 17, 'entityType' => 'Contacts');
// edit the lead
示例#2
0
#!/usr/bin/env php
<?php 
// Configuration:
$apiKey = 'YOUR API KEY HERE';
$username = '******';
// End of configuration
require_once '../NutshellApi.php';
$api = new NutshellApi($username, $apiKey);
/**
 * Example: Retrieving entities from the Nutshell API using find* and get* methods
 * 
 * Relevant documentation:
 * http://www.nutshell.com/api/retrieving-editing.html
 * http://www.nutshell.com/api/finding-searching.html
 */
// Retrieve a contact
echo "getContact example\n------------------------------------------------\n";
$params = array('contactId' => 132);
$result = $api->call('getContact', $params);
var_dump($result);
// Find contacts attached to lead #1209
echo "\nfindContacts example\n------------------------------------------------\n";
$params = array('query' => array('leadId' => 1209));
$result = $api->findContacts($params);
var_dump($result);
echo "\n";
示例#3
0
#!/usr/bin/env php
<?php 
// Configuration:
$apiKey = 'YOUR API KEY HERE';
$username = '******';
// End of configuration
require_once '../NutshellApi.php';
$api = new NutshellApi($username, $apiKey);
/**
 * Example: creating an account, contact, and lead
 * 
 * We will create a new contact, then add a new account associated with that contact,
 * then finally create a new lead involving that account/contact.
 * 
 * Relevant documentation:
 * http://www.nutshell.com/api/detail/class_nut___api___core.html
 */
// Create a new contact and save its ID to $newContactId
$params = array('contact' => array('name' => 'Joan Smith', 'phone' => array('734-555-9090', 'cell' => '734-555-6711'), 'email' => array('*****@*****.**', 'blackberry' => '*****@*****.**')));
$newContact = $api->call('newContact', $params);
$newContactId = $newContact->id;
// Create a new account that includes the contact we just added
$params = array('account' => array('name' => 'Arbor Medical LLC', 'industryId' => 1, 'url' => array('http://example.com', 'http://suppliers.example.com'), 'phone' => array('734-234-9990'), 'contacts' => array(array('id' => $newContactId, 'relationship' => 'Purchasing Manager')), 'address' => array('office' => array('address_1' => '220 Depot St', 'city' => 'Ann Arbor', 'state' => 'MI', 'postalCode' => '48104'))));
$newAccount = $api->newAccount($params);
$newAccountId = $newAccount->id;
// Finally, create a lead that includes the account we just added
$params = array('lead' => array('primaryAccount' => array('id' => $newAccountId), 'confidence' => 70, 'market' => array('id' => 1), 'contacts' => array(array('relationship' => 'First Contact', 'id' => $newContactId)), 'products' => array(array('relationship' => '', 'quantity' => 15, 'price' => array('currency_shortname' => 'USD', 'amount' => 1000), 'id' => 4)), 'sources' => array(array('id' => 2)), 'assignee' => array('entityType' => 'Teams', 'id' => 1000)));
$result = $api->newLead($params);
var_dump($result);
echo "\n";