简体   繁体   中英

How can I add a sales receipt using the Rest API v2 with .NET into QuickBooks Online

I have tried alot to get this working. I finally found some code to create a sales receipt but when I try to add the sales receipt i get an error: "'', hexadecimal value 0x1F, is an invalid character. Line 1, position 1.". I am using Visual Web Developer. Here is the code I came up with:

realmId = "removed";
            accessToken = "removed";
            accessTokenSecret = "removed";
            consumerKey = ConfigurationManager.AppSettings["consumerKey"];
            consumerSecret = ConfigurationManager.AppSettings["consumerSecret"];
            dataSourcetype = IntuitServicesType.QBO;


            OAuthRequestValidator oauthValidator = new OAuthRequestValidator(accessToken, accessTokenSecret, consumerKey, consumerSecret);
            ServiceContext context = new ServiceContext(oauthValidator, realmId, dataSourcetype);
            DataServices commonService = new DataServices(context);



            Intuit.Ipp.Data.Qbo.SalesReceipt qboSalesReceipt = new Intuit.Ipp.Data.Qbo.SalesReceipt();

            //Create Header
            Intuit.Ipp.Data.Qbo.SalesReceiptHeader qboSalesReceiptHeader = new Intuit.Ipp.Data.Qbo.SalesReceiptHeader();
            qboSalesReceiptHeader.DocNumber = "abc123";
            qboSalesReceiptHeader.TxnDate = DateTime.Now;
            qboSalesReceiptHeader.TxnDateSpecified = true;
            qboSalesReceiptHeader.Note = "Sales Receipt Note";
            qboSalesReceiptHeader.CustomerId = new IdType() { idDomain = idDomainEnum.QBO, Value = "49" };

            //Set Payment Detail in Header
            /*Intuit.Ipp.Data.Qbo.PaymentDetail qboSalesReceiptHeaderPaymentDetail = new Intuit.Ipp.Data.Qbo.PaymentDetail();
            qboSalesReceiptHeaderPaymentDetail.Item = new CashPayment { Desc = "Cash Payment Ref #" };
            qboSalesReceiptHeader.Detail = qboSalesReceiptHeaderPaymentDetail;*/

            //Set Header
            qboSalesReceipt.Header = qboSalesReceiptHeader;

            //Set Line Item
            ItemsChoiceType2[] salesReceiptAttributes = { ItemsChoiceType2.ItemId, ItemsChoiceType2.UnitPrice, ItemsChoiceType2.Qty };
            object[] salesReceiptLineValues = { new IdType() { idDomain = idDomainEnum.QBO, Value = "5" }, new decimal(33), new decimal(2) };
            var salesReceiptLine = new SalesReceiptLine();
            salesReceiptLine.Amount = 66;
            salesReceiptLine.AmountSpecified = true;
            salesReceiptLine.Desc = "test " + DateTime.Now.ToShortDateString();
            salesReceiptLine.ItemsElementName = salesReceiptAttributes;
            salesReceiptLine.Items = salesReceiptLineValues;
            salesReceiptLine.ServiceDate = DateTime.Now;
            salesReceiptLine.ServiceDateSpecified = true;

            //Call IDS to Create Sales Receipt
           Intuit.Ipp.Data.Qbo.SalesReceipt addedSalesReceipt = commonService.Add(qboSalesReceipt) as SalesReceipt;
            //Intuit.Ipp.Data.Qbo.SalesReceipt addedSalesReceipt = commonService.Add(qboSalesReceipt);

            string message = "Sales receipt add complete";

            ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", message);

No matter what I do I just can't get this to work. I really appreciate anyones help. Thank you

Try to capture the raw XML request using some tools like fiddler. And then validate if the XML structure is OK(it will check the encoding issues too). You can try XML tools plugin of Notepad++ editor for this check.

You can test this request XML in ApiExplorer tool also.

Ref - https://developer.intuit.com/apiexplorer?apiname=V2QBO

Edit

QBO Ref - https://developer.intuit.com/docs/0025_quickbooksapi/0050_data_services/v2/0400_quickbooks_online/salesreceipt

A sample create XML for V2 QBO

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<SalesReceipt xmlns="http://www.intuit.com/sb/cdm/v2" xmlns:ns2="http://www.intuit.com/sb/cdm/qbopayroll/v1" xmlns:ns3="http://www.intuit.com/sb/cdm/qbo">
    <Header>
        <DocNumber>abc123</DocNumber>
        <TxnDate>2013-09-09-07:00</TxnDate>
        <Note>Sales Receipt Note</Note>     
        <CustomerId idDomain="QBO">1</CustomerId>
    </Header>
    <Line>
        <Id>1</Id>
        <Desc>Item1</Desc>
        <Amount>100.00</Amount>
        <Taxable>false</Taxable>
        <ItemId>3</ItemId>
    </Line>
</SalesReceipt>

Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM