You are here

function hubspot_get_recent in HubSpot 7

Same name and namespace in other branches
  1. 6.2 hubspot.module \hubspot_get_recent()
  2. 6 hubspot.module \hubspot_get_recent()
  3. 7.3 hubspot.module \hubspot_get_recent()
  4. 7.2 hubspot.module \hubspot_get_recent()

Gets the most recent HubSpot leads

Docs: http://docs.hubapi.com/wiki/Searching_Leads

Parameters

int $n Number of leads to fetch:

1 call to hubspot_get_recent()
hubspot_block_view in ./hubspot.module
Implements hook_block_view() to provide a HubSpot recent leads block.

File

./hubspot.module, line 340
Sends Webform results to HubSpot's Leads API by using Webform's provided hooks.

Code

function hubspot_get_recent($n = 5) {
  $hapiKey = variable_get('hubspot_apikey', '');
  $n = intval($n);
  if (empty($hapiKey)) {
    return array(
      'Error' => t('No HubSpot API key specified.'),
    );
  }
  $r = drupal_http_request("https://hubapi.com/leads/v1/list/?hapikey={$hapiKey}&sort=insertedAt&dir=desc&max={$n}");
  return array(
    'Data' => json_decode($r->data),
    'Error' => isset($r->error) ? $r->error : '',
    'HTTPCode' => $r->code,
  );
}