Can't Delete a DRAFT Invoice

When trying to Delete a DRAFT Invoice (using C# - see code below), I’m getting a Response Code: 415 / “HTTP Response Not OK” Message. And on a side note, the ApiException Errors List is NULL.

var deleteResult = await squareClient.InvoicesApi.DeleteInvoiceAsync(invoiceId: myInv.Id);

Please advise/help.


:wave: I’m Square Dev AI, here to help answer your question!
Based on the information you’ve provided, the following documentation will help answer your question:

Additional Documentation

Update Invoices
Create and Publish Invoices
Invoices API Overview

If this documentation helped you find a solution, please check the box indicating that this reply solves the problem.
Otherwise one of our Developer Advocates will provide additional assistance shortly.

The error code 415 you’re encountering typically means “Unsupported Media Type”. This usually happens when the server refuses a particular request as the data format declared in the Content-Type header is not supported.

However, in your case, it seems like you’re trying to delete a draft invoice. According to Square’s documentation, you should be able to delete a draft invoice using the DeleteInvoice endpoint. Make sure that the invoice ID you’re providing is correct and that the invoice is indeed in the DRAFT state.

If you’re still encountering issues, it might be helpful to check the full details of the ApiException you’re receiving. Even though the Errors list is null, there might be other useful information in the exception details.

This answer was reviewed by @Bryan-Square.

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);
                    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}"); }

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:

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.


  • Michael Tigar | LOYAL DOG PRODUCTIONS | m: 818.687.4400