0

我已经尝试了很多让这个工作。我终于找到了一些代码来创建销售收据,但是当我尝试添加销售收据时出现错误:“'',十六进制值 0x1F,是无效字符。第 1 行,位置 1。”。我正在使用 Visual Web Developer。这是我想出的代码:

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);

无论我做什么,我都无法让它发挥作用。我真的很感谢任何人的帮助。谢谢

4

1 回答 1

2

尝试使用 fiddler 等工具捕获原始 XML 请求。然后验证 XML 结构是否正常(它也会检查编码问题)。您可以尝试使用 Notepad++ 编辑器的 XML 工具插件进行此项检查。

您也可以在 ApiExplorer 工具中测试此请求 XML。

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

编辑

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

为 V2 QBO 创建 XML 的示例

<?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>

谢谢

于 2013-09-08T13:37:01.503 回答