Trying to Insert a ManualJournal into Xero with ODBC

  • 7 June 2023
  • 2 replies


I am trying to insert a manual journal entry into Xero using below SQL insert statement. And I get the following error. 
“A validation exception occurred: The total Debits (1.50) must equal total credits (0.00)" It suggests that cdata is not processing it as one API post but as 2 posts and Xero spits back an error because it expects both lines in the POST api. 

INSERT into ManualJournals ( JournalLine_AccountCode, JournalLine_LineAmount, Narration)
VALUES (620, 1.50, 'Test1'), (611, -1.50, 'Test1');

Any ideas would be appreciated. 


Best answer by AndyN 8 June 2023, 05:18

View original

2 replies

Userlevel 1

Hi Andy,


Using a traditional insert in this case would result in a validation error. You’re correct to say that this is because the API calls for each insert are done individually and this results in an error since total debits =/= total credits


If I understand your use-case correctly, you need to insert multiple line items simultaneously. This can be done by using the JournalLineAggregate column. Please refer to this part of the driver’s documentation (under the INSERT sector)::


In your case, I believe you would need to use the following query:

INSERT INTO ManualJournals (Narration, JournalLineAggregate)
'Test1', '<JournalLine><LineAmount>1.50</LineAmount><AccountCode>620</AccountCode></JournalLine> <JournalLine><LineAmount>-1.50</LineAmount><AccountCode>611</AccountCode></JournalLine>'


This would issue an API request with the following POST body:

<JournalLines><JournalLine><LineAmount>1.50</LineAmount><AccountCode>620</AccountCode></JournalLine> <JournalLine><LineAmount>-1.50</LineAmount><AccountCode>611</AccountCode></JournalLine></JournalLines>

Please let me know if your issue persists.


That works perfectly @Erold B  Thanks so much!!