An Issue with saving SalesOrders data from REST API call to Exact Online

627 Views Asked by At

I have been using PHP Client library for Exact Online for a long time.

After saving the customer Accounts, Addresses, Contacts and then filtering out the PaymentConditions based on WooCommerce orders, items are successfully reflecting in the Exact Online dashboard.

But unfortunately calling the SalesOrders post request API. I'm unable to store into the Exact Online dashboard, even though in order to store only OrderedBy itself is enough which is given in the official documentation

$ordersn = $order->save();

Picqer\Financials\Exact\ApiException : Error 403: Forbidden

$order = new SalesOrder($connection);
$lines = new SalesOrderLine($connection);


....

echo'<pre>'; print_r($order); 
$order->SalesOrderLines = $lines;
$ordersn = $order->save();
if ($ordersn->ID)
{
    $orderitem['sync_flag'] = true;
}

Here is the details of an order array

Picqer\Financials\Exact\SalesOrder Object
(
    ...
    [attributes:protected] => Array
            (
                [WarehouseID] => 26ca2016-453f-499a-8a34-c986009bc78d
                [OrderID] => FC290B7D-766B-4CBB-B7A2-47327AA3841F
                [OrderedBy] => 764a4f6d-4b39-43b4-a86c-265e5478afbd
                [DeliverTo] => 764a4f6d-4b39-43b4-a86c-265e5478afbd
                [OrderDate] => 2019-02-17T19:29:53
                [YourRef] => 75591901YP220320G
                [OrderedByName] => Peter Kerner
                [Description] => 16031_PayPal/Lastschrift/Kreditkarte
                [Remarks] => Order is processing
                [PaymentReference] => 16031
                [PaymentCondition] => 
                [SalesOrderLines] => Picqer\Financials\Exact\SalesOrderLine Object
                    (
                        [attributes:protected] => Array
                            (
                                [OrderID] => FC290B7D-766B-4CBB-B7A2-47327AA3841F
                                [VATAmount] => 5,58
                                [Description] => Goodies Box
                                [Quantity] => 1,00
                                [UnitPrice] => 29,37
                                [Item] => 418d43d6-55fe-410a-8df2-b05cbb72cea5
                            )
                            ...
                    )
            )
    ...
)

Do we need to upload VAT code or Am I missing something else data to be resided first shown from the above order-array or what else should we need to call appropriate API. Since in-order to reflect on the Exact Online dashboard. what should we need to follow?

From the built-In function call addItem() below snippets of code:

$soLines = array(
                'OrderID' => $lines->OrderID,
                'Item' => $lines->Item,
                'Description' =>  $lines->Description,
                'Quantity' => $lines->Quantity,
                'UnitPrice' => $lines->UnitPrice,
                'VATAmount' => $lines->VATAmount,
                'VATCode' => $lines->VATCode
           );
$order->addItem($soLines);

Generates the results with LineNumber to be included in SalesOrderLines array

[attributes:protected] => Array
(
    [WarehouseID] => 26ca2016-453f-499a-8a34-c986009bc78d
    [OrderID] => 65F93F56-97A8-4D54-AE37-C0BDDE774E67
    [OrderedBy] => 9b048b81-f729-413a-b196-526436f11fe7
    [DeliverTo] => 9b048b81-f729-413a-b196-526436f11fe7
    [OrderDate] => 2019-02-17T20:45:34
    [YourRef] => 9Y9593859V795183K
    [OrderedByName] => Katrin Lenk
    [Description] => 16033_PayPal Express
    [Remarks] =>  Order is processing
    [PaymentReference] => 16033
    [PaymentCondition] => 
    [SalesOrderLines] => Array
        (
            [0] => Array
                (
                    [OrderID] => 65F93F56-97A8-4D54-AE37-C0BDDE774E67
                    [Item] => 5c415369-615c-4953-b28c-c7688f61cfaa
                    [Description] => ABC Classic
                    [Quantity] => 2,00
                    [UnitPrice] => 15,08
                    [VATAmount] => 5,73
                    [VATCode] => 
                    [LineNumber] => 1
                )

        )

)

Also note I haven't created Journals, GLAccounts, Documents & DocumentAttachments API. Does this actually affects storing of SalesOrders


EDIT:

In much simpler

$salesOrder = new \Picqer\Financials\Exact\SalesOrder($connection);
$salesOrder->WarehouseID = '26ca2016-453f-499a-8a34-c986009bc78d';
$salesOrder->OrderID = '65F93F56-97A8-4D54-AE37-C0BDDE774E67';
$salesOrder->OrderedBy = '9b048b81-f729-413a-b196-526436f11fe7';
$salesOrder->DeliverTo = '9b048b81-f729-413a-b196-526436f11fe7';
$salesOrder->OrderDate = '2019-02-17T20:45:34';
$salesOrder->YourRef = '9Y9593859V795183K';
$salesOrder->OrderedByName = 'Katrin Lenk';
$salesOrder->Description = '16033_PayPal Express';
$salesOrder->Remarks = 'Order is processing';
$salesOrder->PaymentReference = '16033';
$salesOrder->PaymentCondition = 'PP';

$soLines = array(
    'Item' => '5c415369-615c-4953-b28c-c7688f61cfaa',
    'Description' => 'ABC Classic',
    'Quantity' => '1,00',
    'UnitPrice' => '29,37',
    'OrderID' => '65F93F56-97A8-4D54-AE37-C0BDDE774E67'
);

echo '<pre>'; print_r($soLines);
$salesOrder->addItem($soLines);
echo '<pre>'; print_r($salesOrder);
$salesOrder->save();

Resulting value stored from the soLines array

[attributes:protected] => Array
(
    [WarehouseID] => 26ca2016-453f-499a-8a34-c986009bc78d
    [OrderID] => 65F93F56-97A8-4D54-AE37-C0BDDE774E67
    [OrderedBy] => 9b048b81-f729-413a-b196-526436f11fe7
    [DeliverTo] => 9b048b81-f729-413a-b196-526436f11fe7
    [OrderDate] => 2019-02-17T20:45:34
    [YourRef] => 9Y9593859V795183K
    [OrderedByName] => Katrin Lenk
    [Description] => 16033_PayPal Express
    [Remarks] =>  Order is processing
    [PaymentReference] => 16033
    [PaymentCondition] => 
    [SalesOrderLines] => Array
        (
            [0] => Array
                (
                    [OrderID] => 65F93F56-97A8-4D54-AE37-C0BDDE774E67
                    [Item] => 5c415369-615c-4953-b28c-c7688f61cfaa
                    [Description] => ABC Classic
                    [Quantity] => 2,00
                    [UnitPrice] => 15,08
                    [VATAmount] => 5,73
                    [VATCode] => 
                    [LineNumber] => 1
                )

        )

)

Actual Result:

Picqer\Financials\Exact\ApiException : Error 403: Forbidden

1

There are 1 best solutions below

0
On

The reason was OrderID value was included twice in the SalesOrderLine as well as in SalesOrder for the two REST API calls and removing the OrderID entry from SalesOrder worked perfectly and reflecting in the Exact Online Dashboard

You cannot assign $order->SalesOrderLines = $lines; directly resulting in a collection to array error. The only way to do this was to call via in-built function called addItem() passing array objects into it.