I already added the code on my function.php file by applying zoho crm api but the data is not transferring on ZOHO crm.
I called the data through the access token provided by Zoho crm, then i create API v2 of web API and generate client id and client secret. I don’t know where i am making error
Please check and update me where i am making mistake
add_action('wpcf7_mail_sent','brainium_cf7_api_sender');
function brainium_cf7_api_sender(){
$title = $contact_form->title;
if( $title === 'Contact form 1') {
$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-993'];
$auth = 'xxxxxxxxxxxx';
$refreshToken = "xxxxxxxxxxxx";
//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=xxxxxxxxxxxx&client_id=xxxxxxxxxxxx&client_secret=xxxxxxxxxxxx&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 . "rn" . $email;
$leadSaving = $leadSaving . "rn" . "request quote";
file_put_contents("lead-zoho-entry-status.txt", $leadSaving, FILE_APPEND);
file_put_contents("lead-zoho-entry-status.txt", "rnrn", FILE_APPEND); }
}
}
3
Answers
I tried and getting the following SUCCESS response
This is the code used in functions.php file