pscott-au / WebService-GoogleAPI-Client

Perl WebService::GoogleAPI::Client Module
https://pscott-au.github.io/WebService-GoogleAPI-Client/
Other
1 stars 2 forks source link

Sheets API Discovery Error makes update tedious #11

Open pscott-au opened 6 years ago

pscott-au commented 6 years ago

Describe the bug When attempting to update a spreadsheet using sheets.spreadsheets.values.update API End-Point , the discovery spec specifies the valueInputOption parameter location as 'query' when the service actually requires this to be 'path'.

IE - the V4 discovery spec describes the parameter as follows: valueInputOption description 'How the input data should be interpreted.' type 'string' location 'query'

To Reproduce

my $res = $gapi_client->api_query( {
    api_endpoint_id => 'drive.files.create',
    options => {name => 'test', mimeType => 'application/vnd.google-apps.spreadsheet'}
  } )->json;

my $id = $res->{id};
my $range = 'A1:B2';

my $res = $gapi_client->api_query( {
    api_endpoint_id => 'sheets.spreadsheets.values.update',
    options => {
      spreadsheetId => $id,
      valueInputOption => 'RAW',
      range => $range,
      majorDimension => 'ROWS',
      values => [ [ qw/ hi there/ ], [ qw/ pi squared / ] ]
    }
  }
)->json;

dd $res; 

This should work, but gets an error from Google saying that it doesn't know the key value_input_option.

WORKING (but not satisfying)

my $res = $gapi_client->api_query( {
    api_endpoint_id => 'drive.files.create',
    options => {name => 'test', mimeType => 'application/vnd.google-apps.spreadsheet'}
  } )->json;

my $id = $res->{id};
my $range = 'A1:B2';

my $res = $gapi_client->api_query( {
    path => "https://sheets.googleapis.com/v4/spreadsheets/$id/values/$range?valueInputOption=RAW",
    method => "PUT",
    options => {
      majorDimension => 'ROWS', 
      values => [ [ 'hi', 'there' ], [ 'pi', 'squared'] ],
      range => $range 
  }
}
)->json;

This works, but is waaaaay too manual.

Expected behavior Where the API spec is incorrect - there should be a way to override parts of the spec to allow proper calling without reverting to a fully manually constructed request.

pscott-au commented 6 years ago

I am looking at allowing a callback to be passed into the Client->api_query() method to expose the method discovery structure and allow it to be modified by the user.

pscott-au commented 6 years ago

I believe this is solved for now by https://github.com/pscott-au/WebService-GoogleAPI-Client/commit/5c67d16a975a9852a5f28f999bdc800fe95b26e8 but will leave this issue open as there may be a broader requirement to handle similar cases that requires a more robust approach.