I am trying to send a PurchaseOrder created with Intuit .NET SDK v3. I found a suitable example with Invoice: how to add invoice or sales receipt quickbooks rest api v3.0
But I cannot work out what I need to do to make it working for Purchase Order. I am getting BadRequest no matter what properties do I set.
DataService commonService = new DataService(context);
QueryService<Vendor> accountQueryService = new QueryService<Vendor>(context);
Vendor customer = accountQueryService.Where(x => x.Id == "9").FirstOrDefault<Vendor>();
QueryService<Item> itemQueryService = new QueryService<Item>(context);
Item item = itemQueryService.Where(x => x.Id == "1").FirstOrDefault<Item>();
PurchaseOrder invoice = new PurchaseOrder();
invoice.VendorRef = new ReferenceType()
{
name = customer.DisplayName,
Value = customer.Id
};
/*invoice.APAccountRef = new ReferenceType()
{
type = Enum.GetName(typeof(objectNameEnumType), objectNameEnumType.Account),
name = "Account Receivable",
Value = "QB:37"
};*/
List<Line> lineList = new List<Line>();
Line line = new Line();
line.Description = "Description";
line.Amount = new Decimal(100.00);
line.AmountSpecified = true;
//line.DetailType = LineDetailTypeEnum.DescriptionOnly;
//line.DetailTypeSpecified = true;
line.DetailType = LineDetailTypeEnum.PurchaseOrderItemLineDetail;
line.DetailTypeSpecified = true;
PurchaseOrderItemLineDetail det = new PurchaseOrderItemLineDetail();
det.Qty = 10;
det.QtySpecified = true;
det.ItemRef = new ReferenceType()
{
name = item.Name,
Value = item.Id
};
line.AnyIntuitObject = det;
lineList.Add(line);
invoice.Line = lineList.ToArray();
I've tried to set account and use just description in the line without success. If I add PurchaseOrder created with the above code I am getting BadRequest error with Validation exception inside.
Can please somebody point me in the right direction here. I am probably missing some PurchaseOrder property.
I am using the August V3 SDK loaded using NuGet.
UPDATE
This is c# translation of the XML suggested by Manas Mukherjee below
DataService commonService = new DataService(context);
QueryService<Vendor> accountQueryService = new QueryService<Vendor>(context);
Vendor customer = accountQueryService.Where(x => x.Id == "9").FirstOrDefault<Vendor>();
QueryService<Item> itemQueryService = new QueryService<Item>(context);
Item item = itemQueryService.Where(x => x.Id == "1").FirstOrDefault<Item>();
PurchaseOrder invoice = new PurchaseOrder();
invoice.TxnDate = DateTime.Now;
invoice.TxnDateSpecified = true;
invoice.Memo = "For Internal usage";
invoice.GlobalTaxCalculation = GlobalTaxCalculationEnum.TaxInclusive;
invoice.GlobalTaxCalculationSpecified = true;
invoice.ReplyEmail = new EmailAddress();
invoice.ReplyEmail.Address = "testing@testing.com";
invoice.ReplyEmail.Default = false;
invoice.ReplyEmail.DefaultSpecified = true;
invoice.ReplyEmail.Tag = "Home";
invoice.ShipAddr = new PhysicalAddress();
invoice.ShipAddr.Line1 = "shippingToAddr1Sat Oct 19 09:48:52 IST 2013";
invoice.ShipAddr.Line2 = "shippingToAddr2Sat Oct 19 09:48:52 IST 2013";
invoice.ShipAddr.Line3 = "shippingToAddr3Sat Oct 19 09:48:52 IST 2013";
invoice.ShipAddr.City = "Bangalore";
invoice.ShipAddr.Country = "India";
invoice.ShipAddr.CountrySubDivisionCode = "KA";
invoice.ShipAddr.PostalCode = "560045";
invoice.POEmail = new EmailAddress();
invoice.POEmail.Address = "testing@testing.com";
invoice.POEmail.Default = true;
invoice.POEmail.DefaultSpecified = true;
invoice.POEmail.Tag = "Business";
invoice.VendorRef = new ReferenceType()
{
name = customer.DisplayName,
Value = customer.Id
};
invoice.TotalAmt = new Decimal(100.00);
invoice.TotalAmtSpecified = true;
invoice.APAccountRef = new ReferenceType()
{
//type = Enum.GetName(typeof(objectNameEnumType), objectNameEnumType.Account),
name = "Accounts Payable (A/P)",
Value = "32"
};
List<Line> lineList = new List<Line>();
Line line = new Line();
line.Amount = new Decimal(100.00);
line.AmountSpecified = true;
line.DetailType = LineDetailTypeEnum.AccountBasedExpenseLineDetail;
line.DetailTypeSpecified = true;
AccountBasedExpenseLineDetail det = new AccountBasedExpenseLineDetail();
det.AccountRef = new ReferenceType()
{
name = "Accounts Payable (A/P)",
Value = "32"
};
line.AnyIntuitObject = det;
/*PurchaseOrderItemLineDetail det = new PurchaseOrderItemLineDetail();
det.Qty = 10;
det.QtySpecified = true;
det.ItemRef = new ReferenceType()
{
name = item.Name,
Value = item.Id
};
line.AnyIntuitObject = det;*/
lineList.Add(line);
invoice.Line = lineList.ToArray();
return invoice;
Unfortunately I am still getting BadRequest error.
UPDATE 2
After some more testing I found out that it gives error because of APAccountRef property. It's OK without setting up this property.
The other issue came when I tried to use PurchaseOrderItemLineDetail in lines. Not sure if this type is correct (based on the name it looks like one) but using this details type is causing BadRequest error. Using ItemBasedExpenseLineDetail is a workaround.
I will set Manas answer as correct since it gave me a direction to investigate further. But big thanks to Nimisha Shrivastava for the help with logging.