<?php
// Generated by curl-to-PHP: http://incarnate.github.io/curl-to-php/
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://noel.damcentral.cloud/api/rpc');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\n    \"jsonrpc\": \"2.0\",\n    \"id\": \"GET_ASSETS_BY_QUERY\",\n    \"method\": \"getAssetsByQuery\",\n    \"params\": [\n        {\n            \"query\": [\n                {\n                    \"operator\": \"and\",\n                    \"folder\": {\n                        \"folderId\": 66240,\n                        \"recursive\": true\n                    }\n                }\n            ]\n        },\n        {\n            \"sort\": {\n                \"field\": \"assetId\",\n                \"order\": \"asc\"\n            },\n            \"page\": {\n                \"startIndex\": 0,\n                \"size\": 3\n            },\n            \"data\": [\n                \"asset.id\",\n                \"asset.views\",\n                \"asset.attributes\"\n            ]\n        }\n    ]\n}");

$headers = array();
$headers[] = 'Content-Type: application/json';
$headers[] = 'Authorization: apiToken MToCsWyrtNu7w2UlXZQqQDiU8xYqOw';
$headers[] = 'Cookie: AWSALB=awA84P5ESCybOqE51tyLddDfRqX2KdupyItJtvU7Io+zW+hw5rVG2DrLZJWqVpuZvUfI+kpkGDUDwl4UigS3krzjhhXO1+bXWt+PAXzgdk5wWn14ojcqKMY70rLc; AWSALBCORS=awA84P5ESCybOqE51tyLddDfRqX2KdupyItJtvU7Io+zW+hw5rVG2DrLZJWqVpuZvUfI+kpkGDUDwl4UigS3krzjhhXO1+bXWt+PAXzgdk5wWn14ojcqKMY70rLc';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}

curl_close($ch);
print_r($result);
$res = $result.replace('{"id":"GET_ASSETS_BY_QUERY","jsonrpc":"2.0","result":{"','');
print $result;
$decoded_json = json_decode($result,true);  
//print_r($decoded_json);  
echo "<br>A<br>";
$results = $decoded_json["result"]["results"];
echo "<br>B<br>";
foreach($results as $data)  {
//print $decoded_json["result"]["results"][0]["id"]."<br />";
//print_r($decoded_json["result"]["results"]);
   echo $data['id'];
   foreach ($data['views'] as $views => $value){
      print_r ($views->$name -> $value);
   }
print_r ($data['attributes']);
}
echo "<br>C<br>";
    if (count($results)) {
       
   
        echo "<table>";

        // Cycle through the array
        foreach ($results->$result as $idx => $value) {

            // Output a row
            echo "<tr>";
            echo "<td>$result->$value</td>";
           
            echo "</tr>";
        }

     
        echo "</table>"; 
    }
?>