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

**URL:** <https://community.dreamfactory.com/t/help-for-custom-script-no-record-s-detected-in-request/3192>\
**Category:** Server-Side Scripting\
**Created:** [September 6, 2016, 1:02pm UTC](https://community.dreamfactory.com/t/help-for-custom-script-no-record-s-detected-in-request/3192 "2016-09-06T13:02:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gnieark](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.dreamfactory.com/gnieark/32/816_2.png) [@gnieark](https://community.dreamfactory.com/u/gnieark)\
**Post date:** [September 6, 2016, 1:02pm UTC](https://community.dreamfactory.com/t/help-for-custom-script-no-record-s-detected-in-request/3192/1 "2016-09-06T13:02:47Z")

</div>

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;

---

<div class="post-metadata">

**Author:** ![gnieark](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.dreamfactory.com/gnieark/32/816_2.png) [@gnieark](https://community.dreamfactory.com/u/gnieark)\
**Post date:** [September 6, 2016, 5:05pm UTC](https://community.dreamfactory.com/t/help-for-custom-script-no-record-s-detected-in-request/3192/2 "2016-09-06T17:05:43Z")

</div>

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);

---

<div class="post-metadata">

**Author:** ![DFCommunityManager](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.dreamfactory.com/dfcommunitymanager/32/887_2.png) [@DFCommunityManager](https://community.dreamfactory.com/u/DFCommunityManager)\
**Post date:** [September 7, 2016, 5:34pm UTC](https://community.dreamfactory.com/t/help-for-custom-script-no-record-s-detected-in-request/3192/3 "2016-09-07T17:34:10Z")

</div>

Thanks @gnieark for posting your answer!

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

Cheers!  
@AlexBowen
