You are here

public function Hubspot::getHubspotForms in HubSpot 8

Get hubspot forms and fields from their API.

Return value

array The hubspot forms.

Throws

\GuzzleHttp\Exception\GuzzleException

File

src/Hubspot.php, line 164

Class

Hubspot
Define a service for interacting with the HubSpot CRM.

Namespace

Drupal\hubspot

Code

public function getHubspotForms() : array {
  static $hubspot_forms;
  if (!isset($hubspot_forms)) {
    $api = 'https://api.hubapi.com/forms/v2/forms';
    $url = Url::fromUri($api)
      ->toString();
    $response = $this
      ->request('GET', $url);
    if (isset($response['error'])) {
      return [];
    }
    else {
      $hubspot_forms = $response['value'] ?? [];
    }
  }
  return $hubspot_forms;
}