Adding client details to CSV

Hi Guys,

The code which I have pasted below is what I am trying to use to pull in my latest client details and then export them into a csv file, however, this is not working and I was wandering if someone could hep me understand why and how I may go about fixing it?

I am pulling in all my details which I want but cannot seem to push anything into the array for the csv??

require_once dirname(__FILE__).'/cm/csrest_general.php';
require_once dirname(__FILE__).'/cm/csrest_clients.php';
require_once dirname(__FILE__).'/cm/csrest_campaigns.php';

$api_key = 'MY API KEY';
$wrap = new CS_REST_General($api_key);
$result = $wrap->get_clients();

if ($result->was_successful()) {

                $list = array (
                array('test1', 'test2'));
    foreach ($result->response as $client) {
        $client_wrapper = new CS_REST_Clients($client->ClientID, $api_key);
        $client_details_result = $client_wrapper->get();
        $campaigns_result = $client_wrapper->get_campaigns();

        if ($client_details_result->was_successful()) {
            /* This is where the client details will be */
            $client_details = $client_details_result->response;
            array_push($list, 'please', 'work');
            echo ('<pre>');
            /*print out the company name*/
            echo "Company Name = " . $client_details->BasicDetails->CompanyName . "<br/>";
            /*print out the company markup*/
            echo "Markup On Delivery = " . $client_details->BillingDetails->MarkupOnDelivery . "<br/>";
            $count = 0;
            if ($campaigns_result->was_successful()) {
                /*print out the latest campaign name of the current campaign*/
                foreach ($campaigns_result->response as $campaign_ob) {
                echo 'Latest Campaign Name = ' . $campaign_ob->Name . '<br/>';
                echo 'Latest Subject = ' . $campaign_ob->Subject . '<br/>';
                echo 'Total Recipients = ' . $campaign_ob->TotalRecipients . '<br/>';
                echo 'Sent Date = ' . $campaign_ob->SentDate . '<br/>';
                if($count > 0) break;
                }/*end loop*/
            }/*end campaigns if statement*/
            echo ('</pre>');
        } else {
            echo 'Failed with code '.$client_details_result->http_status_code."\n<br /><pre>";
} else {
    echo 'Failed with code '.$result->http_status_code."\n<br /><pre>";
    echo ('</pre>');

$fp = fopen('test4.csv', 'w');

foreach ($list as $fields) {
    fputcsv($fp, $fields);


Greg Strutton Greg Strutton, 5 years ago

Hey dannetherton!

I'm not completely clued up with PHP, but what is the error that you are getting when running the code above?  I'm not sure what the error is you are seeing exactly.

200,000 companies around the world can't be wrong.

From Australia to Zimbabwe, and everywhere in between, companies count on 
Campaign Monitor for email campaigns that drive real business results.

Get started for free