Search code examples
c#asp.netquickbooksintuit-partner-platform

IPP .NET SDK for QuickBooks v3.0 Create Invoice Error - Bad Request


I am having a hard time figuring out what exactly is going wrong here - I do not get alot of insight form the error Bad Request - here is my code:

OAuthRequestValidator oauthValidator = new OAuthRequestValidator(accessToken, accessTokenSecret, consumerKey, consumerSecret);
                ServiceContext context = new ServiceContext(appToken, companyID, IntuitServicesType.QBO, oauthValidator);

                DataService service = new DataService(context);
                Customer customer = new Customer();
                customer.GivenName = "Mary " + DateTime.Now.Second;
                customer.Title = "Ms.";
                customer.MiddleName = "Jayne";
                customer.FamilyName = "Cooper";
                customer.CompanyName = "Mary " + DateTime.Now.Second;
                Customer resultCustomer = service.Add(customer) as Customer;

                Invoice invoice = new Invoice();
                //Mandatory fields
                invoice.DocNumber = Guid.NewGuid().ToString("N").Substring(0, 10);
                invoice.TxnDate = DateTime.Today.Date;
                invoice.TxnDateSpecified = true;
                invoice.CustomerRef = new ReferenceType()
                {
                     Value = resultCustomer.Id
                };

                Line invLine = new Line();

                invLine.Amount = 10000;
                invLine.DetailType = LineDetailTypeEnum.SalesItemLineDetail;
                invLine.Description = "Test Product";

                invoice.Line = new Line[] { invLine };

               Invoice resutlInvoice = service.Add(invoice) as Invoice;

                var invId = resutlInvoice.Id;

Basically I am generating a new customer (which work fine) and then I am trying to create an invoice for them with a single item on it.

Looking at what XML the documentation states here: http://ippdocs.intuit.com/0025_QuickBooksAPI/0050_Data_Services/V3/030_Entity_Services_Reference/Invoice

The NuGet package is missing a few things, which I know cant be true - form the documentation:

<Invoice xmlns="http://schema.intuit.com/finance/v3">
  <Line>
    <Amount>15</Amount>
    <DetailType>SalesItemLineDetail</DetailType>
    <SalesItemLineDetail>
      <ItemRef>1</ItemRef>
    </SalesItemLineDetail>
  </Line>
  <CustomerRef>67</CustomerRef>
</Invoice>

The Line object I get from this SDK has no properties for SalesItemLineDetail or ItemRef on it.

Anyone have a working example of this?


Solution

  • This is one of the areas where the .NET devkit differs from the Java one.

    You have to set the AnyIntuitObject property to the SalesItemLineDetail and then set the DetailType property to LineDetailTypeEnum.SalesItemLineDetail".

    There's a few bits and pieces around the framework that appear like this.

    Here's a short sample, although based on the comments it is not using the latest SDK.

    Line l = new Line()
    {
        l.AnyIntuitObject = new SalesItemLineDetail()
        {
            ItemElementName = ItemChoiceType.UnitPrice,
            AnyIntuitObject = amount,
            ...
        },
        DetailType = LineDetailTypeEnum.SalesItemLineDetail,
        ...
    }