API Illegal string offset 'content'

jra2f

New Member
Hello,

I'm using the API for a couple of years to generate campaigns.
The code is in a php file called by a bigger script that deals with a couple of steps before to generate the content.
Recently I modified the code to generate 2 identical campaigns for 2 lists, with the lists IDs in an array.
(I only took the working code and wrapped it in code to use the array)
It was working the last time I used it a couple of months ago, (I also tested it a lot) but today there's an error showing up and I don't know what is the problem as it is in a part of the code I didn't change.

Warning: Illegal string offset 'content' in
/home/XXX/XXX/XXX/public_html/emailing/remote/scripts/campaigns.php
on line 73

Could you help me to find where is the problem?
Thank you.

PHP:
<?php
/*
 * This file contains examples for using the MailWizzApi PHP-SDK.
 *
 * @author Serban George Cristian <cristian.serban@mailwizz.com>
 * @link http://www.mailwizz.com/
 * @copyright 2013-2017 http://www.mailwizz.com/
 */

// require the setup which has registered the autoloader
require_once dirname(__FILE__) . '/setup.php';

// add the Mailing Lists UIDs below separated by a comma.
$newsletter_lists_uids = array("ny4858l9kXXXX","lx340f30XXXX");
// RESPONSE CONTAINER
echo '<div id="emailing_result">';
foreach ($newsletter_lists_uids as $newsletter_lists_uids){
// CREATE THE ENDPOINT
$endpoint = new MailWizzApi_Endpoint_Campaigns();
$options  = array('http' => array('user_agent' => 'Mozilla/5.0 (iPad; U; CPU iPad OS 5_0_1 like Mac OS X; en-us)   AppleWebKit/535.1+ (KHTML like Gecko) Version/7.2.0.0 Safari/6533.18.5\r\n" // i.e. An iPad'));
$context  = stream_context_create($options);
/*===================================================================================*/

// CREATE CAMPAIGN
$response = $endpoint->create(array(
    'name'          => 'New Painting: '.$ptg_title, // required
    'type'          => 'regular', // optional: regular or autoresponder
    'from_name'     => 'XXXXXXl - Newsletter', // required
    'from_email'    => 'newsletter@XXXXXX.com', // required
    'subject'       => 'New Painting: ' .$ptg_title , // required
    'reply_to'      => 'reply@XXXXXXXXXX.com', // required
    'send_at'       => date('Y-m-d H:i:s', strtotime('+20 min')), // required, this will use the timezone which customer selected
    'list_uid'      => $newsletter_lists_uids, // required ny4858l9kXXXX lx340f306XXXX
    'segment_uid'   => '',// optional, only to narrow down

    // optional block, defaults are shown
    'options' => array(
        'url_tracking'      => 'yes', // yes | no
        'json_feed'         => 'no', // yes | no
        'xml_feed'          => 'no', // yes | no
        'plain_text_email'  => 'yes',// yes | no
        'email_stats'       => null, // a valid email address where we should send the stats after campaign done

        // - if autoresponder uncomment bellow:
        //'autoresponder_event'            => 'AFTER-SUBSCRIBE', // AFTER-SUBSCRIBE or AFTER-CAMPAIGN-OPEN
        //'autoresponder_time_unit'        => 'hour', // minute, hour, day, week, month, year
        //'autoresponder_time_value'       => 1, // 1 hour after event
        //'autoresponder_open_campaign_id' => 1, // INT id of campaign, only if event is AFTER-CAMPAIGN-OPEN,

        // - if this campaign is advanced recurring, you can set a cron job style frequency.
        // - please note that this applies only for regular campaigns.
        //'cronjob'         => '0 0 * * *', // once a day
        //'cronjob_enabled' => 1, // 1 or 0
    ),

    // required block, archive or template_uid or content => required.
    'template' => array(
        //'archive'         => file_get_contents(dirname(__FILE__) . '/template-example.zip'),
        //'template_uid'    => 'TEMPLATE-UNIQUE-ID',
        'content'           => file_get_contents("https://XXXXXX.com/newsletter/mails/newsletter_template.php?painting=$ptg_ID", false, $context),
        'inline_css'        => 'yes', // yes | no
        'plain_text'        => $ptg_title.', '.$ptg_medium.', '.$ptg_h_cm.' x '.$ptg_w_cm.' cm - '.$ptg_h_in.' x '.$ptg_w_in.' in. - '.$ptg_year.' '.$ptg_link.'/'.$ptg_year.'/'.$ptg_filename , // leave empty to auto generate
        'auto_plain_text'   => 'no', // yes | no
    ),
));



$emailing_response=$response->body->toArray();
$mailing_status=$emailing_response['status'];
$mailing_content=$response->body['content'];
$mailing_uid=$response->body['campaign_uid'];
$mailing_error=$response->body['error']['content'];
// DISPLAY RESPONSE
if($mailing_status=="success"){
  echo '<div class="info_message">Newsletter Generated<br>ID:'.$mailing_uid.'</div>';
}
else{
  echo '<div class="error_message">Error with the Newsletter Generation<br>'.$mailing_error.'</div>';
}
}
echo '</div>';
?>
 
Warning: Illegal string offset 'content' in
/home/XXX/XXX/XXX/public_html/emailing/remote/scripts/campaigns.php
on line 73
This error is caused because $response array doesn't contain ['content'] , on error returned array is:
Code:
(
    [_data:MailWizzApi_Params:private] => Array
        (
            [status] => error
            [error] => Please provide a template for your campaign.
        )

    [_readOnly:MailWizzApi_Params:private] =>
)
[\CODE]

// to extract error message you can use
$mailing_error=$response->body['error'];
 
Back
Top