sendgrid-ruby icon indicating copy to clipboard operation
sendgrid-ruby copied to clipboard

Adding multiple Unique Arguments (Custom Args) using the V3 API

Open pwgustafson opened this issue 10 years ago • 10 comments

Issue

I've been trying to add multiple custom args to a single personalization, but getting an ambiguous error response.

Steps to reproduce

mail = Mail.new
personalization = Personalization.new
personalization.custom_args = CustomArg.new(key: 'email_type', value: 'welcome')
personalization.custom_args = CustomArg.new(key: 'user_id', value: user.id)
personalization.custom_args = CustomArg.new(key: 'env', value: Rails.env)

mail.personalizations = personalization

{"errors":[{"message":"Bad Request","field":null,"help":null}]}

  • sendgrid-ruby Version: 4.0.6
  • Ruby Version: 2.3.1

pwgustafson avatar Nov 23 '16 03:11 pwgustafson

UPDATE:

I figured out what was happening; This line:

personalization.custom_args = CustomArg.new(key: 'user_id', value: user.id)

was causing issues, until I changed it to:

personalization.custom_args = CustomArg.new(key: 'user_id', value: user.id.to_s)

Maybe ill open a PR for this issue.

Thanks!

pwgustafson avatar Nov 23 '16 21:11 pwgustafson

Hi @pwgustafson,

Thanks for sharing the fix! Did you still want to open the issue? If not, I'll go ahead and do that.

thinkingserious avatar Nov 29 '16 02:11 thinkingserious

Actually, I'll just use this issue as reference and add this to our backlog. Thanks!

Also, for providing the fix, we'd like to offer you some swag. Please fill out this form and we'll get you set up. Thanks!

thinkingserious avatar Nov 29 '16 02:11 thinkingserious

Thanks @thinkingserious

I will try to open a PR with a fix once I have some free time - Appreciate the swag!

👕 👍

pwgustafson avatar Nov 29 '16 04:11 pwgustafson

Awesome, a PR would be great!

thinkingserious avatar Nov 29 '16 04:11 thinkingserious

@pwgustafson unrelated but how do you leverage these custom args ? Where do they show up in Sendgrid?

scalp42 avatar Jan 02 '17 06:01 scalp42

@scalp42,

Please check out the documentation here: https://sendgrid.com/docs/API_Reference/SMTP_API/unique_arguments.html

While that describes the SMTP API functionality, the same functionality holds true for v3.

Thanks!

thinkingserious avatar Jan 26 '17 17:01 thinkingserious

@scalp42 I don't actually use them in sendgrid, I use them in the webhook callbacks to update specific details for delivered & click events.

pwgustafson avatar Jan 26 '17 17:01 pwgustafson

👋 is this still a relevant issue? Looks like the original unhappy path isn't relevant now that the method add_custom_arg is implemented as well as this change here in CustomArgs: https://github.com/sendgrid/sendgrid-ruby/blob/master/lib/sendgrid/helpers/mail/custom_arg.rb#L7

scottcrawford03 avatar Oct 26 '18 14:10 scottcrawford03

Since there has been no activity on this issue since March 1, 2020, we are closing this issue. Please feel free to reopen or create a new issue if you still require assistance. Thank you!

thinkingserious avatar Mar 11 '21 02:03 thinkingserious