PHP API 500 error messages when trying to create segments

I'm getting 500 error messages, and a suggestion the problem is at the CM end, when trying to create segments using the PHP API. However, when I tested this previously it worked. I've changed the API keys so think they might be in the wrong place, even though I think I'm following the instructions. Am I missing something obvious? Or not so obvious? The code I'm trying is as follows:

require_once '../csrest_segments.php';

require_once 'cm_constants.php'; // this includes my keys

//$wrap = new CS_REST_Segments(NULL, 'Your API Key');
$wrap = new CS_REST_Segments(NULL, API_CLIENT_KEY); // I tried the account key but that also failed

[..... I build segments as an array of arrays here and have checked they look right.]

// Loop through our segments
foreach ($segments as $segment) {
    // $result = $wrap->create('Segments List ID', array(
    $result = $wrap->create(API_LIST, $segment);

    echo "<p>Result of POST /api/v3/segments/" . API_BOOKSELLERS_LIST . "\n<br />";
    if($result->was_successful()) {
        echo "Created with ID\n<br />".$result->response;
    } else {
        echo 'Failed with code '.$result->http_status_code."\n<br /><pre>";
        echo '</pre>';

Many thanks for any help you can provide.


Phil Phil, 4 years ago

Hi Jemima,

Unfortunately without including all the code it's difficult to know if the problem is the bit in this snipped portion:

[..... I build segments as an array of arrays here and have checked they look right.]

There's a strong possibility the problem is in the segments array itself. Any chance you can share that with us too? If there's sensitive data that you don't want to go public, drop us an email

See why 200,000 companies worldwide love Campaign Monitor.

From Australia to Zimbabwe, and everywhere in between, companies count on Campaign Monitor for email campaigns that boost the bottom line.

Get started for free