5

I am trying to find all the freebusy times from my primary calendar, but I cannot get the query to recognize my parameters.

In my controller I have:

@freetimes = client.execute(
  :api_method => service.freebusy.query,
  :parameters => {
  'timeMin' => '2013-06-15T17:06:02.000Z',
  'timeMax' => '2013-06-29T17:06:02.000Z',
  'items' => [{'id' => 'myemail@gmail.com'}]
  },
  :headers => {'Content-Type' => 'application/json'})

the response I get is:

 --- !ruby/object:Google::APIClient::Schema::Calendar::V3::FreeBusyResponse
data:
error:
    errors:
    - domain: global
      reason: required
      message: Missing timeMin parameter.
    code: 400
    message: Missing timeMin parameter.

However is shows that it took the parameters, but they did not get attached to the query:

--- !ruby/object:Google::APIClient::Result
request: !ruby/object:Google::APIClient::Request
  parameters:
  timeMin: '2013-06-15T17:06:02.000Z'
  timeMax: '2013-06-29T17:06:02.000Z'
  items:
   - id: myemail@gmail.com

Any help solving this would be greatly appreciated!

Nazik
  • 8,696
  • 27
  • 77
  • 123
Tristan Toye
  • 85
  • 1
  • 10
  • I have solved it, based on the response found [here][1] The hash needed to be turned into JSON to pass correctly unlike other Calendar methods. [1]:http://stackoverflow.com/questions/7455744/post-json-to-api-using-rails-and-httparty – Tristan Toye Jun 18 '13 at 14:43

2 Answers2

7

solved this by specifying the request body

client.execute(
  :api_method => service.freebusy.query,
  :body => JSON.dump({
    :timeMin => ,
    :timeMax => ,
    :items => 
  }),
  :headers => {'Content-Type' => 'application/json'})
user3330504
  • 86
  • 1
  • 2
3

I was having a similar problem. An alternative, is that you can build a FreeBusyRequest object.
Like this:

 body = Google::Apis::CalendarV3::FreeBusyRequest.new 
 body.items = [calendar_id]
 body.time_min = "2016-06-29T13:00:00z"
 body.time_max = "2016-06-29T21:00:00z"
 body

``` and then you can pass it into a CalendarService object like this:

service = Google::Apis::CalendarV3::CalendarService.new
service.authorization = client
service.query_freebusy(body)

this will definitely return a status 200 response with a body.