0

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 = 'test@gmail.com';
        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
  } 
1

In Visualforce, you can just use an action poller:

<apex:actionPoller interval="3600" action="{!authToPardot}" reRender="page" />

This snippet here sets up a 3,600 second timer to call the AuthToPardot function, and reRender an element with the id of "page" (this is optional, but avoids refreshing the entire page, so it looks nicer).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.