You are here

function hubspot_get_recent in HubSpot 6

Same name and namespace in other branches
  1. 6.2 hubspot.module \hubspot_get_recent()
  2. 7.3 hubspot.module \hubspot_get_recent()
  3. 7 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 in ./hubspot.module
Implements hook_block() to provide a HubSpot recent leads block.

File

./hubspot.module, line 323
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.'),
    );
  }
  $hubSpotURL = "https://hubapi.com/leads/v1/list/?hapikey={$hapiKey}&sort=insertedAt&dir=desc&max={$n}";
  $r = drupal_http_request($hubSpotURL);
  return array(
    'Data' => json_decode($r->data),
    'Error' => isset($r->error) ? $r->error : '',
    'HTTPCode' => $r->code,
  );
}