Report GET_MERCHANT_LISTINGS_ALL_DATA in Json
elvispdosreis opened this issue · comments
Elvis P dos Reis commented
I am having difficulty bringing a report in json, is it possible to bring the data converted into json?
$reportType = [
'contentType' => 'application/json',
'name' => 'GET_MERCHANT_LISTINGS_ALL_DATA'
];
$reportResultDocument = $this->client_report->getReportDocument($id);
$docToDownload = new Document($reportResultDocument, $reportType);
$contents = $docToDownload->download();
$data = $docToDownload->getData();
Daniel Fernandes Correa commented
Hello Elvis,
`function parse_data($api_response) {
$lines_2 = explode("\n", $api_response);
$header_2 = explode("\t", $lines_2[0]);
$result_hash = array();
for ($i = 1; $i < count($lines_2); $i++) {
$values_2 = explode("\t", $lines_2[$i]);
$listing_id = $values_2[array_search("listing-id", $header_2)];
$data_hash_2 = array();
foreach ($header_2 as $index => $key) {
$data_hash_2[$key] = $values_2[$index];
}
$result_hash[$listing_id] = $data_hash_2;
}
return $result_hash;
}
`
api_response is a response from a get_request to url of relatory
Jesse Evers commented
Hi @elvispdosreis -- Amazon doesn't have any mechanism for downloading non-JSON reports as JSON, nor does this library, but since the GET_MERCHANT_LISTINGS_ALL_DATA
is tabular, you should be able to do something like this:
$json = [];
foreach ($data as $row) {
$rowObj = [];
foreach ($row as $header => $value) {
$rowObj[$header] = $value;
}
$json[] = $rowObj;
}
json_encode($json);
(I haven't tested this, so there may be issues with it, but it should point you in the right direction)