I am trying to insert an invoice via IPP into a blank Quickbooks store. The insert will always fail because the Item's ID for the Invoice line item does not exist. I have been trying multiple paths to code around this with no success. I thought I could query for the Items and if it cannot find the one I am looking for It will create it. I cannot seem to get this to work. Can I just build an Invoice with a new Item I have created?
I currently build the invoice like this: (the problem is the line that starts with "object[] invoiceItemValues") Intuit.Ipp.Data.Qbd.InvoiceHeader invoiceHeader = new Intuit.Ipp.Data.Qbd.InvoiceHeader(); invoiceHeader.ARAccountName = "Accounts Receivable"; invoiceHeader.BillAddr = physicalAddress; invoiceHeader.CustomerName = customer.Name; invoiceHeader.DocNumber = (invoiceMaxId).ToString().PadLeft(4, '0'); invoiceHeader.TaxAmt = salesTax; invoiceHeader.TotalAmt = amount;
List<Intuit.Ipp.Data.Qbd.InvoiceLine> listLine = new List<Intuit.Ipp.Data.Qbd.InvoiceLine>();
Intuit.Ipp.Data.Qbd.ItemsChoiceType2[] invoiceItemAttributes = { Intuit.Ipp.Data.Qbd.ItemsChoiceType2.ItemId, Intuit.Ipp.Data.Qbd.ItemsChoiceType2.UnitPrice, Intuit.Ipp.Data.Qbd.ItemsChoiceType2.Qty };
object[] invoiceItemValues = { new Intuit.Ipp.Data.Qbd.IdType() { idDomain = Intuit.Ipp.Data.Qbd.idDomainEnum.QB, Value = "2" }, amount, new decimal(1) };
var invoiceLine = new Intuit.Ipp.Data.Qbd.InvoiceLine();
invoiceLine.Amount = amount;
invoiceLine.AmountSpecified = true;
invoiceLine.Desc = "test " + date.ToShortDateString(); // TODO: This will need to hold the additional fields
invoiceLine.ItemsElementName = invoiceItemAttributes;
invoiceLine.Items = invoiceItemValues;
invoiceLine.ServiceDate = date;
invoiceLine.ServiceDateSpecified = true;
listLine.Add(invoiceLine);
Intuit.Ipp.Data.Qbd.Invoice invoice = new Intuit.Ipp.Data.Qbd.Invoice();
invoice.Header = invoiceHeader;
invoice.Line = listLine.ToArray();
This is the error I get: "Validation for txn_line_rec.item_id INVALID key = 30 domain=QB enum = Item"
Here is what tries to query Items, but also requires IDs.
ItemQuery qbdItemQuery = new ItemQuery();
qbdItemQuery.Items = new object[] { new IdSet() { Id = new IdType[] { new IdType() { idDomain = idDomainEnum.NG, Value = "79841" } } } };
qbdItemQuery.ItemsElementName = new ItemsChoiceType4[] { ItemsChoiceType4.ListIdSet };
List<Item> ItemQueryResult = qbdItemQuery.ExecuteQuery<Item>(context).ToList<Item>();
Please see the sample in QBO, similarly you can code for QBD- Intuit.Ipp.Data.Qbo.Invoice invoice = new Intuit.Ipp.Data.Qbo.Invoice();
Edit: To create item-