No records found in request when running in PHP Custom Script


#1

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" }] }

Response:

{"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 = 'http://127.0.0.1/api/v2/mysql/_table/log?api_key=ba83d0d41ab0201f6674ed22ba307c282a0d78aef2fcadb6274d830e1172961c'; $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.


#2

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


#3

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.


#4

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

Then it worked.

Thanks for responding.