We are working on integrating QBXML with an application of ours and all is working pretty well until today when we attempted to create a new NonInventoryItemPart using the WebConnector. Below is the XML we sent
<?xml version="1.0"?>
<?qbxml version="10.0"?>
<QBXML>
<QBXMLMsgsRq onError="continueOnError">
<ItemNonInventoryAddRq requestID="5468-22415">
<ItemNonInventoryAdd>
<Name>C-1531</Name>
<IsActive>false</IsActive>
<SalesAndPurchase>
<SalesDesc>Sumo Rucsac (225 lb +)… Single</SalesDesc>
<IncomeAccountRef>
<FullName>P/A - Over the Counter</FullName>
</IncomeAccountRef>
<ExpenseAccountRef>
<FullName>C/S P/A - Over the Counter</FullName>
</ExpenseAccountRef>
</SalesAndPurchase>
</ItemNonInventoryAdd>
</ItemNonInventoryAddRq>
</QBXMLMsgsRq>
</QBXML>
The response in the connection log was the well known error message of
0x80040400 :QuickBooks found an error when parsing the provided XML text
After some trial and error and internet searched, the SalesDesc
inner text is what is causing the error, specifically (I think) the plus sign. If we change the SalesDesc
inner text to Sumo Rucsac 225 lb Single
, this item is created successfully.
In C#, we need the ability to properly encode the request so that if other non acceptable characters appear, we can handle them appropriately. However, I cannot find any good details on what characters (encoding) are accepted nor exactly what type of encoding to use so we are more bullet-proof in the future (eg UrlEncoding, HtmlEncoding...custom function?). I could maintain a list of characters to remove, but that seems like it would lead to a maintenance nightmare.
EDIT - Thanks to @Amy below, the problem was narrowed down to ...
. For a temporary fix, we are using item.Name.Replace("...", "..");
to generate the inner text for our items. I still think we will need a more robust character handling going forward, but since its not + or ( or )
, I feel a bit more comfortable with this band-aid for now.