Topic: Creating Invoice through REST API
Using the Latest API module (modified by @ApMuthu) and guidance given in Wiki I modified the following file
facurlrest.php
<?php
// FrontAccounting Bridge REST Test Script
// Author: Ap.Muthu
// Website: www.apmuthu.com
// Release Date: 2012-11-28
include_once "fabridge.php";
$method = isset($_GET['m']) ? $_GET['m'] : 'g'; // g, p, t, d => GET, POST, PUT, DELETE
$action = isset($_GET['a']) ? $_GET['a'] : '';
$record = isset($_GET['r']) ? $_GET['r'] : '';
$filter = isset($_GET['f']) ? $_GET['f'] : false;
$data =  json_encode(array(
      'trans_type' => '10',
      'ref'=> 'NoGuia0001',
      'customer_id'=> '78',
      'branch_id'=> '78',
      'location'=> 'DEF',
      'deliver_to'=> 'ABC, S.A. DE C.V.',
      'delivery_date'=> '2019/11/09',
      'delivery_address'=> 'Karachi',
      'order_date'=> '09/11/2019',
      'phone'=> '',
      'cust_ref'=> '',
      'comments'=> '',
      'ship_via'=> '1',
      'payment'=> '1',
      'sales_type'=> '1',
      'items'=> array
        (
          0 => array
          (
            'stock_id'=> '2801',
            'description'=> 'iPhone',
            'qty'=> '1',
            'price'=> '100',
            'discount'=> '0'
          ),
          0 => array
          (
            'stock_id'=> '2802',
            'description'=> 'Samsung',
            'qty'=> '1',
            'price'=> '100',
            'discount'=> '0'
          ),
        ),
      ));
$output = fa_bridge($method, $action, $record, $filter, $data);
?>The $data is being read at modules/api/sales.inc at Line: 256 as below
Array
(
    [{"trans_type":"10","ref":"NoGuia0001","customer_id":"78","branch_id":"78","location":"DEF","deliver_to":"ABC,_S_A__DE_C_V_","delivery_date":"2019\/11\/09","delivery_address":"Karachi","order_date":"09\/11\/2019","phone":"","cust_ref":"","comments":"","ship_via":"1","payment":"1","sales_type":"1","items":] => Array
        (
            [{"stock_id":"2802","description":"Samsung","qty":"1","price":"100","discount":"0"}] => 
        )
)While the Correct JSON Presentation of this Data shall be
{"trans_type":"10","ref":"NoGuia0001","customer_id":"78","branch_id":"78","location":"DEF","deliver_to":"ABC, S.A. DE C.V.","delivery_date":"2019\/11\/09","delivery_address":"Karachi","order_date":"09\/11\/2019","phone":"","cust_ref":"","comments":"","ship_via":"1","payment":"1","sales_type":"1",
"items":[{"stock_id":"2802","description":"Samsung","qty":"1","price":"100","discount":"0"}]}How to handle this?
Due to wrong presentation of JSON Data I am not able to apply json_decode($data, true).
However, I have tested the api successfully by manually putting the correct presentation of this data on modules/api/sales.inc
Regards.



