2017 © Pedro Peláez
 

library salesforce-rest-api

Experimental Salesforce rest & bulk api

image

diimpp/salesforce-rest-api

Experimental Salesforce rest & bulk api

  • Tuesday, January 26, 2016
  • by diimpp
  • Repository
  • 1 Watchers
  • 1 Stars
  • 1,903 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 2 % Grown

The README.md

Salesforce Rest&Bulk API

Experimental Salesforce REST and Bulk API implementation, that designed in fashion of facebook php ads sdk., (*1)

Currently supports only bulk requests partially., (*2)

Installation


composer.phar require diimpp/salesforce-rest-api

Usage

$api = \Diimpp\Salesforce\Api::init($accessToken, $instanceUrl);
// or
// $api = \Diimpp\Salesforce\Api::initWithAuthentication($clientId, $clientSecret, $username, $password);

// Example usage of bulk api query.
$job = new Job($api);
$job->create([
    'operation' => Job::OPERATION_QUERY,
    'object' => 'Contact',
    'contentType' => Job::CONTENT_TYPE_XML
]);

$soql = 'select id, lastname, firstname, salutation, name from Contact';

$jobBatch = new JobBatch($job, $api);
$jobBatch->create(['body' => $soql]);
$job->close();

// Wait till job batch will be completed.
while (JobBatch::STATE_QUEUED === $jobBatch->state || JobBatch::STATE_IN_PROGRESS === $jobBatch->state) {
    $jobBatch->read();
}
if (JobBatch::STATE_COMPLETED !== $jobBatch->state) {
    throw new \RuntimeException(sprintf('Salesforce Job Batch request failed with reason: %s', print_r($jobBatch->getData(), true)));
}

$jobBatchResult = new JobBatchResult($jobBatch);
$jobBatchResult->read();

// Salesforce API returns either ID as string or array of IDs of batch results.
if (is_string($jobBatchResult->result)) {
    $data = $jobBatchResult->retrieveData($jobBatchResult->result));
} elseif (is_array($jobBatchResult->result)) {
    foreach ($jobBatchResult->result as $resultId) {
        $data[] = $jobBatchResult->retrieveData($resultId));
    }
}

Contributions

Patches and use cases are most welcome., (*3)

The Versions

26/01 2016

dev-master

9999999-dev https://github.com/diimpp/salesforce-rest-api

Experimental Salesforce rest & bulk api

  Sources   Download

MIT

The Requires

 

by Dmitri Perunov

api rest salesforce bulk