Help for custom script ""No record(s) detected in request."

Hi dudes,

Here’s my custom script:

The first call to api (post a file) is OK the second call to api fails with error message No record(s) detected in request. Thanks to help me!

$verb = $event[‘request’][‘method’];

//file is on body

if($verb !== ‘POST’){
throw new \DreamFactory\Core\Exceptions\BadRequestException(‘Only POST is allowed on this endpoint.’);
}

$resourceParts = explode(“/”,$event[‘resource’]);
if (count($resourceParts) !== 2){
throw new \DreamFactory\Core\Exceptions\BadRequestException(‘l'url de la requete doit etre forme de la maniere suivante URL/{id}/{file}’);
}

$id = $resourceParts[0];
$fileName = $resourceParts[0];
$fileNameOnStore = sha1($event[‘request’][‘content’]);
$subPath = substr($fileNameOnStore, 0, 2);

//Mettre le binaire
$result1 = $platform[‘api’]->post-> __invoke(‘files/odooFileStore/’.$subPath.‘/’.$fileNameOnStore, $event[‘request’][‘content’]);

//enregistrer le fichier dans la base de données

$newRow = array(
“create_uid” => 1,
“description” => “testinsertiondepiecejointe”,
“res_model” => “res.partner”,
“type” => “binary”,
“datas_fname” => $fileName,
“res_name” => “Test to delete”,
“file_size” => strlen($event[‘request’][‘content’]),
“name” => “test rpasserieu”,
“company_id” => 1,
“write_uid” => 1,
“store_fname” => $subPath.“/”.$fileNameOnStore
);

$data_string = ‘{“resource”: [’.json_encode($newRow).‘]}’;

$options = array(
“CURLOPT_HTTPHEADER” => array(“Content-type: application/json”,“X-DreamFactory-Application-Name: odoocloneprod”)
);

$result2 = $platform[‘api’]->post-> __invoke(‘odoocloneprod/_table/ir_attachment’,$data_string);

$event[‘response’] = array(
‘status_sode’ => 200,
‘content’ => json_encode(array($result2,$data_string))
);

//return $newRowStr;
return;

I have found after many trys,

When using internal api with PHP dont use a json but an array.

Like that:

$newRow = array(‘resource’ => array(
“create_uid” => 1,
“description” => “something”,
“res_model” => “res.partner”,
“type” => “binary”,
“datas_fname” => $fileName,
“res_name” => " “,
“file_size” => strlen($event[‘request’][‘content’]),
“name” => “test”,
“company_id” => 1,
“write_uid” => 1,
“store_fname” => $subPath.”/".$fileNameOnStore
)
);

$result2 = $platform[‘api’]->post-> __invoke(‘odoocloneprod/_table/ir_attachment’,$newRow);

1 Like

Thanks @gnieark for posting your answer!

It’s much appreciated. I’m also glad to hear you were able to figure it out. :+1:

Cheers!
@AlexBowen