0

I am getting error while creating invoice with XERO PHP SDK. The values passed are correct.

Error : [500] Server error: PUT https://api.xero.com/api.xro/2.0/Invoices?summarizeErrors=false&unitdp=4 resulted in a 500 Internal Server Error response: {"Title":"An error occurred","Detail":"An error occurred in Xero. Check the API Status page http://status.developer.xero (truncated...)

My code is:

        // Line Item tracking
        $tracking = new XeroAPI\XeroPHP\Models\Accounting\LineItemTracking;
            
        $tracking->setName("Unit No")->setOption($property);

        $arr_trackings = [];
        array_push($arr_trackings, $tracking);
        
        $tracking = new XeroAPI\XeroPHP\Models\Accounting\LineItemTracking;
            
        $tracking->setName("Room ID")->setOption("");
                                 
        array_push($arr_trackings, $tracking);

        $invoice = new XeroAPI\XeroPHP\Models\Accounting\Invoice;
        $invoice->setType("ACCPAY");
        $invoice->setReference($property  . " - " . $billmonth);
        
        $invoice->setDate($invoicedate);
        $invoice->setDueDate($duedate);
        
        $xerocustomerid = $this->xeromodel->GetBillContactID($company);
        
        $contact = new XeroAPI\XeroPHP\Models\Accounting\Contact;
        $contact->setContactID($xerocustomerid);            
        $invoice->setContact($contact);

        $invoice->setStatus("SUBMITTED");
        
        $invoice->setLineAmountTypes("Exclusive");
        
        $lineitem = new XeroAPI\XeroPHP\Models\Accounting\LineItem;
        
        $spaccode = "56400";
                
        $lineitem->setDescription(htmlspecialchars($spacno . " - " . $property));
        $lineitem->setQuantity(1);
        $lineitem->setUnitAmount($spamount);
        $lineitem->setAccountCode($spaccode);
        $lineitem->setTaxType("NONE");
        $lineitem->setTracking($arr_trackings); 
        
        $lineitems = [];
                        
        array_push($lineitems, $lineitem);
                        
        $invoice->setLineItems($lineitems);

        // invoices
        $arr_invoices = [];
        
        array_push($arr_invoices, $invoice);

        $invoices = new XeroAPI\XeroPHP\Models\Accounting\Invoices;
        $invoices->setInvoices($arr_invoices);

        $apiResponse = $accountingApi->createInvoices($xeroTenantId, $invoices, $summarize_errors, $unitdp);
arun kumar
  • 703
  • 2
  • 13
  • 33
  • If you post the same data to the previewer, does it give you any more information? A 500 error usually indicates an error in the formation of your data. I use VB, but I can get extended information from the response, I've no idea how you might do that in PHP. Presumably you've defined all the variables that you use somewhere else, and not included them in the post for brevity? – droopsnoot Nov 03 '20 at 12:26
  • PHP SDK does not provide the extended information. It gives this generic error. – arun kumar Nov 03 '20 at 16:21
  • The issue seems to be an account code not available in xero account. It works now. PHP sdk should show the validation errors instead of raising an generic exception. – arun kumar Nov 04 '20 at 06:33
  • I must admit I don't use much of the .net SDK because I found it really complicated, so I do raw HTTP calls to the various endpoints, and the extended error messages are returned in the response if you dig far enough. I only really use the SDK to get all the data structures. – droopsnoot Nov 04 '20 at 08:37

0 Answers0