I am inserting a record via Campaign Monitor API; as I am passing below array; why I am getting error:

Array(
[EmailAddress] => tljljljl@example.com
[Name] => Trial test
[CustomFields] => Array
(
[0] => Array
(
[Key] => First name
[Value] => trial
)
[1] => Array
(
[Key] => Last name
[Value] => test
)
)
[Resubscribe] => 1
)

Hi!

Which is the error? The thread title is truncated. And, can you share your code and explain where the issue happens?

I suppose you're using their library, is this correct?

I am using all the creditials correctly. I am inserting above array which will convert into JSON by API. It is inserting correctly but throwing **PHP Catchable fatal error: Object of class CS_REST_Wrapper_Result could not be converted to string in **

$cm_msg = $subscriber_class->cm_active_trial_user($customer, $cm_custom_fields);
    echo ' | Active C.Monitor cm_active_trial_user MSG : '.$cm_msg;


    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']."";

                    $cm_name = $cm_parent_student['fname']." ".$cm_parent_student['lname'];
                    $cm_name = "".$cm_name."";


            }

            $msg = $this->cm_subscriber('new',$cm_email,$cm_name,$cm_custom_fields);
        }else{
            $msg = 'No Record Found!';
        }
        return $msg;
    }



**$cm_custom_fields holds above array.**




function cm_subscriber($action,$email,$name,$array_subscriber){
        if(count($array_subscriber)>0){
            foreach($array_subscriber as $key=>$object){
                if($object['Value']==''){
                    unset($array_subscriber[$key]);
                }
            }   
            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) {
        print_r($subscriber);
        return $this->post_request($this->_subscribers_base_route.'.json', $subscriber);
    }    

What line is the error on? One of the functions is returning an object, yet you are trying to use it as a string.

Line no 1. where I am getting the error. Thanks for give hint.

$cm_msg is only a string in case of an error. When successful you get an object, so in that case you cannot use . $cm_msg

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.