Quickbooks API V2 QBD - 查看如何使用RecordCountQuery的示例

时间:2013-08-19 13:27:16

标签: intuit-partner-platform

我在.NET中工作,使用QuickBooks V2 API尝试获取用户QBD项目数量的计数。

有没有人有一个如何实现“RecordCountQuery”类来查找QBD中的项目数的工作示例?

这是我尝试这样做之一:

//
// Get a record count of the items
//
var qbItemsCount = new RecordCountQuery();

var myResults = qbItemsCount.ExecuteQuery<Item>(_oQBIDataServices.ServiceContext);

错误:

Intuit.Ipp.Exception.IdsException was unhandled by user code
  HResult=-2146233088
  Message= The RecordCountQuery xml must wrap an existing supported query object. Please modify your query and try again.
  Source=""
  ErrorCode=-2015

我认为我应该在“ExecuteQuery”方法中使用不同的类型,如Intuit.Ipp.Data.QBD.ItemQuery。我试过这个,但得到了一个不同的错误。

所以我要求的不一定是对上面代码的修正,而是.NET中RecordCountQuery类的工作示例。

谢谢。

1 个答案:

答案 0 :(得分:2)

修改 - 添加.net代码

RecordCountQuery query = new RecordCountQuery();
CustomerQuery custQuery = new CustomerQuery();
query.Item1 = custQuery;
List<RecordCount> customerRecordCountQuery = query.ExecuteQuery<RecordCount>(context).ToList();
string customerCount = customerRecordCountQuery[0].Count;

我有一个工作的java代码。请检查它是否有用。

API端点 - https://services.intuit.com/sb/recordcount/v2/ {* relam_id *}

POST正文

<RecordCountQuery xmlns="http://www.intuit.com/sb/cdm/v2">
    <CustomerQuery/>
</RecordCountQuery>

回复

<?xml version="1.0" encoding="UTF-8"?><!--XML GENERATED by IntuitDataSyncEngine (IDS) using \\SBDomainServices\CDM\branches\3.9.0-rel-1-->
<RestResponse xmlns="http://www.intuit.com/sb/cdm/v2"
xmlns:xdb          ="http://xmlns.oracle.com/xdb"
xmlns:xsi          ="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation ="http://www.intuit.com/sb/cdm/v2 ../common/RestDataFilter.xsd"><RecordCounts>
<RecordCount>
<ObjectName>Customer</ObjectName>
<Count>392</Count>
</RecordCount>
</RecordCounts></RestResponse>

Java代码

public int testGetCount() {
    int objectCount = 0;
    try {
        QBCustomerQuery CustomerQuery = QBObjectFactory.getQBObject(
                context, QBCustomerQuery.class);
        QBDRecordCountService iRecordCountSer = QBDServiceFactory
                .getService(context, QBDRecordCountService.class);
        List<QBRecordCountImpl> recordCounts = iRecordCountSer.getCount(
                context, CustomerQuery);
        Iterator<QBRecordCountImpl> iterator = recordCounts.iterator();
        while (iterator.hasNext()) {
            QBRecordCountImpl next = iterator.next();
            objectCount = Integer.parseInt(next.getCount().toString());
        }
        System.out.println("Customer count - " + objectCount);
    } catch (QBInvalidContextException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return objectCount;
}

由于