Request JSON Payload without 'resource' element from Cloud Service

Hi,
I am using a cloud service for creating forms and I have the ability to redirect form submissions via HTTP to a REST interface using the JSON payload.

I want to use DreamFactory as an endpoint, but I am getting the following response:

{
  "error": {
  "code": 400,
  "context": null,
  "message": "No record(s) detected in request. Please make sure record(s) are wrapped in a 'resource' tag. Example: {"resource":[{"record":1},{"record":2}]}",
"status_code": 400
  }
}

I know this is because my payload does not have the { “resource”:[ … ] } wrapper, but I cannot control this as this is generated by the cloud service (FastField Forms) I am using.

The request payload (which I cannot modify) is as follows:

{
	"updatedAt": "2019-06-25T11:58:37.335+01:00",
	"formId": 352793,
	"alpha_1": "John",
	"alpha_2": "Allen",
	"formVersion": 2,
	"formName": "Test WebService Form"
}

What can I do to overcome this issue? Is pre-processing scripting a possible solution by wrapping my request payload within the “resource” element? If so, how do I go about doing this?

I have already tried to set the ‘always_wrap_resources’ => true lines to false in the config.php and .env configuration files, restarted the server, but this has not worked for me.

I am new to DreamFactory and REST configuration, but I do have coding experience so I can handle some scripting.

Any help would be much appreciated.

So, for anybody with a similar issue I managed to resolve it by adding a ‘pre_process’ php script that wraps the payload within '{resource:[…]}" and assigns the modified payload to request.content as follows:

<?php
$payload = $event['request']['payload'];
$rawpayload = '{"resource":['.json_encode($payload).']}';
$event['request']['content'] = json_decode($rawpayload, true);
?>

It probably needs a line added for the response.

The following is a screenshot of the DF interface:

I hope this saves someone else some time.

1 Like