Reputation: 301
I'm having troubles sending a draft in Gmail through their API and the documentation doesn't help very much, especially since I'm working with Ruby.
I can create a draft without any issue, but then when I try to send the newly created draft, I get an error saying:
ArgumentError (wrong number of arguments (0 for 1))
The involved code is as follows:
@gmail = client.discovered_api('gmail', 'v1')
@send_result = client.execute(
:api_method => @gmail.users.drafts.send,
:parameters => { 'userId' => 'me' },
:body_object => { 'id' => '<message_id>' }
)
Taking a look at the debugger, the error seems to appear because of this:
@gmail.users.drafts.send
What am I missing here? I haven't seen anywhere that I should be passing parameters into the api_method? Also where can I find where this is documented and what is the parameter supposed to be?
Thanks!
Upvotes: 0
Views: 152
Reputation: 2415
The question is pretty old at this point, but I just ran into the same problem and figured it's better to answer late than never.
@gmail.users.drafts.send
is colliding with Ruby's Object#send. You can work around the collision by converting the Google::APIClient::Resource
item to a hash and then reading the value by key:
:api_method => @gmail.users.drafts.to_h["gmail.users.drafts.send"]
Your example, including the workaround:
@gmail = client.discovered_api('gmail', 'v1')
@send_result = client.execute(
:api_method => @gmail.users.drafts.to_h["gmail.users.drafts.send"],
:parameters => { 'userId' => 'me' },
:body_object => { 'id' => '<message_id>' }
)
I hope that helps!
Upvotes: 1
Reputation: 7159
I'm just going off of: https://developers.google.com/gmail/api/v1/reference/users/drafts/send
But I think you have it right. The userId should be a parameter (e.g. in the URL) and the draft ID should be in the (POST) body. Can you confirm you're actually providing a draft ID and not the message.id?
Are you able to get an HTTP trace of the actual request, that would help immensely (you should likely be able to set this on the client or underlying http library your client uses, etc).
Upvotes: 0