Object of class CS_REST_Wrapper_Result could not be converted to string in CAMPAIGN MONITOR

277 views Asked by At

Below is json encoded data (but I am passing array) which I am sending. None of the field is not empty. It is creating in LIST but still throwing "Object of class CS_REST_Wrapper_Result could not be converted to string in"

I am not able to remove above error.

{"EmailAddress":"[email protected]","Name":"Amal Pushp","CustomFields":[{"Key":"First name","Value":"Amal"},{"Key":"Last name","Value":"Pushp"},{"Key":"Customer ID","Value":"27221"},{"Key":"Created","Value":"08-06-2015"},{"Key":"Landing Page","Value":"SIGN-UP"},{"Key":"Lead Capture page","Value":"SIGN-UP"},{"Key":"Subscription Type","Value":"MONTHLY"},{"Key":"Subscription Status","Value":"ACTIVE"},{"Key":"Postcode","Value":"110002"},{"Key":"Students","Value":5},{"Key":"Last Payment Date","Value":"29-05-2015"},{"Key":"Next Payment Date","Value":"29-06-2015"},{"Key":"Total Worksheets Completed","Value":"0"},{"Key":"01Student-Name","Value":"Amal_pushp_111"},{"Key":"01Student-Id","Value":"27222"},{"Key":"01Student-Year","Value":"0"},{"Key":"01Student-Worksheets-Completed","Value":"0"},{"Key":"01Student-Subjects","Value":"MATHS"},{"Key":"02Student-Name","Value":"Amal_pushp_112"},{"Key":"02Student-Id","Value":"27223"},{"Key":"02Student-Year","Value":"0"},{"Key":"02Student-Work sheets-Completed","Value":"0"},{"Key":"02Student-Subjects","Value":"ENGLISH"},{"Key":"03Student-Name","Value":"Amal_pushp_113"},{"Key":"03Student-Id","Value":"27224"},{"Key":"03Student-Year","Value":"0"},{"Key":"03Student-Worksheets-Completed","Value":"0"},{"Key":"03Student-Subjects","Value":"ALL SUBJECTS"},{"Key":"04Student-Name","Value":"Amal_pushp_114"},{"Key":"04Student-Id","Value":"27225"},{"Key":"04Student-Year","Value":"0"},{"Key":"04Student-Worksheets-Completed","Value":"0"},{"Key":"04Student-Subjects","Value":"ALL SUBJECTS"},{"Key":"05Student-Name","Value":"Amal_pushp_115"},{"Key":"05Student-Id","Value":"27226"},{"Key":"05Student-Year","Value":"0"},{"Key":"05Student-Worksheets-Completed","Value":"0"},{"Key":"05Student-Subjects","Value":"MATHS"}],"Resubscribe":true}

1

There are 1 answers

1
Abhi Kumar On
require_once 'csrest_subscribers.php';
$subscriber_class = new CS_REST_Subscribers($cm['list_id'], $cm['api_key']);
$cm_custom_fields = array( 
                array('Key' => 'First name','Value' => ''),                     
                array('Key' => 'Last name','Value' => ''),                      
                array('Key' => 'Customer ID','Value' => ''),                    
                array('Key' => 'Created','Value' => ''),                        
                array('Key' => 'Trial length','Value' => ''),                   
                array('Key' => 'Lead Capture page','Value' => ''),              
                array('Key' => 'Subscription Type','Value' => ''),              /* 6  */
                array('Key' => 'Subscription Status','Value' => ''),            
                array('Key' => 'Postcode','Value' => ''),                                           array('Key' => 'Students','Value' => ''),                       /* 9  */        
                array('Key' => 'Subscription start date','Value' => ''),        
                array('Key' => 'Next Payment Date','Value' => ''),              
                array('Key' => 'Total Worksheets Completed','Value' => ''),     
                array('Key' => '01Student-Name' ,'Value' => ''),                
                array('Key' => '01Student-Id'   ,'Value' => ''),                
                array('Key' => '01Student-Year' ,'Value' => ''),                
                array('Key' => '01Student-Worksheets-Completed' ,'Value' => ''),    
                array('Key' => '01Student-Subjects' ,'Value' => ''),            
                array('Key' => '02Student-Name' ,'Value' => ''),                
                array('Key' => '02Student-Id'   ,'Value' => ''),                
                array('Key' => '02Student-Year' ,'Value' => ''),                
                array('Key' => '02Student-Worksheets-Completed' ,'Value' => ''),
                array('Key' => '02Student-Subjects' ,'Value' => ''),            
                array('Key' => '03Student-Name' ,'Value' => ''),                
                array('Key' => '03Student-Id'   ,'Value' => ''),                
                array('Key' => '03Student-Year' ,'Value' => ''),                
                array('Key' => '03Student-Worksheets-Completed' ,'Value' => ''),
                array('Key' => '03Student-Subjects' ,'Value' => ''),            
                array('Key' => '04Student-Name' ,'Value' => ''),                
                array('Key' => '04Student-Id' ,'Value' => ''),                  
                array('Key' => '04Student-Year' ,'Value' => ''),                
                array('Key' => '04Student-Worksheets-Completed' ,'Value' => ''),
                array('Key' => '04Student-Subjects' ,'Value' => ''),            
                array('Key' => '05Student-Name' ,'Value' => ''),                
                array('Key' => '05Student-Id' ,'Value' => ''),                  
                array('Key' => '05Student-Year' ,'Value' => ''),                
                array('Key' => '05Student-Worksheets-Completed' ,'Value' => ''),
                array('Key' => '05Student-Subjects' ,'Value' => ''),            
                array('Key' => 'Sign up page','Value' => '')                    
            );

