intuit / QuickBooks-V3-DotNET-SDK

.Net SDK for QuickBooks REST API v3 services
Apache License 2.0
107 stars 140 forks source link

BadRequest on SalesReceipt Add when using SalesLineItemDetail #326

Open nasai5533 opened 9 months ago

nasai5533 commented 9 months ago

I get the following exception when using a SalesLineItemDetail for AnyIntuitObject on a Line when adding a SalesReceipt: BadRequest. Details: Required parameter Line.SalesItemLineDetail is missing in the request

This appears to happen when I use the SalesItemLineDetail object without setting any of its properties. If I set any property, say ServiceDate and ServiceDateSpecified, it works. Without setting a property, the object gets serialized as <SalesLineItemDetail/>, which for some reason gets rejected. Since according to the documentation all properties of SalesItemLineDetail are optional, I believe the intended functionality should be for an empty SalesItemLineDetail to be accepted.

This works: AnyIntuitObject = new SalesItemLineDetail() { ServiceDate = DateTime.Now, ServiceDateSpecified = true }

This works: AnyIntuitObject = new SalesItemLineDetail() { Qty = 1, QtySpecified = true }

This does not work: AnyIntuitObject = new SalesItemLineDetail()

tcm614ce commented 9 months ago

I get the following exception when using a SalesLineItemDetail for AnyIntuitObject on a Line when adding a SalesReceipt: BadRequest. Details: Required parameter Line.SalesItemLineDetail is missing in the request

@nasai5533, I am receiving a different error, Intuit.Ipp.Exception.IdsException: 'BadRequest. Details: Required parameter Line.DetailType is missing in the request , '

I am including the Line.Detail Type = LineDetailTypeEnum.SalesItemLineDetail. Would you mind sharing your code to create a Sales Receipt?

nasai5533 commented 9 months ago

I get the following exception when using a SalesLineItemDetail for AnyIntuitObject on a Line when adding a SalesReceipt: BadRequest. Details: Required parameter Line.SalesItemLineDetail is missing in the request

@nasai5533, I am receiving a different error, Intuit.Ipp.Exception.IdsException: 'BadRequest. Details: Required parameter Line.DetailType is missing in the request , '

I am including the Line.Detail Type = LineDetailTypeEnum.SalesItemLineDetail. Would you mind sharing your code to create a Sales Receipt?

You have to both set the DetailType and set DetailTypeSpecified to true

tcm614ce commented 9 months ago

Ah yes! That works! Weird, but o.k., thanks so much!

nasai5533 commented 9 months ago

No problem! And yes, it's a paradigm sometimes used in languages which don't allow for nullable value types. In the case they receive a call from you where the value for the DetailType property has been left at its default value, they want to be sure you actually intended to use the default value rather than forgot to set it.

Because .NET allows for nullable value types, they could have easily set the type of the property to LineDetailTypeEnum? or Nullable and throw the exception when they receive null. DetailTypeSpecified would be redundant in this case and they could safely remove it. But this is all doubly weird because they could easily just inspect the type of the object you assigned to AnyIntuitObject and get rid of both properties. The inclusion of this kind of enum at all is a paradigm for languages that don't make the use of static typing.