skip to Main Content

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


  1. I tried and getting the following SUCCESS response

    {"data":[{"code":"SUCCESS","details":{"Modified_Time":"2022-07-27T17:28:36+05:30","Modified_By":{"name":"Sourav Sinha","id":"1153488000000068001"},"Created_Time":"2022-07-27T17:28:36+05:30","id":"1153488000046560019","Created_By":{"name":"Sourav Sinha","id":"1153488000000068001"}},"message":"record added","status":"success"}]}
    [email protected]
    request quote
    
    Login or Signup to reply.
  2. <?php
    $first_name = 'first-name';
    $last_name = 'last-name';
    $email = '[email protected]';
    $phone = '9876543210';
    $message = 'your-message';
    $budget = '1000';
    $checkbox = '1';
    
              $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=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);
    
    Login or Signup to reply.
  3. This is the code used in functions.php file

    add_action('wpcf7_mail_sent','brainium_cf7_api_sender');
    function brainium_cf7_api_sender($contact_form){
        $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-194'][0];
    
                $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); 
            }
        } 
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search