sendgrid-nodejs: 403 access forbidden

Issue Summary

I am trying to add a Single Recipient to sendgrid following these instructions: https://sendgrid.com/docs/API_Reference/Web_API_v3/Marketing_Campaigns/contactdb.html#Add-Single-Recipient-POST But when I try to hit that endpoint I receive 403 access forbidden

{
  "message": "FORBIDDEN",
  "code": 403,
  "response": {
    "headers": {
      "server": "nginx",
      "date": "Tue, 30 Jul 2019 00:31:22 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": "2",
      "x-ratelimit-limit": "3",
      "x-ratelimit-reset": "1564446684"
    },
    "body": {
      "errors": [
        {
          "field": null,
          "message": "access forbidden"
        }
      ]
    }
  }
}

I am already using the @sendgrid/mail and I have no problem with that.

Steps to Reproduce

I am trying to call the API endpoint from a serverless function

sendgridClient.setApiKey(tokens.SEND_GRID)

My API key has full access

exports.saveContact = functions.https.onRequest(async (req, res) => {
  cors(req, res, async () => {
    const { email } = req.body
    const request = {}
    request.body = [{ email }]
    request.method = 'POST'
    request.url = '/v3/contactdb/recipients'

    try {
      const [response] = await sendgridClient.request(request)
      res.status(200).send(response)
    } catch (error) {
      res.status(500).send(error)
    }
  })
})

Technical details:

  • sendgrid-nodejs Version: 6.4.0
  • Node.js Version: 11.15.0

PS: I have a Blaze pay as you go plan with firebase and cloud functions

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 36 (5 by maintainers)

Most upvoted comments

@wcandillon Thanks for the code snippet. I just got a response from SendGrid support that confirms that this is the correct endpoint to use. Response below:

POST /v3/contactdb/recipients is an endpoint associated with our Legacy Marketing Campaigns product. I’m able to see on our backend that your account does not have access to due to it the Legacy experience, having been created after the launch of the New Marketing Campaigns Experience. I feel this is the most likely source of the unexpected error.

In this case the PUT /marketing/contacts call will be the equivalent call for the New Marketing Campaigns experience. https://sendgrid.api-docs.io/v3.0/contacts/add-or-update-a-contact

I was able to use this endpoint successfully.

Hey @alfredoreduarte @mbosek

I’m a product manager at SendGrid, though I don’t own this part of the product.

I checked it out and am similarly unable to get a PUT to work either with the example or based on the field requirements in the doc. I’m following up with the PM/Team who owns this part of the product to see what’s up and will circle back with you here once I know more.

Me to, I feel like my code should work, bit I just keep getting a 403 when sending an email with node.