sendgrid / sendgrid-ruby

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

Senders - 403 Access Forbidden #424

Closed evangallup closed 4 years ago

evangallup commented 4 years ago

Issue Summary

Using the same code from your examples section, I am unable to create a sender identity through this library.

Steps to Reproduce

  1. Installed sendgrid-ruby gem
  2. Run code below with my own API key pasted in instead of ENV['SENDGRID_API_KEY'] (note: I also tried to adjust the email, address, etc. but I get the same response with the info below). It's also worth noting, I attempted to generate and use multiple API keys, but still received the same response.

Code Snippet

require 'sendgrid-ruby'

sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])

##################################################
# Create a Sender Identity #
# POST /senders #

data = JSON.parse('{
  "address": "123 Elm St.", 
  "address_2": "Apt. 456", 
  "city": "Denver", 
  "country": "United States", 
  "from": {
    "email": "from@example.com", 
    "name": "Example INC"
  }, 
  "nickname": "My Sender ID", 
  "reply_to": {
    "email": "replyto@example.com", 
    "name": "Example INC"
  }, 
  "state": "Colorado", 
  "zip": "80202"
}')
response = sg.client.senders.post(request_body: data)
puts response.status_code
puts response.body
puts response.headers

Exception/Log

403
{"errors":[{"field":null,"message":"access forbidden"}]}
{"server"=>["nginx"], "date"=>["Tue, 19 May 2020 14:40:00 GMT"], "content-type"=>["application/json"], "content-length"=>["56"], "connection"=>["close"], "access-control-allow-methods"=>["HEAD, GET, PUT, POST, DELETE, OPTIONS, PATCH"], "access-control-max-age"=>["21600"], "access-control-expose-headers"=>["Link, Location"], "access-control-allow-origin"=>["*"], "access-control-allow-headers"=>["AUTHORIZATION, Content-Type, On-behalf-of, x-sg-elas-acl, X-Recaptcha, X-Request-Source"], "content-security-policy"=>["default-src https://api.sendgrid.com; frame-src 'none'; object-src 'none'"], "x-content-type-options"=>["nosniff"], "strict-transport-security"=>["max-age=31536000"], "x-ratelimit-remaining"=>["599"], "x-ratelimit-limit"=>["600"], "x-ratelimit-reset"=>["1589899260"]}

Technical details:

jsalik commented 3 years ago

Same issue here, @egallup02360 did you manage to fix it?

evangallup commented 3 years ago

Same issue here, @egallup02360 did you manage to fix it?

I believe this endpoint is attempting to use some sort of marketing feature and I didn't have it configured or have access to it (free plan). 'Create a Sender Identity' wasn't what I wanted to do to allow emails to be sent from a certain address.

I could be misremembering this though. May feels like so long ago now. Hope this helps!

dgavey commented 3 years ago

Looks to me like the API updated to use verified_senders instead of senders testing the GET with that worked Ex: sg.client.verified_senders.get() however sg.client.senders.get() gave me a 403.