Failed with code 400

Working on an a web application that is only accessible in a network, so to connect to the api I am using api keys.

Unfortunately, I am having trouble altering a sample from the php wrapper. In "samples/client/get_lists.php" (code version from a year or so ago) the CS_REST_CLIENTS has been tried with:

require_once '../../csrest_clients.php';
$wrap = new CS_REST_Clients(
    'CLIENT API KEY', //also tried CLIENT ID Number
    'MAIN ACCOUNT API KEY');

$result = $wrap->get_lists();

echo "Result of /api/v3/clients/{id}/lists\n<br />";
if($result->was_successful()) {
    echo "Got lists\n<br /><pre>";
    var_dump($result->response);
} else {
    echo 'Failed with code '.$result->http_status_code."\n<br /><pre>";
    var_dump($result->response);
}
echo '</pre>';

Are the problems from using an old wrapper, or am I confusing how the api authentication call is made? I was successful in using the sample to upload templates, but fr  some reason this one has not been working.

jamesd jamesd, 3 years ago

Hey there,

I'd recommend getting the latest version of the library, which is currently version 3.0.0.

Once you're using the latest version of the library, you can use the sample code to get a client's lists and just modify the $auth array to authenticate using an API key instead. Here's what your code should look like:

<?php

require_once '../../csrest_clients.php';

$auth = array('api_key' => 'Your API key');
$wrap = new CS_REST_Clients(
    'ClientID to get Lists for', 
    $auth);

$result = $wrap->get_lists();

echo "Result of /api/v3/clients/{id}/lists\n<br />";
if($result->was_successful()) {
    echo "Got lists\n<br /><pre>";
    var_dump($result->response);
} else {
    echo 'Failed with code '.$result->http_status_code."\n<br /><pre>";
    var_dump($result->response);
}
echo '</pre>';

The API documentation describes how to get the Client ID for the client you want lists for on the Getting Started page.

Hope that helps.

jtesolin jtesolin, 3 years ago

That solved it, thank you... now to update the rest of the application then back to this.  ;)

Thank you again :D

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