sendgrid / sendgrid-ruby

The Official Twilio SendGrid Led, Community Driven Ruby API Library
https://sendgrid.com
MIT License
625 stars 322 forks source link

Sending with a batch_id does not seem to work #433

Closed shelmire closed 4 years ago

shelmire commented 4 years ago

Issue Summary

batch_id seems to be ignored when used as described in documentation and example: https://github.com/sendgrid/sendgrid-ruby/blob/master/USAGE.md#v3-mail-send and https://github.com/sendgrid/sendgrid-ruby/blob/master/examples/mail/mail.rb#L50

Steps to Reproduce

  1. Create a batch id:

    sg = SendGrid::API.new(api_key: 'redacted')
    response = sg.client.mail.batch.post()
    batch_id = JSON.parse(response.body)['batch_id']
  2. Send a message with the batch_id

    
    data = {"personalizations"=>[{"to"=>[{"email"=>"myemail@mydomain.com"}], "subject"=>"Anything)"}], "from"=>{"email"=>"anotheremail@anotherdomain.com"}, "content"=>[{"type"=>"text/plain", "value"=>"This is a message"}], "batch_id"=>batch_id, "categories"=>["Category"], "custom_args"=>{"BATCH_ID"=> batch_id}, "send_at"=>unix_timestamp}

response = sg.client.mail._('send').post(request_body: data)

I'm passing in the custom_args so that I get the batch_id back to our webhook. send_at should be some future time. The message sends successfully at the correct time.

3. The problem is that the batch_id is being ignored - it doesn't show up in the web app when viewing it. When I try to cancel the batch, it doesn't cancel, and when I try to get the scheduled send, I get an empty array as the return body. Neither of the below work as expected.

```ruby
response = sg.client.user.scheduled_sends._('redacted').get()
puts response.status_code
puts response.body
puts response.headers

data = JSON.parse('{
  "batch_id": "redacted",
  "status": "cancel"
}')
response = sg.client.user.scheduled_sends.post(request_body: data)
puts response.status_code
puts response.body
puts response.headers

Technical details:

shelmire commented 4 years ago

Note that using curl as described here doesn't help either:

https://sendgrid.com/docs/for-developers/sending-email/curl-examples/

Could this be a permissions issue with the API token? I'd expect an API to respond with some sort of error if permission was denied.

Maybe I need to allow more time for the send_at?

shelmire commented 4 years ago

The send does seem to cancel correctly if send_at is set far enough out (10 minutes?). Still weird that it just gives an ok with no body as a response, same for the get. Closing.