Can't Delete a DRAFT Invoice

Thank you for your prompt Reply.

Please see the attached .JPG, which shows Invoices #39 (the Inv. my below code is attempting to Delete) & #37 are, in fact, in the DRAFT state.

I am using the DeleteInvoice endpoint and believe the Invoice ID is correct, per my following code:

    var locationsResult = await squareClient.LocationsApi.ListLocationsAsync();
    string _sellerLocationId = locationsResult.Locations[0].Id;

    var _listInvoicesResult = await squareClient.InvoicesApi.ListInvoicesAsync(locationId: _sellerLocationId);

    foreach (Invoice myInv in _listInvoicesResult.Invoices)
    {
            if (myInv.Status == "DRAFT")
            {
                    try {
                            var deleteResult = await squareClient.InvoicesApi.DeleteInvoiceAsync(invoiceId: myInv.Id);
                            break;
                    }
                    catch (Square.Exceptions.ApiException e)
                    {
                            Console.WriteLine($" Failed to DELETE Newly Created INVOICE {myInv.InvoiceNumber}\n\t Response Code: {e.ResponseCode}\n\t Exception: {e.Message}");
                            foreach (Error foo in e.Errors) { Console.WriteLine($"\t Category: {foo.Category}"); Console.WriteLine($"\t Code: {foo.Code}"); Console.WriteLine($"\t Detail: {foo.Detail}"); Console.WriteLine($"\t Field: {foo.Field}"); }
                            return;
                    }
            }
    }

Regarding other useful information in the exception detailsWhat might I look for?

Interestingly, my Response Body = “Unrecognized content-type="application/x-www-form-urlencoded", supported: application/x-protobuf, application/json\n” – which appears to be the same as was happening in your Ruby SDK in Dec ’22, per this thread: https://developer.squareup.com/forums/t/invoice-api-ruby-sdk-delete/7893

I hope my above reply and attached .JPG is helpful. Please know, since asking this thread’s question, I’ve also filed this as Bug Report.

Looking forward to your thoughts.

Sincerely,

  • Michael Tigar | LOYAL DOG PRODUCTIONS | m: 818.687.4400