Skip to content

Instantly share code, notes, and snippets.

@douglascayers
Last active February 24, 2020 21:00
Show Gist options
  • Select an option

  • Save douglascayers/0247af2e382ebc58737d16a7cdbe83d0 to your computer and use it in GitHub Desktop.

Select an option

Save douglascayers/0247af2e382ebc58737d16a7cdbe83d0 to your computer and use it in GitHub Desktop.
Sample Apex HTTP Callout to Pardot API http://developer.pardot.com/
String email = '<pardot email/username>';
String password = '<pardot password>';
String userKey = '<pardot user key>';
HttpRequest req = new HttpRequest();
req.setEndpoint( 'https://pi.pardot.com/api/login/version/4' );
req.setMethod( 'POST' );
req.setBody( 'email=' + email + '&password=' + password + '$&user_key=' + userKey );
HttpResponse res = new Http().send( req );
System.debug( res );
System.debug( res.getStatus() );
System.debug( res.getBody() );
// poor man's parsing to retrieve api key without using xml/dom parser
String response = res.getBody();
Integer startIdx = response.indexOf( '<api_key>' ) + 9;
Integer endIdx = response.indexOf( '</api_key>' );
String apiKey = response.substring( startIdx, endIdx );
System.debug( apiKey );
req = new HttpRequest();
req.setEndpoint( 'https://pi.pardot.com/api/event/version/4/do/read' );
req.setMethod( 'POST' );
req.setBody( 'user_key=a911aefbf2f3ab4b70e797123ffac8a7&api_key=' + apiKey );
res = new Http().send( req );
System.debug( res );
System.debug( res.getStatus() );
System.debug( res.getBody() );
@vnktsf
Copy link
Copy Markdown

vnktsf commented Feb 7, 2020

Thanks for sharing...

@MowAlon
Copy link
Copy Markdown

MowAlon commented Feb 24, 2020

Thank you. This helped me out... but it looks like you left your personal API key in line 26. Also, there's a stray '$' in line 8. It didn't work until I removed that character.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment