0

I want to integrate salesforce with ActiveCampighn using the Api key and Url of ActiveCampighn through Http Post method. I want to create a contact from Salesforce to Active campaign. I tried with the below code snippet and got 200(Success) status. But the contact is not available in Active Campaign.

HttpRequest req = new HttpRequest();
req.setEndpoint('http://navsoft12350.activehosted.com/admin/api.php?api_action=contact_add');
req.setMethod('POST');
req.setHeader('Authorization', 'key={!$Credential.Password}');
string body = ' "contact": [ ' +
' { ' +
' "id": 12, ' +
' "email": "jsmith@example.com", ' +
' "firstName": "John", ' +
' "lastName": "smith", ' +
' "p[123]": "123", ' +
' "phone": 122222222' +
' }' +
' ]';
req.setBody(body);
Http http = new Http();
HTTPResponse res = http.send(req);

Kindly provide me any feasible solution of this one.

1

API Parameters should be URL encoded. They don't accept any other input formats like JSON.

https://www.activecampaign.com/api/example.php?call=contact_add

See the image

Here is an example of add contact in active campaign from Salesforce Apex

String key = 'Get FROM https://{{Host}}.activehosted.com/app/settings/developer';

    String authUrl = 'https://{{Host}.api-us1.com/admin/api.php?api_action=contact_add&api_key='+key;
    Http http = new Http();
    HttpRequest request = new HttpRequest();
    request.setEndpoint(authUrl);
    request.setMethod('POST');
    request.setHeader('Content-Type', 'application/x-www-form-urlencoded');
    String payload = 'email='+EncodingUtil.urlEncode('test@example.com','UTF-8')+'&FirstName='+EncodingUtil.urlEncode('FirstName','UTF-8')+'&last_name='+EncodingUtil.urlEncode('last_name','UTF-8')+'&customer_acct_name='+EncodingUtil.urlEncode('Acme, Inc.','UTF-8');
    System.debug(payload);

    request.setBody(payload);
    HttpResponse response = http.send(request);

    if (response.getStatusCode() != 200) {
        System.debug('The status code returned was not expected: ' + response.getStatusCode() + ' ' + response.getStatus());
    } else {
        System.debug(response.getBody());
    }
|improve this answer|||||
  • !!Thank you very much, sir. It's working. – Sam Jan 9 at 9:26

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.