This guide will show you how to add a new contact to ActiveCampaign when a user submits a Quform form. Choose one of the 3 different examples below, depending on your needs.

Add a contact

Add the following code to the WordPress theme functions.php file (or create a plugin for it).

1234
5
6
7891011
12
13
14
15
16
17
18
19
20
21
22
add_filter('quform_post_process_1', function (array $result, Quform_Form $form) {    $apiUrl = 'https://example.api-us1.com';    $apiKey = 'yourApiKey'; 
    $data = array(
        'contact' => array(
            'email' => $form->getValue('quform_1_4'),            'firstName' => $form->getValue('quform_1_3')[2],            'lastName' => $form->getValue('quform_1_3')[4],            'phone' => $form->getValue('quform_1_5')        )
    );
 
    wp_remote_post($apiUrl . '/api/3/contact/sync', array(
        'headers' => array(
            'Api-Token' => $apiKey
        ),
        'body' => wp_json_encode($data)
    ));
 
    return $result;
}, 10, 2);
add_filter('quform_post_process_1', function (array $result, Quform_Form $form) {
    $apiUrl = 'https://example.api-us1.com';
    $apiKey = 'yourApiKey';

    $data = array(
        'contact' => array(
            'email' => $form->getValue('quform_1_4'),
            'firstName' => $form->getValue('quform_1_3')[2],
            'lastName' => $form->getValue('quform_1_3')[4],
            'phone' => $form->getValue('quform_1_5')
        )
    );

    wp_remote_post($apiUrl . '/api/3/contact/sync', array(
        'headers' => array(
            'Api-Token' => $apiKey
        ),
        'body' => wp_json_encode($data)
    ));

    return $result;
}, 10, 2);
  • On line 1, replace the number 1 with the form ID
  • On line 2, replace https://example.api-us1.com with your ActiveCampaign API Access URL (see below)
  • On line 3, replace yourApiKey the ActiveCampaign API Access Key (see below)
  • On line 7, replace 1_4 with the Email element unique ID
  • On lines 8 and 9, replace 1_3 with the Name element unique ID if the form has a Name element, otherwise these lines can be removed
  • On line 10, replace 1_5 with the Phone element unique ID if the form has a Phone element, otherwise this line can be removed

Add a contact + add to a list

Add the following code to the WordPress theme functions.php file (or create a plugin for it).

1234
5
6
7891011
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
3031
32
33
34
35
36
37
38
39
add_filter('quform_post_process_1', function (array $result, Quform_Form $form) {    $apiUrl = 'https://example.api-us1.com';    $apiKey = 'yourApiKey'; 
    $data = array(
        'contact' => array(
            'email' => $form->getValue('quform_1_4'),            'firstName' => $form->getValue('quform_1_3')[2],            'lastName' => $form->getValue('quform_1_3')[4],            'phone' => $form->getValue('quform_1_5')        )
    );
 
    $response = wp_remote_post($apiUrl . '/api/3/contact/sync', array(
        'headers' => array(
            'Api-Token' => $apiKey
        ),
        'body' => wp_json_encode($data)
    ));
 
    $response = json_decode(wp_remote_retrieve_body($response), true);
 
    if (is_array($response) && isset($response['contact']['id'])) {
        wp_remote_post($apiUrl . '/api/3/contactLists', array(
            'headers' => array(
                'Api-Token' => $apiKey
            ),
            'body' => wp_json_encode(array(
                'contactList' => array(
                    'list' => 2,                    'contact' => $response['contact']['id'],
                    'status' => 1
                )
            ))
        ));
    }
 
    return $result;
}, 10, 2);
add_filter('quform_post_process_1', function (array $result, Quform_Form $form) {
    $apiUrl = 'https://example.api-us1.com';
    $apiKey = 'yourApiKey';

    $data = array(
        'contact' => array(
            'email' => $form->getValue('quform_1_4'),
            'firstName' => $form->getValue('quform_1_3')[2],
            'lastName' => $form->getValue('quform_1_3')[4],
            'phone' => $form->getValue('quform_1_5')
        )
    );

    $response = wp_remote_post($apiUrl . '/api/3/contact/sync', array(
        'headers' => array(
            'Api-Token' => $apiKey
        ),
        'body' => wp_json_encode($data)
    ));

    $response = json_decode(wp_remote_retrieve_body($response), true);

    if (is_array($response) && isset($response['contact']['id'])) {
        wp_remote_post($apiUrl . '/api/3/contactLists', array(
            'headers' => array(
                'Api-Token' => $apiKey
            ),
            'body' => wp_json_encode(array(
                'contactList' => array(
                    'list' => 2,
                    'contact' => $response['contact']['id'],
                    'status' => 1
                )
            ))
        ));
    }

    return $result;
}, 10, 2);
  • On line 1, replace the number 1 with the form ID
  • On line 2, replace https://example.api-us1.com with your ActiveCampaign API Access URL (see below)
  • On line 3, replace yourApiKey the ActiveCampaign API Access Key (see below)
  • On line 7, replace 1_4 with the Email element unique ID
  • On lines 8 and 9, replace 1_3 with the Name element unique ID if the form has a Name element, otherwise these lines can be removed
  • On line 10, replace 1_5 with the Phone element unique ID if the form has a Phone element, otherwise this line can be removed
  • On line 30, replace the number 2 with the ActiveCampaign List ID, which you can find in the browser address bar when viewing a list in the ActiveCampaign Dashboard:
    ActiveCampaign List ID

