Trying to get PHP script working on a Get PostProcesing

I’m trying to get a PHP script to work when I call a table with a GET. I want to modify the JSON response to meet the format needed by my mobile app to display the information.

I have put this script on my service Dining as a table get post process ( dining._table.RightNow.get.post_process). The intent is to get it to return the JSON in a way that can be consumed in the mobile app tool.

Here is my php:
###########################
$data = event.response.content;

$info = json_decode($data);

ob_start();

echo ’
{
“metadata”: {
“version”: “1.0”
},
“content”: [
{
“elementType”: “portlet”,
“navbarTitle”: “Dining Budget”,
“height”: “medium”,
“content”: [
{
“elementType”: “carousel”,
“items”: [
{
“title”: “As of: ‘.$info->AsOf.’ ?>”,
“subtitle”: “Status: ‘.$info->budgetstatus.’”,
“subtitle”: “Spend: ‘.$info->Spent.’”,
“image”: {
“url”: “https://s3.amazonaws.com/gwmobile/’.$info->image.’.jpg
}
},
{
“title”: “Details”,
“subtitle”: “Average Daily Spend: ‘.$info->DailyAvg.’”,
“subtitle”: “Daily Budget Amount: ‘.$info->DailyBudget.’
}
]
}
]
}
]
}

;
$myStr = ob_get_contents();

return $myStr;

ob_end_clean();

###########################

I’m sure I’m just not thinking clearly. My hope is to use this for students in my course, which is a business students that won’t be strong at programming and system administration. DreamFactory would work great for them to connect a mobile app provided this PHP can work.

Thanks,
Mark

Hi @gwmalbert,

Can you confirm you have ‘can modify response’ checked? If that is not the problem can you please show the error.

Thank you,
Kevin

Yes - the can modify response flag is checked. The script is set to active as well.

I’m not getting an error. I just not getting this script to execute at all. Whenever I go to the endpoint through the API Docs or through Postman it returns the same JSON response I get if the script isn’t even there.

########## Output from API Docs #############

https://35.171.xxx.xx/api/v2/dining/_table/RightNow

Server response
Code Details
200
Response body

{
“resource”: [
{
“NetID”: “abateman”,
“budgetstatus”: “Over Budget”,
“AsOf”: “August 07 2018”,
“Spent”: 64.11,
“DailyAvg”: “21.37”,
“DailyBudget”: 18,
“image”: “red”
},
{
“NetID”: “malbert”,
“budgetstatus”: “Over Budget”,
“AsOf”: “August 07 2018”,
“Spent”: 127.03,
“DailyAvg”: “42.34”,
“DailyBudget”: 9.99,
“image”: “red”
},
{
“NetID”: “nbarbic”,
“budgetstatus”: “Over Budget”,
“AsOf”: “August 07 2018”,
“Spent”: 189.4,
“DailyAvg”: “63.13”,
“DailyBudget”: 15,
“image”: “red”
}
]
}

Response headers

cache-control: no-cache, private connection: Keep-Alive content-type: application/json date: Tue, 28 Aug 2018 18:40:37 GMT keep-alive: timeout=5, max=100 server: Apache transfer-encoding: chunked vary: Cookie x-frame-options: SAMEORIGIN x-powered-by: PHP/7.0.30

@gwmalbert I will bring this up with our engineers and get back to you as soon as possible.