Question

I am working with the campaign monitor api and tring to access the summary of a campaign. So far i have the following working:

require_once '../../csrest_campaigns.php';

$auth = array('api_key' => 'xxxxxxxxxxxxxxxxxxxxxxxxx');
$wrap = new CS_REST_Campaigns('xxxxxxxxxxxxxxxxxxxxxx', $auth);

$result = $wrap->get_summary();

echo "Result of GET /api/v3/campaigns/{id}/summary\n<br />";
if($result->was_successful()) {

    var_dump($result->response);

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

i would like to extract certain data from the above so i added the following (replacing the var_dump):

foreach($result->response as $entry) { 
        echo $entry->Recipients;
        echo $entry->TotalOpened.'<br/>';
        echo $entry->Clicks.'<br/>';
        echo $entry->Unsubscribed.'<br/>';
        echo $entry->Bounced.'<br/>';
        echo $entry->UniqueOpened.'<br/>';
        echo $entry->SpamComplaints.'<br/>';
        echo $entry->WebVersionURL.'<br/>';
        echo $entry->WebVersionTextURL.'<br/>';
        echo $entry->WorldviewURL.'<br/>';
        echo $entry->Forwards.'<br/>';
        echo $entry->Likes.'<br/>';
        echo $entry->Mentions.'<br/>';
    }

This shows no data at all? Can anyone see where i am going wrong?

var_dump:

stdClass Object
(
    [Recipients] => 5
    [TotalOpened] => 28
    [Clicks] => 2
    [Unsubscribed] => 0
    [Bounced] => 0
    [UniqueOpened] => 4
    [SpamComplaints] => 0
    [WebVersionURL] => http://xxxxxxxxxxxxxxxx
    [WebVersionTextURL] => http://xxxxxxxxxxxxxxxxxxx
    [WorldviewURL] => http://xxxxxxxxxxxxxxxxxxx
    [Forwards] => 0
    [Likes] => 0
    [Mentions] => 0
)   

No correct solution

OTHER TIPS

See stdClass object and foreach loops - campaign monitor api

I think you might need:

$campaigns = $result->response->Results;

then:

foreach($campaigns as $s) {
    echo $s->Recipients . "\t" . $s->TotalOpened . "\n"; // etc.
}

Most Campaign Monitor methods return objects have a response->Results structure to get at the individual items in a set (campaigns, lists, subscribers etc.). As you probably saw, the documentation doesn't explain this last step - it just var_dumps the objects, although you can work out what to do by examining them. Make sure you check whether there are any wrappers before you examine the object directly, but I've found you mostly end up using response->Results to get at the arrays of data. Pete

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top