-
-
Save vnktsf/06a717c7b73eee0bb3e88ac488a19905 to your computer and use it in GitHub Desktop.
Sample Apex HTTP Callout to Pardot API http://developer.pardot.com/
This file contains hidden or 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() ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment