PHP Post to MSSQL with ServiceHandler

In lieu of existing documentation for the PHP classes, I am hoping someone could shed a little more light on this.

PHP - post process. I am trying to post a record to MS SQL DB. When I do this through the api_docs it works fine. But when I fire this from another post process, I get the error:

**Required field 'id_session' can not be NULL.**

I am certain the value is in my payload. I am calling the post using the service handler like this:

$auditPost= DreamFactory\Core\Utility\ServiceHandler::handleRequest('POST','ap-db','_table/Audit',[],$jsonPayload,'JSON','Content-Type: application/json');

What I am unsure of are the last two arguments, (the format, and the header) as I could not find any examples. I looked at the api_docs post in the chrome debugger, and this was my best guess. The $jsonPayload is well-formed json that works fine when submitted vi api_docs so I know the id_session value is there {
“resource”: [{
“id_session”: “10A4A35E-0D2B-4A27-A178-4A1F82E72FC2”,
“form_name”: “Toolbox Inspection”,
“start_time”: “2016-02-22 20:49:01”,
“end_time”: “2016-02-23 01:49:49”,
“GenDate”: “2016-02-23 01:49:49”,
“InstitutionName”: “Eddie’s Garage”,
“GenBuilding”: “Back Shack”,
“GenRoom”: “6”,
“GenAuditor”: “Joey the Tool”,
“Question_id”: null,
“Violation_Flag”: null,
“ShowRisk”: false,
“Violation_CD”: “CHEM_MSDS.001”,
“Violation_Qty”: null,
“Violation_Note”: null
}]
}
}`

Any ideas would be great. TIA

Well after looking at the ServiceHandler function I missed that headers needed to be array, so that is fixed (I think). Headers below are the same as passing from api_docs which works.
$headers = array( 'Accept: application/json', 'Content-Type: application/json' );
However problem still exists getting the same error:

**Required field 'id_session' can not be NULL.**

Which leaves me to the format “JSON” string in the arguments. Is that correct? According the code in dr github ServiceHandler if the $payload is json and the $format is undefined it throws an undeclared format exception.

Anyone have any ideas?

For clarity, my call now looks like this:

$headers = array( 'Accept: application/json', 'Content-Type: application/json' ); $auditPost= DreamFactory\Core\Utility\ServiceHandler::handleRequest('POST','ap-db','_table/Audit',[],$jsonPayload,'JSON',$headers);

The only element from the api_docs not present is the $query filters=* which I do not want. I only need the id back which IIRC is the default. BTW I can also add records via the Data tab.

Try this…(just now getting around to documenting use of platform resource, see wiki)

$payload = ['resource' => [['name' => 'test', 'complete' => false]]];
$result = $platform['api']->post->__invoke('mysql/_table/todo', $payload);
echo print_r($result);

Worked like a charm thanks!

Any example using the platform api post to create a file in a new sub-folder on S3 (or any storage service for that matter)? I’m trying to upload an image to s3 in a new subfolder, and the api docs are not much help.