Message":"There was an error processing the request.","StackTrace":"","ExceptionType" - JQUERY

16.2k Views Asked by At

Here is my code, I keep on getting the same error response.

"{"Message":"There was an error processing the request.","StackTrace":"","ExceptionType":""}"

I can't figure it out. I'm using Eloqua APIs to get basic information such as total number of accounts, landing pages, users, images, etc. It's weird because I tried the API on POSTMAN application and it did work perfectly Screenshot of postman response to the API

PHP

$objetos = array("data/accounts", "data/contacts", "assets/emails", "assets/landingPages", "assets/images", "assets/forms", "system/users", "assets/microsites", "assets/customObjects");

for ($i = 0; $i < 9; $i++){

   $url = 'http://secure.p03.eloqua.com/API/REST/1.0/' . $objetos[$i] . '?count=1';

   $ch=curl_init();
   curl_setopt($ch,CURLOPT_URL,$url);

   $headers = array(
       'Content-type: application/json',
       'Authorization: BASIC "MY TOKEN"'
   );
   curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
   curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
   curl_setopt($ch, CURLOPT_CAINFO, getcwd() ."/EloquaApi_lvl1.cer");

   curl_setopt($ch, CURLOPT_POST, 0);
   curl_setopt($ch, CURLOPT_HTTPGET, 1);

   $data[$i] = curl_exec($ch);
   curl_close($ch);
}
echo json_encode($data);

 ?>

JS

function getObjetos(){

$.get("objetos.php", function (data) {
    console.log(data);
}, "json").done(function (data) {
    console.log(data);

// rest of my code 
}

Console console.log response (click for image)

2

There are 2 best solutions below

0
On

Try changing the url http://secure.p03.eloqua.com/API/REST/1.0/ to https

0
On

Use https://ssl.bing.com/webmaster/api.svc/json/SubmitUrlbatch?apikey=KEY

My full PHP code here

$data = array();
$data['siteUrl'] = 'https://example.com';
$data['urlList'][] = 'https://example.com/news/1';

$ch = curl_init('https://ssl.bing.com/webmaster/api.svc/json/SubmitUrlbatch?apikey=KEY');
curl_setopt_array($ch, array(
    CURLOPT_POST => TRUE,
    CURLOPT_RETURNTRANSFER => TRUE,
    CURLOPT_HTTPHEADER => array(
        'Content-Type: application/json',
        'charset=utf-8',
        'HTTP/1.1'
    ),
    CURLOPT_POSTFIELDS => json_encode($data)
));


$response = curl_exec($ch);