You are here

public function Salesforce::apiCall in Salesforce Suite 7.3

Make a call to the Salesforce REST API.

Parameters

string $path: Path to resource.

array $params: Parameters to provide.

string $method: Method to initiate the call, such as GET or POST. Defaults to GET.

string $type: Type of object to request. Defaults to 'rest'. Most common examples:

  • rest - Call the standard Salesforce REST API.
  • apexrest - Call a custom REST URL defined in Salesforce.

Return value

mixed The requested response.

Throws

SalesforceException

13 calls to Salesforce::apiCall()
Salesforce::getDeleted in includes/salesforce.inc
Retrieves the list of individual objects that have been deleted within the given timespan for a specified object type.
Salesforce::getUpdated in includes/salesforce.inc
Return a list of SFIDs for the given object, which have been created or updated in the given timeframe.
Salesforce::listResources in includes/salesforce.inc
Return a list of available resources for the configured API version.
Salesforce::objectCreate in includes/salesforce.inc
Create a new object of the given type.
Salesforce::objectDelete in includes/salesforce.inc
Delete a Salesforce object.

... See full list

File

includes/salesforce.inc, line 112
Objects, properties, and methods to communicate with the Salesforce REST API

Class

Salesforce
Ability to authorize and communicate with the Salesforce REST API.

Code

public function apiCall($path, $params = array(), $method = 'GET', $type = 'rest') {
  if (!$this
    ->getAccessToken()) {
    $this
      ->refreshToken();
  }
  $this->response = $this
    ->apiHttpRequest($path, $params, $method, $type);
  switch ($this->response->code) {

    // The session ID or OAuth token used has expired or is invalid.
    case 401:

      // Refresh token.
      $this
        ->refreshToken();

      // Rebuild our request and repeat request.
      $this->response = $this
        ->apiHttpRequest($path, $params, $method, $type);

      // Throw an error if we still have bad response.
      if (!in_array($this->response->code, array(
        200,
        201,
        204,
      ))) {
        throw new SalesforceException($this->response->error, $this->response->code);
      }
      break;
    case 200:
    case 201:
    case 204:

      // All clear.
      break;
    default:

      // We have problem and no specific Salesforce error provided.
      if (empty($this->response->data)) {
        throw new SalesforceException($this->response->error, $this->response->code);
      }
  }
  $data = drupal_json_decode($this->response->data);
  if (empty($data[0])) {
    $this
      ->checkResponseDataForApiError($data);
  }
  else {
    foreach ($data as $item) {
      $this
        ->checkResponseDataForApiError($item);
    }
    if (count($data) == 1) {
      $data = $data[0];
    }
  }
  return $data;
}