Kartra Documentation Technical Documentation for Kartra

PHP sample: editing a specific lead

Here’s a very simple PHP sample to EDIT a lead’s details plus, in the same API call, we will also assign a tag (yes, you can chain two or more actions inside the same API call):

<?php

$ch = curl_init();
// CONNECT TO API, VERIFY MY API KEY AND PASSWORD AND GET THE LEAD DATA
curl_setopt($ch, CURLOPT_URL,"https://app.kartra.com/api");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
    http_build_query(
        array(
            'app_id' => 'AIm863DwsOW',
            'api_key' => 'QG9GPLW8G',
            'api_password' => 'kdwFAfwrfVS',
            'lead' => array(
                'id' => '3232323223', //you may pass either ID or EMAIL. If both, the system will pick ID
                'email' => 'JoeSmith@domain.com',
                'first_name' => 'Joe New',
                'last_name' => 'Smith New',
                'custom_fields' => [
                    '0' => [
                               'field_identifier' => 'text1',
                               'field_value' => 'text message'
                           ],
                    '1' => [
                               'field_identifier' => 'dropdown1',
                               'field_value' => '612'
                           ],
                    '2' => [
                               'field_identifier' => 'checkbox1',
                               'field_value' => ['620', '621']
                           ],
                ], // Please read Note (1) below 
                'new_email' => 'JoeSmith+new@domain.com' 
            ), 
            'actions' => array( 
                '0' => array( 
                    'cmd' => 'edit_lead'
                ), 
                '1' => array( 
                    'cmd' => 'assign_tag', 
                    'tag_name' => 'My customer' 
                ) 
            ) 
        ) 
     ) 
  ); // REQUEST CONFIRMATION MESSAGE FROM API… curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $server_output = curl_exec ($ch); curl_close ($ch); $server_json = json_decode($server_output); switch ($server_json->status) { case "Error" : // process what error was about break; case "Success" : // after this you can use the info passed from kartra in your own scripts. // Ex: $server_json->lead_details contains the lead details break; } ?>

 

Note (1): Custom field names must already exist in your Kartra account. Otherwise, if the system cannot find the corresponding custom name, it will ignore it.

© 2024 Kartra All Rights Reserved