1

How can I add an invoice or sales receipt using the QuickBooks API Rest v3? Preferably in .NET. I was interested previously in v2 but apparently that is going to be replaced soon. I can't seem to find any sample code in .NET to add a sales receipt or invoice for version 3. A simple example with minimum data supplied would be appreciated.

MohsinG
  • 121
  • 2
  • 11

1 Answers1

4

You can try the following code snippet.

   public void AddInvoice()
   {
       OAuthRequestValidator reqValidator = new OAuthRequestValidator(accessToken, accessTokenSecret, consumerKey, consumerKeySecret);
       ServiceContext context = new ServiceContext(realmId, IntuitServicesType.QBO, reqValidator);

       Invoice added = Helper.Add<Invoice>(qboContextoAuth, CreateInvoice(qboContextoAuth));

   }

   internal Invoice CreateInvoice(ServiceContext context)
    {
        Customer customer = FindorAdd<Customer>(context, new Customer());
        TaxCode taxCode = FindorAdd<TaxCode>(context, new TaxCode());
        Account account = FindOrADDAccount(context, AccountTypeEnum.AccountsReceivable, AccountClassificationEnum.Liability);

        Invoice invoice = new Invoice();
        invoice.Deposit = new Decimal(0.00);
        invoice.DepositSpecified = true;
        invoice.AllowIPNPayment = false;
        invoice.AllowIPNPaymentSpecified = true;

        invoice.CustomerRef = new ReferenceType()
        {
            name = customer.DisplayName,
            Value = customer.Id
        };
        invoice.DueDate = DateTime.UtcNow.Date;
        invoice.DueDateSpecified = true;
        invoice.GlobalTaxCalculation = GlobalTaxCalculationEnum.TaxExcluded;
        invoice.GlobalTaxCalculationSpecified = true;
        invoice.TotalAmt = new Decimal(0.00);
        invoice.TotalAmtSpecified = true;
        invoice.ApplyTaxAfterDiscount = false;
        invoice.ApplyTaxAfterDiscountSpecified = true;

        invoice.PrintStatus = PrintStatusEnum.NotSet;
        invoice.PrintStatusSpecified = true;
        invoice.EmailStatus = EmailStatusEnum.NotSet;
        invoice.EmailStatusSpecified = true;
        invoice.ARAccountRef = new ReferenceType()
        {
            type = Enum.GetName(typeof(objectNameEnumType), objectNameEnumType.Account),
            name = "Account Receivable",
            Value = "QB:37"
        };
        invoice.Balance = new Decimal(0.00);
        invoice.BalanceSpecified = true;

        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;

        lineList.Add(line);
        invoice.Line = lineList.ToArray();
        TxnTaxDetail txnTaxDetail = new TxnTaxDetail();
        txnTaxDetail.DefaultTaxCodeRef = new ReferenceType()
        {
            Value = taxCode.Id,
            type = Enum.GetName(typeof(objectNameEnumType), objectNameEnumType.Customer),
            name = taxCode.Name
        };

        txnTaxDetail.TotalTax = new Decimal(0.00);
        txnTaxDetail.TotalTaxSpecified = true;


        return invoice;
    }

V3 Invoice Doc Ref - https://developer.intuit.com/docs/0025_quickbooksapi/0050_data_services/v3/030_entity_services_reference/invoice Hope, it will be useful to you.

Thanks

Manas Mukherjee
  • 5,270
  • 3
  • 18
  • 30
  • Hi, this works but I wanted to specify line item details. When I specify LineDetailTypeEnum.SalesItemLineDetail, I get error bad request. Can you please post a sample with SalesItemLineDetail. Maybe with Quantity and unit price. Thanks – MohsinG Sep 08 '13 at 23:28
  • 2
    Plz check the ans of the following thread. http://stackoverflow.com/questions/18542914/ipp-net-sdk-for-quickbooks-v3-0-create-invoice-error-bad-request/18622269#18622269 Thanks – Manas Mukherjee Sep 09 '13 at 07:48
  • @ManasMukherjee is the code above correct for the tax portion? It looks like you are creating a txnTaxDetail but then never attaching it to the Invoice in any manner? – crichavin Feb 27 '14 at 20:08
  • Yes.. while writing this POC(it was just for a sample Invoice creation :) ), I missed to associate txnTaxDetail with the invoice. I'll update my post. Thanks – Manas Mukherjee Feb 28 '14 at 05:52