Adding multiple Unique Arguments (Custom Args) using the V3 API
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
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!
Hi @pwgustafson,
Thanks for sharing the fix! Did you still want to open the issue? If not, I'll go ahead and do that.
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!
Thanks @thinkingserious
I will try to open a PR with a fix once I have some free time - Appreciate the swag!
👕 👍
Awesome, a PR would be great!
@pwgustafson unrelated but how do you leverage these custom args ? Where do they show up in Sendgrid?
@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!
@scalp42 I don't actually use them in sendgrid, I use them in the webhook callbacks to update specific details for delivered & click events.
👋 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
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!