0

I'm using the Google API Ruby client to do 4 things:

  1. Access my drive
  2. Create a new spreadsheet
  3. Update cells in the the spreadsheet
  4. Get cells with calculated results from same spreadsheet

I'm able to successfully achieve the first 3 items listed above, but arrive at a 503 error when attempting to fetch the cells. I am able to get cells from the spreadsheet if I DO NOT run the #batch_update_values method. The error only occurs when both functions are called sequentially, yet work when called individually.

In my service:

data = [list of ValueRange Objects]
request_body = Google::Apis::SheetsV4::BatchUpdateValuesRequest.new
request_body.value_input_option = "user_entered";
request_body.data = data;

# this works
@sheets_client.batch_update_values(working_copy.id, request_body)


# this does not work even with retries set
range = "Sheet2!A3:BN23"
response = @sheets_client.get_spreadsheet_values(working_copy.id, range, value_render_option: "UNFORMATTED_VALUE", date_time_render_option: "SERIAL_NUMBER")

The exact error is:

{"error": {
"cause": null,
"status_code": 503,
"header": {
  "Vary": "Referer",
  "Content-Type": "application/json; charset=UTF-8",
  "Content-Encoding": "gzip",
  "Date": "Tue, 04 Apr 2017 00:42:21 GMT",
  "Server": "ESF",
  "Cache-Control": "private",
  "X-Xss-Protection": "1; mode=block",
  "X-Frame-Options": "SAMEORIGIN",
  "Alt-Svc": "quic=\":443\"; ma=2592000; v=\"37,36,35\"",
  "Transfer-Encoding": "chunked"
},
"body": "{\n  \"error\": {\n    \"code\": 503,\n    \"message\": \"The service is currently unavailable.\",\n    \"errors\": [\n      {\n        \"message\": \"The service is currently unavailable.\",\n        \"domain\": \"global\",\n        \"reason\": \"backendError\"\n      }\n    ],\n    \"status\": \"UNAVAILABLE\"\n  }\n}\n"

} }

the update:

def generate_value_range_objects(data)
  value_range_objects = []
  data.each do |range, value|
    value_range_objects << Google::Apis::SheetsV4::ValueRange.new(major_dimension: "ROWS", values: [[value]], range: range)
  end
  value_range_objects
end

d = Hash.new
d["Sheet1!B5"] = "# Address"
d["Sheet1!B6"] = "# City/Town"
d["Sheet1!B7"] = "# County"
d["Sheet1!B8"] = "# State"
d["Sheet1!B9"] = "# Zip"

d["Sheet1!B11"] = "# Year Built"
d["Sheet1!B12"] = "# Year Gut Renovated"

d["Sheet1!B14"] =  "# Number of Residential Units"
d["Sheet1!B15"] =  "# Number of Commercial Units"
d["Sheet1!B17"] =  "# Number of Occupied Units Mo. X"
d["Sheet1!B18"] =  "# Number of Occupied Units Mo. X"
d["Sheet1!B19"] =  "# Number of Occupied Units Mo. X"

# Operating Numbers
# Something in here causing issue
d["Sheet1!B22"] = "# Income "
d["Sheet1!B23"] = "# Less Concessions"
d["Sheet1!B24"] = "# Vacancy"
d["Sheet1!B27"] = "# Income "
d["Sheet1!B28"] = "# Plus Income Other"
d["Sheet1!B35"] = "# Expense"
d["Sheet1!B36"] = "# Expense"
d["Sheet1!B37"] = "# Expense"
d["Sheet1!B38"] = "# Expense"
d["Sheet1!B39"] = "# Expense"
d["Sheet1!B40"] = "# Expense"
d["Sheet1!B41"] = "# Expense"


data = generate_value_range_objects(d)
request_body = Google::Apis::SheetsV4::BatchUpdateValuesRequest.new
request_body.value_input_option = "user_entered";
request_body.data = data;

@sheets_client.batch_update_values(working_copy.id, request_body)
yesyoukenn
  • 207
  • 4
  • 17
  • 1
    A 503 is an internal error in the spreadsheets service. Can you paste the smallest possible update you can apply that triggers the error on the get? If so, I can look I to what's going wrong. – Sam Berlin Apr 04 '17 at 01:40
  • @SamBerlin It's hard to show exactly what's causing the issue as it appears to occur with any # of updates to the sheet. It seems that when I update a cell with a certain value the get fails. – yesyoukenn Apr 04 '17 at 02:31
  • 1
    If it's not too large, can you paste the exact update you're doing (or if that's not possible & the data isn't private, the spreadsheet ID that you're seeing a 503 on)? If you can reproduce this 100% with create->update->get, then the update is causing some pathological internal failure. – Sam Berlin Apr 04 '17 at 02:35
  • @SamBerlin the data is a bit private and i've replaced it with strings, however, the spreadsheet id is 1K4nGpsq2SvbmbnNrLkhUvorZ-WwPZ3BgNduFU-xidxQ. To clarify, I use Google Drive API to create a copy an existing spread sheet (i.e. master spreadsheet), then batch-update the spreadsheet, and then get values from another worksheet in the same spreadsheet – yesyoukenn Apr 04 '17 at 02:53
  • 1
    Ok thanks, will try to repro & report back here w/ results. – Sam Berlin Apr 04 '17 at 02:56
  • @SamBerlin it appears that the batch update is causing an error in the sheet which subsequently doesn't allow me to get any values even though the sheet appears fine in Drive itself. I discovered this by looking at the revision history of the sheet and noticed that the only revisions listed show me an error page. – yesyoukenn Apr 04 '17 at 19:54
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/139899/discussion-between-yesyoukenn-and-sam-berlin). – yesyoukenn Apr 04 '17 at 19:59

0 Answers0