I am making callout to PARDOT and displaying prospect data into VF page, the issue is every one hour api_key get expired and I have to manually make a authentication call to pardot to get the api_key. Is there any way through which I can automate this process ?
Here is my authentication method in the rest service.
public void AuthToPardot() {
String email = '[email protected]';
String password = 'test';
String userKey = 'testuserkey';
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 );
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 );// I am getting value here
}