jsgoupil / quickbooks-sync

Sync Quickbooks Desktop
MIT License
87 stars 40 forks source link

QuickBooks found an error when parsing the provided XML text stream. #29

Closed hhuutan closed 5 years ago

hhuutan commented 5 years ago

I'm trying to create a Sales Order but receive message: QuickBooks found an error when parsing the provided XML text stream. This is my XML:

<?xml version="1.0" encoding="utf-8"?>
<?qbxml version="13.0"?>
<QBXML>
  <QBXMLMsgsRq onError="stopOnError">
    <SalesOrderAddRq>
      <SalesOrderAdd defMacro="MACROTYPE">
        <SalesOrderLineAdd>
          <Rate>1.00</Rate>
          <ItemRef>
            <ListID>160000-933272656</ListID>
          </ItemRef>
          <Quantity>2.00</Quantity>
          <Amount>200.00</Amount>
        </SalesOrderLineAdd>
        <SalesOrderLineAdd>
          <Rate>1.00</Rate>
          <ItemRef>
            <ListID>1C0000-933272656</ListID>
          </ItemRef>
          <Quantity>2.00</Quantity>
          <Amount>200.00</Amount>
        </SalesOrderLineAdd>
        <CustomerRef>
          <ListID>800000DD-1702612106</ListID>
        </CustomerRef>
        <RefNumber>SO-001</RefNumber>
        <BillAddress>
          <Addr1>110 Main Street</Addr1>
          <Addr2>Suite 2000</Addr2>
          <State>TX</State>
          <PostalCode>99875</PostalCode>
          <Country>US</Country>
        </BillAddress>
        <DueDate>2019-10-10</DueDate>
      </SalesOrderAdd>
    </SalesOrderAddRq>
  </QBXMLMsgsRq>
</QBXML>

The reason is the order of fields is not match. For example, in your request the first tag should be CustomerRef, then RefNumber, after BillAddress etc. So here is a correct version of the request:

<?xml version="1.0" encoding="utf-8"?>
<?qbxml version="13.0"?>
<QBXML>
  <QBXMLMsgsRq onError="stopOnError">
    <SalesOrderAddRq>
      <SalesOrderAdd defMacro="MACROTYPE">
       <CustomerRef>
          <ListID>800000DD-1702612106</ListID>
        </CustomerRef>
        <RefNumber>SO-001</RefNumber>
        <BillAddress>
          <Addr1>110 Main Street</Addr1>
          <Addr2>Suite 2000</Addr2>
          <State>TX</State>
          <PostalCode>99875</PostalCode>
          <Country>US</Country>
        </BillAddress>
        <DueDate>2019-10-10</DueDate>
        <SalesOrderLineAdd>
          <ItemRef>
            <ListID>160000-933272656</ListID>
          </ItemRef>
          <Quantity>2.00</Quantity>
          <Rate>1.00</Rate>
          <Amount>200.00</Amount>
        </SalesOrderLineAdd>
        <SalesOrderLineAdd>
          <ItemRef>
            <ListID>1C0000-933272656</ListID>
          </ItemRef>
          <Quantity>2.00</Quantity>
          <Rate>1.00</Rate>
          <Amount>200.00</Amount>
        </SalesOrderLineAdd>
      </SalesOrderAdd>
    </SalesOrderAddRq>
  </QBXMLMsgsRq>
</QBXML>

How to fix it in the code?

jsgoupil commented 5 years ago

My latest commit lost the order of things. Let me see what I can do.

jsgoupil commented 5 years ago

Can you paste your code showing me how you make your request please?

hhuutan commented 5 years ago

My temporary solution is using [XmlElementAttribute(Order = ... )] above each public property in Objects class and it works well. My code example:

/// <remarks/>
        [XmlElementAttribute(Order = 1)]
        public CustomerRef CustomerRef
        {
            get
            {
                return this.customerRefField;
            }
            set
            {
                this.customerRefField = value;
            }
        }

        /// <remarks/>
        [XmlElementAttribute(Order = 2)]
        public ClassRef ClassRef
        {
            get
            {
                return this.classRefField;
            }
            set
            {
                this.classRefField = value;
            }
        }

        /// <remarks/>
        [XmlElementAttribute(Order = 3)]
        public TemplateRef TemplateRef
        {
            get
            {
                return this.templateRefField;
            }
            set
            {
                this.templateRefField = value;
            }
        }

        /// <remarks/>
        [XmlElementAttribute(Order = 4)]
        public DATETYPE TxnDate
        {
            get
            {
                return this.txnDateField;
            }
            set
            {
                this.txnDateField = value;
            }
        }

        /// <remarks/>
        [XmlElementAttribute(Order = 5)]
        [System.ComponentModel.DataAnnotations.StringLength(11)]
        public string RefNumber
        {
            get
            {
                return this.refNumberField;
            }
            set
            {
                string temp = QbNormalizer.NormalizeString(value, 11);
                this.refNumberField = temp;
            }
        }

        /// <remarks/>
        [XmlElementAttribute(Order = 6)]
        public BillAddress BillAddress
        {
            get
            {
                return this.billAddressField;
            }
            set
            {
                this.billAddressField = value;
            }
        }

        /// <remarks/>
        [XmlElementAttribute(Order = 7)]
        public ShipAddress ShipAddress
        {
            get
            {
                return this.shipAddressField;
            }
            set
            {
                this.shipAddressField = value;
            }
        }
jsgoupil commented 5 years ago

Can you please provide the code you use to make the request. The framework you use as well?

jsgoupil commented 5 years ago

I cannot repro the problem, so I need the code you used to make the problem happen. Not the solution.

jsgoupil commented 5 years ago

And tell me which framework you are using please...

hhuutan commented 5 years ago

I'm using .net core 2.2 in my web project

hhuutan commented 5 years ago

Hey, my lastest test in your sample was passed but in my project with .net core 2.2 was failed. This is probably the main reason. So sorry

jsgoupil commented 5 years ago

There is a problem with .NET Core 2.2 We will have to fix this.