How to create a blank spreadsheet using the Google Docs API

I am trying to create a blank spreadsheet through the Google Docs API, but I’m encountering problems. Every time I make my request, I receive an error stating that the “document could not be converted.”

Here’s the code that I am using:

$requestBody = "--PART_BOUNDARY\r\n".
        "Content-Type: application/atom+xml;\r\n\r\n".
        "<?xml version='1.0' encoding='UTF-8'?>
        <entry xmlns=\"http://www.w3.org/2005/Atom\" xmlns:docs=\"http://schemas.google.com/docs/2007\">
          <category scheme=\"http://schemas.google.com/g/2005#kind\"
              term=\"http://schemas.google.com/docs/2007#spreadsheet\"/>
            <title>".$spreadsheetName."</title>
        </entry>\r\n".
        "--PART_BOUNDARY\r\n".
        "Content-Type: text/csv;\r\n\r\n".
        "--PART_BOUNDARY--\r\n";

I am sending this information to Google’s servers using a POST request with the convert=true parameter, but it results in a conversion failure. Additionally, I tried using ‘application/vnd.oasis.opendocument.spreadsheet’ for the content type without the convert parameter, but that results in an internal error instead.

Can someone guide me on the proper way to create an empty spreadsheet using this API?

That Google Docs API is deprecated - don’t use it for spreadsheets anymore. I hit the same wall last year on a project. The multipart requests constantly break because Google’s picky about content boundaries and headers, and getting those right with the old API is a nightmare. That convert=true parameter especially hates empty content. Just switch to Google Sheets API v4. Way easier - you can spin up a blank spreadsheet with a basic JSON request to the spreadsheets endpoint. Auth is cleaner, error messages actually help, and the docs don’t suck. You’ll save yourself hours of debugging.

hey alice, u should really switch to the sheets api v4. its way simpler for creating a spreadsheet. just use the spreadsheets.create method and skip all that boundary/xml stuff. good luck!

You’re hitting this issue because you’re trying to create an empty spreadsheet using the deprecated Google Docs API. I ran into the same problem with a legacy system - Google’s conversion process needs actual data to work with. When you send empty content, it just fails. Your multipart boundary formatting is fine. The real problem is Google can’t convert nothing into a spreadsheet. Try adding a simple header row like “Column1,Column2” to your CSV - that might fix the conversion error. But honestly, you’re setting yourself up for more headaches. The Google Docs API for spreadsheets is officially deprecated. Those auth tokens and endpoints could stop working anytime without warning, and then your app’s broken.