You are here

public function PardotClient::getPardotProspect in Pardot Integration 2.x

Retrieve a Pardot Prospect ID using an email address.

Parameters

string $visitor_email: The email address to use to look up a Pardot Prospect ID.

Return value

mixed The Prospect ID (integer) if found, or an empty string on error.

Overrides PardotClientInterface::getPardotProspect

File

src/Service/PardotClient.php, line 232

Class

PardotClient
Provides methods to execute Pardot API operations.

Namespace

Drupal\pardot\Service

Code

public function getPardotProspect(string $visitor_email) {

  // Build the request to retrieve prospect data from Pardot.
  $post_data = $this
    ->buildDefaultPostData();
  $prospect_options = [
    'email' => $visitor_email,
  ];
  $post_data[RequestOptions::FORM_PARAMS] = array_merge($post_data[RequestOptions::FORM_PARAMS], $prospect_options);

  // Execute the request.
  $prospect_endpoint = "{$this->apibaseUrl}/api/prospect/version/4/do/read/email/{$visitor_email}";
  $response = $this
    ->executePardotOperation($prospect_endpoint, $post_data);
  if (is_array($response)) {
    $prospect_id = $response['prospect']['id'] ?? '';
    return $prospect_id;
  }
  return '';
}