<?php

//Initialize the CURL handle with our Controller URL.
$ch curl_init('https://apps.net-results.com/api/v2/rpc/server.php?Controller=Contact');

//Tell CURL we want responses returned to us when we execute.
curl_setopt($chCURLOPT_RETURNTRANSFERtrue);

//recommend to use a unique, api only user, so you can trace data changes.
//Don't forget to actually add the user in the interface!
//This uses HTTP-Auth, which is built into the HTTP Protocol. Curl supports this natively.
curl_setopt($chCURLOPT_USERPWD'api-user@your-domain.com:sekritpassword');

//please ensure you are validating the server certificate to prevent man in the middle security attacks.
curl_setopt($chCURLOPT_SSL_VERIFYPEERtrue);

//you can turn off client certificate validation.
curl_setopt($chCURLOPT_SSL_VERIFYHOST2);

curl_setopt($chCURLOPT_POSTFIELDS,
    
json_encode(
        array(
            
//A value is required but it may be any value you choose used to identify unique calls.
            //You must pass a value - please be sure when filing support requests to include the value you submitted here, so we can find it.
            
'id' => uniqid('sample-00001'),
            
'method' => 'submitContactImport',
            
'jsonrpc' => '2.0',
            
'params' => array(
                
'contacts' => array(
                    array(
                        
'email address' => 'newcontact@mydomain.com',
                        
'visitor_id' => $_COOKIE['__mauuid'],
                        
'first' => 'New',
                        
'last' => 'Contact',
                    ),
                    array(
                        
'email address' => 'johndoe@johndoe.com',
                        
'visitor_id' => $_COOKIE['__mauuid'],
                        
'first' => 'John',
                        
'last' => 'Doe',
                    )
                ),

                
//if the contact exists, update them with this info. if they don't, create the contact.
                
'overwrite' => true,

                
//left hand side of this map represent the column names you used above in the 'contacts' array.
                //right hand side of this map are the Attribute names in our system. They must match exactly the names in our system. you can find lists of these attributes when you segment by Contact Attributes, be it Custom or Standard.
                //Note how the properties of the 'contacts' array above exactly match the left hand side properties of this map.
                
'contact_import_mapping' => array(
                    
'email address' => 'Email Address',
                    
'visitor_id' => 'Unique Visitor UUID',
                    
'first' => 'First Name',
                    
'last' => 'Last Name'
                
),

                
//the name of your import, recommend to keep fairly distinct and unique, so you can keep track what's changing your data and when
                
'contact_import_name' => 'customer import - contact form submission - 2015-01-01 12:35:38',

                
//leave as an empty array to skip notifications. recommend to leave on while testing
                
'notification_recipients' => array(
                    
'youraddress@yourdomain.com'
                
),

                
//list ids to add these contacts to. leave blank like remove_from_lists to do nothing
                //get list ids from the api EmailList controller, or via interface by hovering the link to edit a list.
                
'add_to_lists' => array(
                    
123456,
                    
123457
                
),

                
//list ids to remove contacts from. leave blank to to do nothing.
                
'remove_from_lists' => array(
                )
            )
        )
    )
);

//We are sending this as POST submission.
curl_setopt($chCURLOPT_POSTtrue);

$strResponse curl_exec($ch);

//recommend to check for curl response code < 400, so that you know if the server encountered an error or if you may safely proceed.
if ($strResponse) {
    
//decode response as an array
    
$arrResponse json_decode($strResponsetrue);

    
//do something with the response...

} else {
    print 
"invalid json from server\n";
    
print_r($strResponse);
}