PHP Client Looping

Hi All,

I have been looking through the PHP wrapper and for what I need to do it seems too complicated (For my limited PHP knowledge)

I would like to loop through all of my clients and echo out their details (Name etc..)

I am sure I can do this using a simple GET request using either the .josn or .xml api requests.

Does anybody know a simple, small function too accomplish this to give me a head start.


- Dan

terryt terryt, 5 years ago

Hi Dan!

I was able to do this by moving our API wrapper into a folder called "cm" and then I wrote the following script:

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

$api_key = 'Your API key here';
$wrap = new CS_REST_General($api_key);
$result = $wrap->get_clients();

if ($result->was_successful()) {
    foreach ($result->response as $client) {
        $client_wrapper = new CS_REST_Clients($client->ClientID, $api_key);
        $client_details_result = $client_wrapper->get();

        if ($client_details_result->was_successful()) {
            /* This is where the client details will be */
            $client_details = $client_details_result->response;

            /* This is just a sample of dumping out all the information to the screen. */
        } 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>";


Please let me know if you need anything else!

Terry Tice
Campaign Monitor

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

Get started for free