Community Discussion

Ask a Question
Back to All

Issues connecting to API for new environment


We've worked with the backstage API a bit before, but for a new project, we had a sandbox environment set up for testing purposes.

We are having difficulty getting our API call to work, and the errors that are returning are not at all helpful. I really wish the API responded with more information to help troubleshoot.

If we use the numerical account ID provide by our account manager we get the following error:

{http_status: 403, message: "Requested action is forbiddenโ€}

If we use the alpha string ID ie. "Your Account Sandbox Name" with letters and spaces we get the following error:

"Bad Request"

Our payload follows the JSON structure outlined here:

That is the method we are calling from our application, which submits the JSON object via an AJAX post.

Here is a section of our code to show what we are doing:

$url = '';
$data = array('client_id' => $taboolaCID, 'client_secret' => $taboolaSecret, 'grant_type' => 'client_credentials');
$options = array(
        'http' => array(
        'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
        'method'  => 'POST',
        'content' => http_build_query($data),

$context  = stream_context_create($options);
$result = file_get_contents($url, false, $context);

$taboolaAccessToken = json_decode($result)->{'access_token'};

$ch = curl_init(''.$taboolaAccount.'/campaigns/'.$campaign_id.'/items/mass' );

$payload = json_encode($collection, JSON_UNESCAPED_SLASHES);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, โ€˜Our Application Name');
curl_setopt($ch, CURLOPT_POST, true);   
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload );
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'cache-control: no-cache',
    'Authorization: Bearer ' . $taboolaAccessToken

$data = curl_exec($ch);
$info = curl_getinfo($ch);

Any assistance would be greatly appreciated.