function cm_active_trial_user($parent_id,$cm_custom_fields){
    $stripe_customer  = Stripe_Customer::retrieve($parent_id);
    $subs_obj         = $stripe_customer['subscriptions']['data'][0];
    $total_students   = '0';
    $student_default_counter = 13;
    $plan_type = mysql_fetch_assoc(mysql_query("select (CASE WHEN plan_type ='2' THEN 'MONTHLY'
    WHEN plan_type = '3' THEN 'ANNUAL' ELSE 'NA' END) AS pt from ep_subscription_parent where parent_id='".$parent_id."'"));
    $qry = mysql_query("select id, fname, lname, post_code, email, subject, auto_assign_subject, user_type, date_modified, student_year from ep_wsusers where id='".$parent_id."' or parent_id='".$parent_id."' order by id") or mysql_error();
    $count = mysql_num_rows($qry) or mysql_error();
    $subject_array=array('1'=>'MATHS','2'=>'ENGLISH','3'=>'SCIENCE','9'=>'ALL SUBJECTS');
    if($count>=0){
        while($cm_parent_student=mysql_fetch_assoc($qry))
        {

            $landing_page ='SIGN-UP';
            if($cm_parent_student['user_type']=='parent'){
                $cm_email = $cm_parent_student['email'];
                $cu       = $this->objectToArray($this->get("'".$cm_email."'"));
                $cm_custom_fields[0]['Value']  = $cm_parent_student['fname'];
                $cm_custom_fields[1]['Value']  = $cm_parent_student['lname'];
                $cm_custom_fields[2]['Value']  = $cm_parent_student['id'];
                $cm_custom_fields[3]['Value']  = date('d-m-Y');
                $cm_custom_fields[4]['Value']  = $cu['response']['CustomFields'][4]['Value'];
                $cm_custom_fields[5]['Value']  = $cu['response']['CustomFields'][5]['Value'];
                $cm_custom_fields[6]['Value']  = $plan_type['pt'];
                $cm_custom_fields[8]['Value']  = $cm_parent_student['post_code'];                   
                $cm_custom_fields[10]['Value'] = $cu['response']['CustomFields'][10]['Value'];
                $cm_custom_fields[38]['Value'] = $cu['response']['CustomFields'][38]['Value'];      
                $cm_name    = ucfirst(trim($cm_custom_fields[0]['Value'].' '.$cm_custom_fields[1]['Value']));
                $parent = mysql_fetch_assoc(mysql_query("select sum(is_complete) as total_ws from  ep_wsassigned where parentId='".$parent_id."' and is_complete='1'"));
                $total_ws = ($parent['total_ws']!='')?$parent['total_ws']:'0';
                $cm_custom_fields[12]['Value']=$total_ws;
            }else{
                $total_students=$total_students+1;
                $subject_id     =($cm_parent_student['subject'])?$cm_parent_student['subject']:$cm_parent_student['auto_assign_subject'];
                $cm_student_name= ucfirst(trim($cm_parent_student['fname'].' '.$cm_parent_student['lname']));
                $cm_custom_fields[$student_default_counter++]['Value']= $cm_student_name;
                $cm_custom_fields[$student_default_counter++]['Value']= $cm_parent_student['id'];
                $student_year = ($cm_parent_student['student_year'])?$cm_parent_student['student_year']:'0';
                $cm_custom_fields[$student_default_counter++]['Value']= $student_year;
                $student = mysql_fetch_assoc(mysql_query("select sum(is_complete) as total_ws from  ep_wsassigned where studentId='".$cm_parent_student['id']."' and is_complete='1'"));
                $total_ws = ($student['total_ws']!='')?$student['total_ws']:'0';
                $cm_custom_fields[$student_default_counter++]['Value']= $total_ws;
                $cm_custom_fields[$student_default_counter++]['Value']= $subject_array[$subject_id];
            }
        }
        $cm_custom_fields[9]['Value'] = "$total_students";
        if($is_trial || $subs_obj['status']=='trialing'){
            $cm_custom_fields[7]['Value']   = 'TRIAL';
            $cm_custom_fields[11]['Value']  = date('d-m-Y',$subs_obj['trial_end']);
        }else if($subs_obj['status']=='active'){
            $cm_custom_fields[7]['Value']   = 'ACTIVE';
            $cm_custom_fields[11]['Value']  = date('d-m-Y',$subs_obj['current_period_end']);
        }
        $msg = $this->cm_subscriber('new',$cm_email,$cm_name,$cm_custom_fields);
    }else{
        $msg = 'No Record Found!';
    }
    return $msg;
}

function cm_subscriber($action,$email,$name,$array_subscriber){
    if(count($array_subscriber)>0){
        /*
        foreach($array_subscriber as $key=>$value){
            if($value){
                $key=$value;
            }else{
                unset($key,$value);
            }
        }       
        echo '<pre>';
        print_r($array_subscriber);
        foreach($array_subscriber as $key=>$object){
            if($object['Value']==''){
                unset($array_subscriber[$key]);
            }
        }
        print_r($array_subscriber);
        */  
        if($action=='new'){ /* Creates New Subscription */
            $new_subscriber = array(
                        'EmailAddress' => $email,
                        'Name' => $name,
                        'CustomFields' => $array_subscriber,
                        'Resubscribe' => true
                    );          
            $msg = $this->add($new_subscriber);
        }else if($action=='update'){
            $update_custom_fields = array( 'CustomFields' => $array_subscriber  );
            $msg = $this->update($email, $update_custom_fields);
        }       
    }else{
        $msg = 'error';
    }
    return $msg;
}

function add($subscriber) {
return $this->post_request($this->_subscribers_base_route.'.json', $subscriber);
}