I’m trying to make an empty spreadsheet with the Google Docs API. But I keep getting an error that says ‘could not convert document’. Here’s what I’ve tried:
$spreadsheet_data = "--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>$sheet_name</title>
</entry>\r\n" .
"--BOUNDARY\r\n" .
"Content-Type: text/csv;\r\n\r\n" .
"--BOUNDARY--\r\n";
I’m sending this to Google’s server with a POST request and the ‘convert=true’ parameter. I also tried using ‘application/vnd.oasis.opendocument.spreadsheet’ instead of ‘text/csv’ and removing ‘convert=true’, but that gave me an internal error. Any ideas what I’m doing wrong?
I’ve encountered similar issues when attempting to create a blank spreadsheet. In my experience, switching from the older Google Docs API approach to the newer Google Sheets API v4 helped a lot. Rather than juggling with Atom XML and boundary content issues, I found that issuing a POST request directly to https://sheets.googleapis.com/v4/spreadsheets with an OAuth 2.0 authorization header simplified the process. Using a straightforward JSON body with just the title enabled the API to generate the spreadsheet without conversion errors. Checking that the proper OAuth scopes are enabled further ensured a smoother execution.
Based on my experience, the Google Docs API you’re using is outdated for creating spreadsheets. I’d recommend switching to the Google Sheets API v4, which is specifically designed for spreadsheet operations. With this API, you can create a blank spreadsheet using a simple POST request to ‘https://sheets.googleapis.com/v4/spreadsheets’ with a JSON body containing just the title. Make sure you’ve set up proper OAuth 2.0 authentication and enabled the necessary API scopes in your Google Cloud Console. This approach should resolve the conversion errors you’re encountering and streamline your spreadsheet creation process significantly.
hey ryan, have u tried using the sheets API instead? it’s way easier for making spreadsheets. just send a POST to https://sheets.googleapis.com/v4/spreadsheets with a JSON body that has the title. make sure u got the right OAuth stuff set up tho. that should fix ur conversion problem