问题
Please help me on writing a check using the QuickBooks online(Qbo) API. I tried to do that but i'm always getting an error saying "Error validating Detail Lines:At least one detail line is required." Sample Code is in Below.. How should I add Lines for Checks.
Dim existingChk = New Qbo.Check()
Dim existingChks = commonService.FindAll(existingChk, 1, 10).ToList()
Dim payment = New Qbo.Payment()
Dim payments = commonService.FindAll(payment, 1, 10).ToList()
Dim qboCheck = New Intuit.Ipp.Data.Qbo.CheckHeader()
Dim bank = New Intuit.Ipp.Data.Qbo.Account()
bank.Type = Intuit.Ipp.Data.Qbo.AccountTypeEnum.Asset
Dim Banks = commonService.FindAll(bank, 1, 100).ToList()
Dim accountId As New Qbo.IdType
For Each bnk As Intuit.Ipp.Data.Qbo.Account In Banks
If bnk.Name = "Test Bank" Then
accountId = bnk.Id
End If
Next
qboCheck.BankAccountId = accountId
qboCheck.BankAccountName = "Test Bank"
qboCheck.TotalAmt = 20.0
qboCheck.Currency = Intuit.Ipp.Data.Qbo.currencyCode.USD
qboCheck.TxnId = payments(0).Id
Dim qboCustomer = New Intuit.Ipp.Data.Qbo.Customer()
Dim qboCustomers = commonService.FindAll(qboCustomer, 1, 10).ToList()
For Each cus As Intuit.Ipp.Data.Qbo.Customer In qboCustomers
If cus.Name.Contains("Customer1") Then
qboCheck.EntityId = cus.Id
End If
Next
qboCheck.EntityType = Qbo.EntityTypeEnum.Customer
Dim check = New Intuit.Ipp.Data.Qbo.Check()
check.Header = qboCheck
check.Id = New Qbo.IdType
check.Id.idDomain = existingChks(0).Id.idDomain
check.Id.Value = CInt(existingChks(0).Id.Value) + 1
Dim resultCheck As Qbo.Check = TryCast(commonService.Add(check), Qbo.Check)
回答1:
Looks like it is a bug in .net devkit(I'm not 100% sure). JavaDocs says accountId and itemId both are inherited from LinePurchase(PFB snapshot). But in .net devkit, I don't see those fields neither in LinePurchase nor in LineBase.
JavaDoc Ref - http://developer-static.intuit.com/SDKDocs/QBV2Doc/ipp-java-devkit-2.0.10-SNAPSHOT-javadoc/

API endpoints are working fine.
https://developer.intuit.com/docs/0025_quickbooksapi/0050_data_services/v2/0400_quickbooks_online/check#Sample_Create_Request_XML
<?xml version="1.0" encoding="utf-8" ?>
<Check xmlns:ns2="http://www.intuit.com/sb/cdm/qbo" xmlns="http://www.intuit.com/sb/cdm/v2">
<Header>
<TxnDate>2013-08-09</TxnDate>
<BankAccountId>44</BankAccountId>
<EntityId>2</EntityId>
</Header>
<Line>
<Desc>Hard Disks</Desc>
<Amount>500</Amount>
<BillableStatus>NotBillable</BillableStatus>
<ItemId>4</ItemId>
<Qty>10</Qty>
<UnitPrice>50</UnitPrice>
</Line>
</Check>
PN -
<BankAccountId>
: This account should be a 'checking' type.
<ItemId>
: Item should have a 'ExpenseAccountRef' tag.
You can test this usecase, using ApiExplorer tool.
Link - https://developer.intuit.com/apiexplorer?apiname=V2QBO
If possible I'll try this using .net devkit on monday and confirm if it is a bug in .net devkit.
Thanks
回答2:
Adding pseudo code for c# for BillpaymentHeader.
Similarly you can use it for CheckLine:
billheader.ItemsElementName = new ItemsChoiceType[1];
billheader.ItemsElementName[0] = ItemsChoiceType.BankAccountId;
billheader.Items = new object[1];
billheader.Items[0] = new Intuit.Ipp.Data.Qbo.IdType() { idDomain = Intuit.Ipp.Data.Qbo.idDomainEnum.QBO, Value = "1" };
Refer- How to add AccountID or ItemID when creating Checks in QuickBooks
回答3:
If you have bill already then you can simply use billpayment API to create checks. URL : https://quickbooks.api.intuit.com/v3/company/111111111111/billpayment?minorversion=4
request JSON data:
{
"VendorRef": {
"value": "1",
"name": "vendor_name"
},
"PayType": "Check",
"CheckPayment": {
"BankAccountRef": {
"value": "1",
"name": "Test Account"
}
},
"TotalAmt": 100.00,
"PrivateNote": "Acct. 1JK90",
"Line": [
{
"Amount": 100.00,
"LinkedTxn": [
{
"TxnId": "1",
"TxnType": "Bill"
}
]
}
]
}
来源:https://stackoverflow.com/questions/17342010/create-checks-with-quickbooks-api