Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a row to Google Spreadsheet via cURL - required fields errors

So the docs here say very plainly that POSTing XML to the list feed url for the sheet with the field names in the format of this XML will insert a new row.

Auth is working and authorized account can access sheet. All those errors are resolved.

So when I post to https://spreadsheets.google.com/feeds/list/key/mySheetIDHere/private/full without I get

"The posted entry is missing one or more of the required field(s): title"

So I added <title></title> in addition to the previously existing <gsx:Title></gsx:Title> and that goes away but is replaced by

"The posted entry is missing one or more of the required field(s): rowCount"

So I tried adding an int that is the current row count but that error persists.

Current XML is below

<entry xmlns="http://www.w3.org/2005/Atom"
    xmlns:gsx="http://schemas.google.com/spreadsheets/2006/extended">
  <title>A Title</title>
  <rowCount>3</rowCount>
  <gsx:Title>A Title</gsx:Title>
  <gsx:Name>A Name</gsx:Name>
  <gsx:Email>An email</gsx:Email>
  <gsx:Phone>A phone</gsx:Phone>
</entry>

The docs say nothing about required fields or row counts. Anyone know what I am doing wrong?

like image 829
jerrygarciuh Avatar asked Feb 13 '15 20:02

jerrygarciuh


2 Answers

Got it working, here's a Gist with all of my scripts. From your URL, it looks like you might be POSTing to the add a worksheet endpoint instead of the add a list row endpoint. The worksheet endpoint expects title and rowCount like you're seeing. What you want is a URL that looks like

https://spreadsheets.google.com/feeds/list/$spreadsheet_id/$worksheet_id/private/full

I set up a spreadsheet to test with three columns:

  • Fruit
  • Color
  • Size

I seeded it (hah!) with Apple, Red, Medium as I tested auth and reading, then added Orange, Orange, Medium with this cURL command:

curl \
  --header "Authorization: GoogleLogin auth=$auth" \
  --header 'Content-Type: application/atom+xml' \
  -d @data.xml \
  -X POST \
  "https://spreadsheets.google.com/feeds/list/$spreadsheet_id/$worksheet_id/private/full"

Where:

  • $auth is my Google auth token obtained from https://www.google.com/accounts/ClientLogin
  • $spreadsheet_id is the ID visible in the URL or obtained from https://spreadsheets.google.com/feeds/spreadsheets/private/full
  • $worksheet_idis the worksheet (one sheet/tab inside the whole document) obtained from https://spreadsheets.google.com/feeds/worksheets/$spreadsheet_id/private/full. I didn't see anywhere visible in the UI I could get the worksheet ID.

and data.xml looks like this:

<entry xmlns="http://www.w3.org/2005/Atom"
    xmlns:gsx="http://schemas.google.com/spreadsheets/2006/extended">
  <gsx:fruit>Orange</gsx:fruit>
  <gsx:color>Orange</gsx:color>
  <gsx:size>Medium</gsx:size>
</entry>

I noticed that the columns have all been lowercased - I'm not sure if that matters. I also noticed there are title and content tags when I fetch the rows, in addition to the structured elements, but that title was a red herring for the title error you're seeing.

<!-- GET https://spreadsheets.google.com/feeds/list/$spreadsheet_id/$worksheet_id/private/full -->
<!-- snip -->
  <title type="text">Apple</title>
  <content type="text">color: Red, size: Medium</content>
  <gsx:fruit>Apple</gsx:fruit>
  <gsx:color>Red</gsx:color>
  <gsx:size>Medium</gsx:size>
<!-- snip -->
like image 146
Kristján Avatar answered Sep 21 '22 12:09

Kristján


I was simply using the wrong URL - instead of referencing the List feed link element with rel="http://schemas.google.com/g/2005#post", I was referencing the Worksheet feed, which has also has a link element with the same rel but a different href.

From what I gather, the list feed URL and the list feed POST URL are the same, which is where the confusion began for me.

like image 28
Ruby_Pry Avatar answered Sep 19 '22 12:09

Ruby_Pry