Click here to Skip to main content
15,886,078 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
It is working fine in localhost but when i updating it on live site it giving following error-

{"data":[{"code":"INVALID_DATA","details":{"maximum_length":20,"api_name":"Subscribed_Newsletter"},"message":"invalid data","status":"error"}]}

You can find the reference code below-

What I have tried:

add_action('wpcf7_mail_sent','brainium_cf7_api_sender');
function brainium_cf7_api_sender($contact_form){
    $title = $contact_form->title;

    if( $title === 'Test') {
	
       $submission = WPCF7_Submission::get_instance();

        if( $submission ){
            $posted_data = $submission->get_posted_data();

            $first_name = $posted_data['first-name'];
            $last_name = $posted_data['last-name'];
            $email = $posted_data['your-email'];
            $phone = $posted_data['Phone-no'];
            $message = $posted_data['your-message'];
            $budget = $posted_data['budget'];
            $checkbox = $posted_data['checkbox-37'][0];	
			
				  

            $auth = 'fa738eaef1becee890f8935f65169e99';
            $refreshToken = "1000.3c0d5bb96a00e9438d132d94a316a72b.2d5261b7e33c42614c08f1bd4e9a0f1a";
            //get the last date and time of refresh token generation
            
            //get the access token
            $url = "https://accounts.zoho.com/oauth/v2/token";
            $query = "refresh_token=1000.3c0d5bb96a00e9438d132d94a316a72b.2d5261b7e33c42614c08f1bd4e9a0f1a&client_id=1000.PJ66M19LBVNAYS7XXP3XP9RU5MXJAH&client_secret=6995e79c891ec5444440b9d07bc2a00c535c074cf3&grant_type=refresh_token";
            
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_TIMEOUT, 30);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
            $result = curl_exec($ch);
            curl_close($ch);
            //get the token from the JSON in result
            $accessToken =  json_decode($result, true);
            //echo ($accessToken['access_token']); 
            //die();        
            
            $data = array("First_Name"=>$first_name, "Last_Name"=>$last_name, "Email"=>$email, "Phone"=>$phone, "Description"=>($message), "Budget"  => $budget, 'Subscribed_Newsletter' => $checkbox, "Lead_Date"=>$zoho_date , '$gclid'=>$zc_gad);
            //$data = json_encode($data);
            
            $encodedData = array();
            $encodedData['data'][0] = $data;
            
            //var_dump($data);
            //echo(json_encode($encodedData));
            //die();
            //che


            $url ="https://www.zohoapis.com/crm/v2/Leads";
            $headers = array(
                                'Authorization: Zoho-oauthtoken '.$accessToken['access_token'],
                                'Content-Type:application/json'
                            );

            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_TIMEOUT, 30);
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($encodedData));
            $result = curl_exec($ch);
            curl_close($ch);
            //echo $result;
            // End zoho CRM
            $success = true;
            $msg = 'Done';
            
            $leadSaving = print_r($result, true);
            $leadSaving = $leadSaving . "\r\n" . $email;
            $leadSaving = $leadSaving . "\r\n" . "request quote";
            file_put_contents("lead-zoho-entry-status.txt", $leadSaving, FILE_APPEND);
            file_put_contents("lead-zoho-entry-status.txt", "\r\n\r\n", FILE_APPEND); 
        }
    } 
}
Posted
Updated 15-Nov-22 18:49pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900