No records found in request when running in PHP Custom Script

I am unable to execute a post request form Custom PHP server side script on DF version 2.2.
Also note that same script works fine on DF version 2.1.1
Here is the post contents,

{ "resource": [{ "devid": "20160022", "event": "0000", "time": "2016-05-03 18:21:14", "result": "PASS", "etype": "EVENT_IGNITION_KEYED", "bac": "255", "image": "", "lat": "5.000000", "lon": "5.000000", "speed": "0.00" }] }


{"status_code":400,"content":{"error":{"context":null,"message":"{"error":{"context":null,"message":"No record(s) detected in request.","code":400}}","code":400}},"content_type":null,"format":201}

The script collects the HTTP post request and does a post using platform.api functions as shown below.
$api = $platform['api']; $post = $api->post; $in_content = $event['request']['content'];

//Store log data $query = ''; $result = $post($query,$in_content);

$event['response']['content_type'] = "application/json"; $event['response']['content'] = $result;

Ran this request from fiddler and got error of No records found in request.

Please could anyone help.

Asking an engineer about this. I was able to duplicate the issue.

this line
$in_content = $event['request']['content'];

needs to be changed to
$in_content = $event['request']['payload'];

Both content and payload used to work, but now you must use payload for the response data object. Content is just a raw string of whatever comes in the request.

Thank you Drew, It worked. I also had to change the way the post is called from,
$result = $post($query,$in_content);
$result = $platform[‘api’]->post->__invoke($query,$in_content);

Then it worked.

Thanks for responding.

1 Like