I'm building a loop in PHP to post curl requests to a server. I'm sending JSON and hoping to return a report which outputs parameters included in the JSON. My code is as follows:
$json = '{"report":{"special_pixel_reporting":false,"report_type":"network_analytics","timezone":"EST5EDT","start_date":"2016-03-01 00:00:00","end_date":"2016-04-01 00:00:00","filters":[{"seller_member_id":["273"]}],"columns":["imps","cost"],"row_per":[],"pivot_report":false,"fixed_columns":[],"show_usd_currency":false,"orders":["imps","cost"],"name":"Network Analytics Report - 04\/4\/2016","ui_columns":["imps","cost"],"filter_objects":[]}}';
foreach ($results as $k => $v) {
$ch = curl_init('https://api.appnexus.com/report');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization:'.$v['token'],
'Content-Type: application/json'));
$output = curl_exec($ch);
var_dump($output);
};
where $results is a 2D array containing the authentication token (which I'm using as an iterator). I'm expecting to return an output for each token but can't get a response from the server.
Essentially I'm trying to replicate this curl request in PHP.
curl -X POST -d '{"report":{"special_pixel_reporting":false,"report_type":"network_analytics","timezone":"EST5EDT","start_date":"2016-03-01 00:00:00","end_date":"2016-04-01 00:00:00","filters":[{"seller_member_id":["273"]}],"columns":["imps","cost"],"row_per":[],"pivot_report":false,"fixed_columns":[],"show_usd_currency":false,"orders":["imps","cost"],"name":"Network Analytics Report - 04\/4\/2016","ui_columns":["imps","cost"],"filter_objects":[]}}' --header "Authorization:[AUTH HERE]" https://api.appnexus.com/report
Does anyone have any advice as to why my PHP code won't return any output?
CURLOPT_VERBOSEoption for debugging.If you do not have PHP error that should help you to get more info.