Reading Data

With the fetchRecords(), fetchMyRecords(), searchRecords() methods you can (as an example) pull a list of Accounts, or a list of your newest leads, etc. These are the most widely used and basic processes of the API. An example of implementation using the PHP programming language can be found below.

 

/*
 * Snapforce Workflow #1 - fetchRecords()
 */
// This page uses cURL to pull data from your Snapforce CRM.

// Identify the URL:
$url = 'https://crm2.snapforce.com/sf_receive_request.inc.php';

// Start the process:
$curl = curl_init($url);

$fetchRecords = 'format=xml&api_user=API User&api_key=API Key&module=Leads&status=Active&method=fetchRecords';

// Tell cURL to fail if an error occurs:
curl_setopt($curl, CURLOPT_FAILONERROR, 1); 

// Allow for redirects:
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);

// Assign the returned data to a variable:
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

// Set the timeout:
curl_setopt($curl, CURLOPT_TIMEOUT, 5);

// Use POST:
curl_setopt($curl, CURLOPT_POST, 1);

// Set the POST data:
curl_setopt($curl, CURLOPT_POSTFIELDS, $fetchRecords);

// Execute the transaction:
$r = curl_exec($curl);

// Close the connection:
curl_close($curl);

#####################################
# NOW LETS LOOP THROUGH THE RESULTS #
#####################################
libxml_use_internal_errors(true);    

    $xml = simplexml_load_string($r) or die("Error: Cannot create object");
    #print_r($xml);
    // Output each document
    #echo $xml->leads;
    foreach ($xml as $xml1) {
        echo $xml1->lead_id;
        echo $xml1->type;
        echo $xml1->website;
        echo $xml1->contact_first;
    }