sendgrid / sendgrid-ruby

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

<%asm_global_unsubscribe_raw_url%> will not be replaced #420

Closed fogonthedowns closed 4 years ago

fogonthedowns commented 4 years ago

The unsubscribe link includes a link to <%asm_global_unsubscribe_raw_url%> which will not be replaced. The guides online are totally incomplete and I have spent hours trying to determine how to fix this. Moreover, this is required.

Issue Summary

This is a blocking issue.

Steps to Reproduce

  1. I use the code below
  2. I send an email
  3. I see a href linking http://<%asm_global_unsubscribe_raw_url%>
  4. I expect users to be able to unsubscribe.

    Code Snippet

      @token = token
      token_url = ENV['ENV_URI'] + "/users/confirmation?confirmation_token=" + record.confirmation_token
      data = JSON.parse('{
        "template_id": "d-000682d7c4274b5a92c7fe9fa33d04d4",
        "asm_group_id": 17454,
        "asm_groups_to_display": [17454],
        "personalizations": [
        {
          "to": [
            {
              "email": "'+record.email+'"
            }
          ],
          "subject": "Welcome to JZ! Confirm Your Email",
          "dynamic_template_data": {
              "token": "'+token_url+'",
              "Sender_Address": "181 Foo St",
              "Sender_City" : "SF",
              "Sender_State" : "CA",
              "Sender_Zip": "90210"
            }
          }
        ],
        "from": {
          "email": "foo@bar.io"
        },
        "content": [
          {
            "type": "text/html",
            "value": "'+record.confirmation_token+'"
          }
        ],
        "substitutions": {
              "Sender_Name": "support@foo.bar",
              "Sender_Address": "181 Foo St",
              "Sender_City" : "SF",
              "Sender_State" : "CA",
              "Sender_Zip": "90210"
         }
      }')
    
      sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
      begin
          response = sg.client.mail._("send").post(request_body: data)

Exception/Log

# paste exception/log here

Technical details:

fogonthedowns commented 4 years ago

THE CORRECT WAY TO DO THIS:

"asm": {"group_id":17454,"groups_to_display":[17454]},

is undocumented. YOUR DOCS ARE TERRIBLE

childish-sambino commented 4 years ago

Docs are here: https://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/index.html#-Request-Body-Parameters