Add a contact + add a tag

Add the following code to the WordPress theme functions.php file (or create a plugin for it).

1234
5
6
7891011
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
3132
33
34
35
36
37
38
add_filter('quform_post_process_1', function (array $result, Quform_Form $form) {    $apiUrl = 'https://example.api-us1.com';    $apiKey = 'yourApiKey'; 
    $data = array(
        'contact' => array(
            'email' => $form->getValue('quform_1_4'),            'firstName' => $form->getValue('quform_1_3')[2],            'lastName' => $form->getValue('quform_1_3')[4],            'phone' => $form->getValue('quform_1_5')        )
    );
 
    $response = wp_remote_post($apiUrl . '/api/3/contact/sync', array(
        'headers' => array(
            'Api-Token' => $apiKey
        ),
        'body' => wp_json_encode($data)
    ));
 
    $response = json_decode(wp_remote_retrieve_body($response), true);
 
    if (is_array($response) && isset($response['contact']['id'])) {
        wp_remote_post($apiUrl . '/api/3/contactTags', array(
            'headers' => array(
                'Api-Token' => $apiKey
            ),
            'body' => wp_json_encode(array(
                'contactTag' => array(
                    'contact' => $response['contact']['id'],
                    'tag' => 1                )
            ))
        ));
    }
 
    return $result;
}, 10, 2);
add_filter('quform_post_process_1', function (array $result, Quform_Form $form) {
    $apiUrl = 'https://example.api-us1.com';
    $apiKey = 'yourApiKey';

    $data = array(
        'contact' => array(
            'email' => $form->getValue('quform_1_4'),
            'firstName' => $form->getValue('quform_1_3')[2],
            'lastName' => $form->getValue('quform_1_3')[4],
            'phone' => $form->getValue('quform_1_5')
        )
    );

    $response = wp_remote_post($apiUrl . '/api/3/contact/sync', array(
        'headers' => array(
            'Api-Token' => $apiKey
        ),
        'body' => wp_json_encode($data)
    ));

    $response = json_decode(wp_remote_retrieve_body($response), true);

    if (is_array($response) && isset($response['contact']['id'])) {
        wp_remote_post($apiUrl . '/api/3/contactTags', array(
            'headers' => array(
                'Api-Token' => $apiKey
            ),
            'body' => wp_json_encode(array(
                'contactTag' => array(
                    'contact' => $response['contact']['id'],
                    'tag' => 1
                )
            ))
        ));
    }

    return $result;
}, 10, 2);
  • On line 1, replace the number 1 with the form ID
  • On line 2, replace https://example.api-us1.com with your ActiveCampaign API Access URL (see below)
  • On line 3, replace yourApiKey the ActiveCampaign API Access Key (see below)
  • On line 7, replace 1_4 with the Email element unique ID
  • On lines 8 and 9, replace 1_3 with the Name element unique ID if the form has a Name element, otherwise these lines can be removed
  • On line 10, replace 1_5 with the Phone element unique ID if the form has a Phone element, otherwise this line can be removed
  • On line 31, replace the number 1 with the ActiveCampaign Tag ID, which you can find in the browser address bar when you filter contacts by tag in the ActiveCampaign Dashboard:
    ActiveCampaign Tag ID

How to get your ActiveCampaign API Access URL & Key

Log in to ActiveCampaign and go to Settings → Developer where you will find the fields containing your ActiveCampaign API Access URL & Key to use in the code above.

Where to find ActiveCampaign API URL and Key

Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy