Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save stephenreid/2821580 to your computer and use it in GitHub Desktop.
Save stephenreid/2821580 to your computer and use it in GitHub Desktop.
Pardot Authentication
<?
/**
Written by James Laughlin
http://developer.pardot.com/discussions/questions/55-php-login-example
There seems to be little on this forum that is language specific, so If you are using Drupal or Wordpress, you'll need to build interfaces to Pardot in PHP at some point. Here's a function you can use to retrieve your Pardot credentials in one array object so that you can make your API calls.
**/
// the pardot API key is only good for an hour
// so it's best to get it before every API call
function get_pardot_credentials(){
$pardot_login = '< your pardot userid (email address) >';
$pardot_password = '< your pardot password >';
$pardot_user_key = '< your pardot user key >';
$pardot_api_key = '';
// prepare the array to be returned with everything
// but the API key.
$return_vals = array();
$return_vals[ 'pardot_login' ] = $pardot_login;
$return_vals[ 'pardot_password' ] = $pardot_password;
$return_vals[ 'pardot_user_key' ] = $pardot_user_key;
$url = 'https://pi.pardot.com/api/login/version/3?';
$headers = array( 'Content-Type' => 'application/x-www-form-urlencoded' );
$method = 'POST';
$data = array();
$data[ 'email' ] = $return_vals[ 'pardot_login' ];
$data[ 'password' ] = $return_vals[ 'pardot_password' ];
$data[ 'user_key' ] = $return_vals[ 'pardot_user_key' ];
$queryData = http_build_query( $data , '', '&' );
$result = drupal_http_request( $url, $headers, $method, $queryData );
$xml_response = simplexml_load_string( $result->data );
$return_vals[ 'pardot_api_key' ] = (string)$xml_response->api_key;
return $return_vals;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment