Hi
This is my first time using JSON with PHP and i am having difficulty getting any results returned. I am using woopra API, I have check to make sure the HTTP headers are working and i am getting an ok message.
I was kinda hoping if anyone can see what is wrong with my curl and as to why it is not returning any results? maybe the json code is wrong?
I have CURL and JSON version 1.2.1 modules running on apache i am on PHP version 5.2.6
Any help or thoughts is much appreciated, been stuck on it for a good 2 days.
$json =<<<ENDJSON
{
"report":{
"group_by": [
{
"key": "visit.day",
"transforms": [
{ "function": "trim" },
{ "function": "substring", params: [ 0 , 4 ] }
]
}
],
"render": "'Rendered value for '+ group_by(0) "
"order_by": "Total Actions",
"columns": [
{
"name": "Total Actions",
"method": "sum",
"by": "amount",
"scope": "actions",
"render": " Math.round(cell('Total Actions')) "
}
]
}
};
ENDJSON;
$ch = curl_init('http://www.woopra.com/rest/report/');
curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
"report"=>$json,
"date_format"=>"yyyymmdd",
"start_day"=>"20130101",
"end_day"=>"20130131",
"segments"=>"[]",
"limit"=>"100",
"offset"=>"0"
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type:pplication/json",
'X-Access-Id: #################,
'X-Access-Secret: ##########################,
'X-Api-Version: 2.0'
));
//$result =
$res = curl_exec($ch);
echo $res;
echo $ch;
print_r($res);
//echo "Returned : $result";
echo "<pre>";
print_r(curl_getinfo($ch));
echo "</pre>";
echo "Error number: ".curl_errno( $ch )."<br>";
echo "Error er ".curl_error( $ch )."<br>";;
thought this might help:
curl_getinfo returns the following:-
Array
(
[url] => http://www.woopra.com/rest/report/
[content_type] => application/json
[http_code] => 500
[header_size] => 297
[request_size] => 365
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 2.235
[namelookup_time] => 0
[connect_time] => 0.125
[pretransfer_time] => 0.125
[size_upload] => 1320
[size_download] => 0
[speed_download] => 0
[speed_upload] => 590
[download_content_length] => 0
[upload_content_length] => 1320
[starttransfer_time] => 2.125
[redirect_time] => 0
)
and this print_r($res) returns the following:-
Resource id #2