Last active
February 24, 2020 21:00
-
-
Save douglascayers/0247af2e382ebc58737d16a7cdbe83d0 to your computer and use it in GitHub Desktop.
Sample Apex HTTP Callout to Pardot API http://developer.pardot.com/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() ); |
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
Thanks for sharing...