The remote server returned an error: (400) Bad Request. while connecting to QB online through qbxml

StackOverflow https://stackoverflow.com/questions/10896524

  •  12-06-2021
  •  | 
  •  

Question

My connection to QB online is working fine. It also works for add customers to QB online. When i am passing checks through it gives Bad request error.

below is my qbxml.

string post = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
            <?qbxml version=""10.0""?>
            <QBXML>
            <SignonMsgsRq>
            <SignonDesktopRq>
            <ClientDateTime>%%CLIENT_DATE_TIME%%</ClientDateTime>
            <ApplicationLogin>%%AppLogin%%</ApplicationLogin>
            <ConnectionTicket>%%ConnTicket%%</ConnectionTicket>
            <Language>English</Language>
            <AppID>%%AppID%%</AppID>
            <AppVer>1</AppVer>
            </SignonDesktopRq>
            </SignonMsgsRq>
            <QBXMLMsgsRq onError=""continueOnError"">
            <CheckAddRq>                            
            <CheckAdd> 
                <AccountRef>
                    <ListID>1</ListID> 
                    <FullName>Chase Checking</FullName>
                </AccountRef>
                <PayeeEntityRef> 
                    <ListID>IDTYPE</ListID>
                    <FullName>Test Vendor</FullName> 
                </PayeeEntityRef>
                  <RefNumber>11</RefNumber> 
                  <TxnDate>05/06/2012</TxnDate> 
                  <Memo>My first Memo</Memo> 
                  <Address> 
                      <Addr1>Ahmedabad</Addr1> 
                      <Addr2>Ahmedabad</Addr2> 
                      <Addr3>Ahmedabad</Addr3> 
                      <Addr4>Ahmedabad</Addr4> 
                      <Addr5>Ahmedabad</Addr5> 
                      <City>Ahmedabad</City> 
                      <State>Gujarat</State> 
                      <PostalCode>360015</PostalCode> 
                      <Country>India</Country> 
                      <Note>Note</Note>                          
                </Address>
                <IsToBePrinted>N</IsToBePrinted>
                <ExchangeRate></ExchangeRate>
                <ExternalGUID></ExternalGUID> 
                <ApplyCheckToTxnAdd> 
                    <TxnID>9054</TxnID> 
                    <Amount>1000</Amount> 
                </ApplyCheckToTxnAdd>
                <ExpenseLineAdd>
                    <AccountRef>
                        <ListID></ListID>
                        <FullName>PublisherPayment</FullName> 
                    </AccountRef>
                    <Amount>100</Amount> 
                    <Memo>Memo</Memo>                            
                </ExpenseLineAdd>                             
            </CheckAdd>
            <IncludeRetElement>STRTYPE</IncludeRetElement> 
            </CheckAddRq>
            </QBXMLMsgsRq>
            </QBXML>";

Can anybody guide, please ?

Was it helpful?

Solution

As the qbxml version needs to be 6.0 (even though the IDN Unified On-Screen Reference shows 7.0)
I needed to include the onError="continueOnError" attribute.
Setting the WebRequestObject.ContentLength property is required.
Content Type needs to be "application/x-qbxml"
And finally I received many "The remote server returned an error: (400) Bad Request." exceptions which were not helpful at all but in the end I was able to trace them to something wrong with the xml. So if you get this exception look to your xml as the source of the problem.

So, finally i changed my xml as below.

    string post = @"<?xml version=""1.0"" encoding=""UTF-8""?>
<?qbxml version=""6.0""?>
<QBXML> 
                <SignonMsgsRq>
                <SignonDesktopRq>
                <ClientDateTime>%%CLIENT_DATE_TIME%%</ClientDateTime>
                <ApplicationLogin>%%AppLogin%%</ApplicationLogin>
                <ConnectionTicket>%%ConnTicket%%</ConnectionTicket>
                <Language>English</Language>
                <AppID>%%AppID%%</AppID>
                <AppVer>1</AppVer>
                </SignonDesktopRq>
                </SignonMsgsRq>
    <QBXMLMsgsRq onError=""stopOnError"">

        <CheckAddRq requestID=""1"">
            <CheckAdd>
                <AccountRef>
                    <FullName>Checking</FullName>
                </AccountRef>                
                <PayeeEntityRef>
                    <FullName>Departures Magazine</FullName>
                </PayeeEntityRef>
                <RefNumber>9999</RefNumber>
                <TxnDate>2012-06-06</TxnDate>
                <Memo>Injury Claims Payment</Memo>
                <Address>
                    <Addr1>Eli Manning</Addr1>
                    <Addr2>1234 S. Giant St</Addr2>
                    <City>New York</City>
                    <State>NY</State>
                    <PostalCode>40961</PostalCode>
                </Address>
                <IsToBePrinted>false</IsToBePrinted>
                <ExpenseLineAdd>
                    <AccountRef>
                        <FullName>Publisher Payment</FullName>
                    </AccountRef>
                    <Amount>200.00</Amount>
                </ExpenseLineAdd>
            </CheckAdd>
        </CheckAddRq>
    </QBXMLMsgsRq>
</QBXML>";
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top