API Forum

This forum is in read-only mode.
Please refer to our API support in case you have any questions.
We can be reached at api@e-conomic.com
e-conomic API developer forum

Uncaught SoapFault [Solved] UpdateFromData missing Handle

0
I get this when i try to update a Debtor using Debtor_UpdateFromData



It also tells me that the error is on line 329 and that is the 2nd line here-

                    $debtorHandle = $client-Debtor_UpdateFromData(array(
                    'data' = $DebtorData))-Debtor_UpdateFromDataResult;


Building the DebtorData looks like this


                $SweDebtorGroup = GetDebtorGroup($client); // Get our debtor group
                $Currency = $client-Currency_FindByCode(array(
                    'code' = 'SEK'))-Currency_FindByCodeResult; // get the handle for our Swedish crap
                $TermOfPayHandle = $client-TermOfPayment_FindByName(array(
                    'name' = 'Importerade Webshopar'))-TermOfPayment_FindByNameResult-TermOfPaymentHandle; // Get the handle for payment
                //Fake Enum for VatZone
                $VatZones = array('HomeCountry','EU','Abroad');
            //     if ($Store == 'Mobilfynd') {
                    $LayoutString = 'Mobilfynd Kvitto';
            //     } else {
            //         $LayoutString = 'Tell Your Friends Kvitto';
            //     }
                $Layout = $client-TemplateCollection_FindByName(array(
                'name' = $LayoutString))-TemplateCollection_FindByNameResult-TemplateCollectionHandle; // Set what recipt should have for layout

                $address = $magentoorder'in_street1'; // Set address with street1
                if(!empty($magentoorder'in_street2')) { // If there is something on street2
                    $address = \n  $magentoorder'in_street'; // Add new line and street2
                }
                $DebtorData = array(
                    'IsAccessible' = true,
//                     'Number' = $NewDebtorID, // must have it
                    'DebtorGroupHandle' = $SweDebtorGroup, // must have it
                    'Name' = $magentoorder'cus_name', // must have it
                    'TermOfPaymentHandle' = $TermOfPayHandle, // must have it
                    // Skipping Company on this line, don't export it atm, add it when we update the order export
                    'VatZone' = $VatZones0, // Must have it
                    'CurrencyHandle' = $Currency, // must have it
                    'LayoutHandle' = $Layout, // must have it
                    'Email' = $magentoorder'cus_email',
                    'TelephoneAndFaxNumber' = $magentoorder'cus_phone',
                    'Address' = $address,
                    'PostalCode' = $magentoorder'in_postalcode',
                    'City' = $magentoorder'in_city'
                );


                    $debtornr = $idarray$magentoorder'cus_id'; // Get the id
                    $DebtorData'Number' = $debtornr; // Set it in debtor array

I used almost exactly the same code in the old version of the import, so I can't see what's wrong
I printed the DebtorData array, and all is there.


Array ( IsAccessible = 1 DebtorGroupHandle = stdClass Object ( Number = 1 ) Name = Bj??rn Kraft TermOfPaymentHandle = stdClass Object ( Id = 16 ) VatZone = HomeCountry CurrencyHandle = stdClass Object ( Code = SEK ) LayoutHandle = stdClass Object ( Id = 4 ) Email = bjorn@tellyourfriendsse TelephoneAndFaxNumber = 0000000000 Address = Lustigkullev?¤gen 17 PostalCode = 59147 City = Motala Number = 4 )


Weird letters is due to phppage is not coded to DISPLAY utf8. And that have worked before.
created Mar 14, 2011 by Madman
0% Accept Rate
Q 5 A 13 C 0

1 Answer

0
I managed to figuer it out myself.
The problem was, that i copied a code that was used  Debtor_CreateFromData but, i'm useing this code to both update and create.
So, the DebtorData array remains the same.
How ever after that i posted a code where I inserted Number in to the array.
Bellow is the OLD complete code to deside if to update or to create

                if($idarray$magentoorder'cus_id') { // Does id have an e-c id?
                    $debtornr = $idarray$magentoorder'cus_id'; // Get the id
                    $DebtorData'Number' = $debtornr; // Set it in debtor array
                     // Update debtor in e-c and get returned handle
                    $debtorHandle = $client-Debtor_UpdateFromData(array(
                    'data' = $DebtorData))-Debtor_UpdateFromDataResult;
                    echo('Debtor '  $debtornr  'updated br/');
                } else {
                    $debtornr = GetNewDebtorID($client); // Get next free number
                    $DebtorData'Number' = $debtornr;
                    $debtorHandle = $client-Debtor_CreateFromData(array(
                    'data' = $DebtorData))-Debtor_CreateFromDataResult;
                    echo('Debtor '  $debtornr  ' createdbr/');
                    $idarray$magentoorder'cus_id' = $debtornr;
                    $string = serialize($idarray);
                    $file = fopen(dirname(__FILE__)  '/ids','w');
                    fwrite($file,$string);
                    fclose($file);
                }

The only diffrent from them is that get's an number from an array, while the other create a new number and creates a new debtor.

The new code looks like this.

                if($idarray$magentoorder'cus_id') { // Does id have an e-c id?
                    $debtornr = $idarray$magentoorder'cus_id'; // Get the id
                    $DebtorData'Number' = $debtornr; // Set it in debtor array
                    $DebtorData'Handle' = $client-Debtor_FindByNumber(array(
                    'number' = $debtornr))-Debtor_FindByNumberResult; // We are updateing, so we need to get the handle
//                     print_r($DebtorData);
//                     echo('br/br/');
                     // Update debtor in e-c and get returned handle
                    $debtorHandle = $client-Debtor_UpdateFromData(array(
                    'data' = $DebtorData))-Debtor_UpdateFromDataResult;
                    echo('Debtor '  $debtornr  'updated br/');
                } else {
                    $debtornr = GetNewDebtorID($client); // Get next free number
                    $DebtorData'Number' = $debtornr;
                    $debtorHandle = $client-Debtor_CreateFromData(array(
                    'data' = $DebtorData))-Debtor_CreateFromDataResult;
                    echo('Debtor '  $debtornr  ' createdbr/');
                    $idarray$magentoorder'cus_id' = $debtornr;
                    $string = serialize($idarray);
                    $file = fopen(dirname(__FILE__)  '/ids','w');
                    fwrite($file,$string);
                    fclose($file);
                }

As you can see i added a $DebtorData['Handle'] witch inserts the handle of the debtor to update.
That was my problem. Since I'm updateing E-conomic needs to know the handle of the debtor i'm updateing.
When createing we don't need it, simply beacuse there is no handle to send...
answered Mar 16, 2011 by Madman
Visma e-conomic A/S
...