Failed with code 200?

Strange error message - failed with code 200...I thought that code 200 meant call was  successful? I am looking at all campaigns in an account and getting the email client usage numbers.

Failed with code 200 
array(0) {
}
......
array(1) {
  [0]=>
  object(stdClass)#1 (4) {
    ["Client"]=>
    string(17) "Microsoft Outlook"
    ["Version"]=>
    string(12) "Outlook 2007"
    ["Percentage"]=>
    float(100)
    ["Subscribers"]=>
    int(1)
  }
}
Failed with code 200 
array(6) {
  [0]=>
  object(stdClass)#641 (4) {
    ["Client"]=>
    string(17) "Microsoft Outlook"
    ["Version"]=>
    string(27) "Outlook 2000, 2003, Express"
    ["Percentage"]=>
    float(40.243902439)
    ["Subscribers"]=>
    int(33)
  }
jamesd jamesd, 3 years ago

Hey,

Can you post your code which produces that result?

It looks like you're using createsend-php. You might like to try the sample included. I just tried that and it works as expected.

The API is definitely responding with a 200 OK response when you successfully retrieve email client usage for a campaign.

Hope that helps.

jtesolin jtesolin, 3 years ago

Hello,

Yes, sorry, this was the createsend-php. And my code is based of the samples. The code was working until Friday evening. For some reason it happened after we were generating reports on the 4th of 7 accounts for numbers. I removed our custom code in the for each, and just left the code from the sample we are using

error_reporting(E_ERROR | E_PARSE);
ini_set('default_charset', 'UTF-8');
header('content-type: text/html; charset: utf-8');
mb_language('uni');
mb_internal_encoding('UTF-8');
ini_set('max_execution_time', 600); //300 seconds = 5 minutes

session_start();
if ((isset($_SESSION['username'])) && (isset($_POST['Submit']))) { //check to see if user is logged in.
    $findYear = '2012';
    $cm_account='client ID here from form';// added client id's to select box
                require_once '../cm_api/csrest_clients.php';
                require_once '../cm_api/csrest_campaigns.php';
                $auth = array('api_key' => 'API KEY HERE');
                $wrap = new CS_REST_Clients(
                    $cm_account, 
                    $auth);

                $result = $wrap->get_campaigns();

                echo "Result of /api/v3/clients/{id}/lists\n<br />";
                if($result->was_successful()) {
                    foreach ($result->response as $row) {
                        $campaignid = $row->CampaignID;
                           $campaigndate = $row->SentDate;
                       $pos1 = stripos($campaigndate, $findYear);
                        $wrap = new CS_REST_Campaigns($campaignid, $auth); //first var is list id
                        $result = $wrap->get_email_client_usage();

                        
                        if( ($result->was_successful()) && ($pos1 !== false) ) {
                            foreach ($result->response as $row) {
                                $emailClient = $row->Client;
                                   $emailVersion = $row->Version;
                                   $emailPercentage = $row->Percentage;
                                   $emailSubscribers = $row->Subscribers;
                                   echo '<p>'.$emailClient.' ('.$emailVersion.')<br>Percentage:'.$emailPercentage.'<br>Number of Subscribers with this client (in campaign):'.$emailSubscribers.'</p>';

                            }
                        } else {
                                echo 'Failed with code '.$result->http_status_code."\n<br /><pre>";
                               var_dump($result->response);
                                    echo '</pre>';
                        }
                    }
                } else {
                    echo 'Failed with code '.$result->http_status_code."\n<br /><pre>";
                }    

} else {
    include('../includes/header.php');
    echo '<p>Use system to work with items.</p>;';
    include('../includes/footer.php');
}

Edit: Removed our api key's, and fixed comments

jamesd jamesd, 3 years ago

So the API is working as expected, and the sample code is working as expected.

It looks like there are problems with the logic of your own code – I'm not really in a position to debug that for you.

However based on your output, it looks like the following condition isn't behaving like you want it to:

if( ($result->was_successful()) && ($pos1 !== false) )

That appears to be causing the output you originally posted:

Failed with code 200 
array(0) {
}
...
jtesolin jtesolin, 3 years ago
jamesd :

It looks like there are problems with the logic of your own code – I'm not really in a position to debug that for you.

However based on your output, it looks like the following condition isn't behaving like you want it.

Ah ha, Thanks fort he point in the right direction. I thought it was something other than that if statement. I broke it apart and moved the year finding logic down. Seems to be working as desired now.

Join 200,000 companies around the world that use Campaign Monitor to run email marketing campaigns that deliver results for their business.

Get started for free
1-888-533-8098