Sunday, July 30, 2017

Integrate with Active Campaign

>>To integrate with Active campaign first register with free trail edition by the below link

http://www.activecampaign.com/free/


>> After logging in create a list by clicking on LIST TAB


>>At the complete right top of the screen,click on your profile and click on my settings.

>>under your settings take the key and url and use them in the following code.

Ex: Key='a1228bae475b1f07c64dbf7d4018758c5f3cxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';

      url='https://sfdc550.activehosted.com;

>> please register Active campaign url in the salesforce remote site settings.

EX: https://tcs550.activehosted.com


Step 1:

create below class in the Salesforce org, this is to control recursion

public class recursioncontrol {     public static boolean firstRun = true;  }
   
Step 2:
create below class in the Salesforce org, this contains http code.

public class activecamp { @future (callout=true) public static void contactcreation(string firstname, string lastname, string email) { String APIkey='a1228bae475b1f07c64dbf7d4018758c5f3cac6b036c4c0c1afa70e5051c1cd5dcbd099b'; String apiaction='contact_add'; string hostname='https://tcs550.api-us1.com/admin/api.php?'; string apioutput='json'; String thirdpartyendpoint=hostname+'api_key='+APIkey+'&api_action='+apiaction+'&api_output='+apioutput;  HttpRequest req=new HttpRequest();     req.setMethod('POST');          req.setEndpoint(thirdpartyendpoint);              req.setBody('Content-Type=application/x-www-form-urlencoded');               string targetString='email='+email +'&first_name='+firstname+'&last_name='+lastname+'&p[1]=1';     req.setBody('Content-Length="512"');  req.setBody(targetString);     System.debug('HttpRequest :' +req); System.debug('HttpRequest :' +req.getBody());  HttpResponse response = null;     Http http = new Http();     response = http.send(req); system.debug('@@@@@@@@@@@'+response);     system.debug('@@@@@@@@@@@'+response.getBody()); } }

Step 3:

Copy this code in the contact triggers, this helps to integrate in real time
trigger syncwithactivecampaigns on Contact (after insert, after update) {



For(Contact c1:Trigger.new){

if(recursioncontrol.firstrun){

//activecampint.contactupdatecreation(c1.firstname,c1.lastname,c1.email,integer.valueof(c1.phone));

activecamp.contactcreation(c1.firstname,c1.lastname,c1.email);

recursioncontrol.firstrun=false;
}

}


}

No comments:

Post a Comment