Sheets API access with PHP part 2: Editing Rows

row-xml-previewMy previous Sheets API post demonstrated how to add rows to Google Sheets with PHP.  Some readers were interested in editing or deleting rows.

Google has a very informative reference here that describes the list-based feed for manipulating sheets.  All of my scripts have been using this method, which requires the sheet to have a single header row (I’d been lucky to use that format without knowing the requirement).  I use the example HTTP code from Google’s reference pages to give me guidance for my PHP.

I’ve added a file to the gist demonstrating how to edit a row.  Here’s what you need to know:

  1. When you get the sheet list feed (Section 3 of the first file in the gist), you need to add a header (“GData-Version” => “3.0”) to the GET request so that the Etag is returned for each line.
  2. Once you have a list of entries and find the one that you want to edit, you need to grab its Etag, Id, and the edit URL (see lines 1, 2, and 9 in the image above, and click on the image to see the whole entry).
  3. Now you just need to issue a PUT request to the edit URL and include the XML with the Etag, Id, and updated sheet data.

Hope this helps a few people!

1 thought on “Sheets API access with PHP part 2: Editing Rows

  1. Pingback: Google Sheets API access with PHP - Karl's Place

Leave a Reply

Your email address will not be published. Required fields are marked *