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

403 access forbidden

Open MatteoGioioso opened this issue 7 years ago β€’ 36 comments

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

MatteoGioioso avatar Jul 30 '19 01:07 MatteoGioioso

Any update on this?

MatteoGioioso avatar Aug 07 '19 00:08 MatteoGioioso

at the moment I am unable to save contacts, any help?

MatteoGioioso avatar Aug 13 '19 03:08 MatteoGioioso

same problem

rafaelvicio avatar Aug 21 '19 17:08 rafaelvicio

From what I've verified, this is because our account is on the free plan, which doesn't allow us to use this API.

rafaelvicio avatar Aug 25 '19 02:08 rafaelvicio

I am a paying customer and am getting a 403 on this endpoint:

/v3/contactdb/lists/{id}/recipients

any suggestions?

JClackett avatar Sep 17 '19 12:09 JClackett

I am also suffering from the same issue. My API key is unrestricted and I am on the free plan. @JClackett seems to suggest that upgrading to the paid tier won't solve the issue.

wcandillon avatar Sep 22 '19 05:09 wcandillon

Same issue here for the endpoint v3/contactdb/recipients. I tried created a new API key with full access, and still no luck. This is on the paid "Pro" plan. I have no issue sending mail with the same key. This really seems like a bug on SendGrid side.

ZenPylon avatar Sep 24 '19 16:09 ZenPylon

I haven't tried it yet but their support seemed to suggest to do a PUT instead of a POST?

wcandillon avatar Sep 24 '19 16:09 wcandillon

Thanks for the suggestion - just tried that, but no luck. πŸ˜•

ZenPylon avatar Sep 24 '19 20:09 ZenPylon

I was able to create contacts using the straight API and "Try It Out" feature, so the backend seems to be working as expected.

Contacts API - Recipients https://sendgrid.api-docs.io/v3.0/contacts-api-recipients

On Tue, Sep 24, 2019 at 2:02 PM Andrew Decker [email protected] wrote:

Thanks for the suggestion - just tried that, but no luck. πŸ˜•

β€” You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/sendgrid/sendgrid-nodejs/issues/957?email_source=notifications&email_token=AARP5MW4NQ6KFDDWJE2F7A3QLJW4DA5CNFSM4IHXNHK2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD7PT7JY#issuecomment-534724519, or mute the thread https://github.com/notifications/unsubscribe-auth/AARP5MX5PBM7KL7JHKUUYBDQLJW4DANCNFSM4IHXNHKQ .

aroach avatar Sep 24 '19 22:09 aroach

Thanks for your comment, @aroach. Perhaps the issue lies in the way API keys are being provisioned? The API key I'm using has "Full Access", so if the endpoint itself is working, then there must be something wrong with the key.

ZenPylon avatar Sep 25 '19 00:09 ZenPylon

We’re you able to succeed using the try it out with the same API key? On Sep 24, 2019, 6:30 PM -0600, Andrew Decker [email protected], wrote:

Thanks for your comment, @aroach. Perhaps the issue lies in the way API keys are being provisioned? The API key I'm using has "Full Access", so if the endpoint itself is working, then there must be something wrong with the key. β€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

aroach avatar Sep 25 '19 00:09 aroach

It unfortunately gives the same 403.

ZenPylon avatar Sep 25 '19 00:09 ZenPylon

I was wondering if perhaps because the API key I created a while ago, maybe something had changed with API keys. But, I created a fresh one and it still worked for me.

Perhaps triple check your API key permissions. I was able to get it to 403 by disabling the Marketing Campaigns scope.

On Tue, Sep 24, 2019 at 6:45 PM Andrew Decker [email protected] wrote:

It unfortunately gives the same 403.

β€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sendgrid/sendgrid-nodejs/issues/957?email_source=notifications&email_token=AARP5MUIB6UFN6WXDF3G2OTQLKYD7A5CNFSM4IHXNHK2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD7QHCKY#issuecomment-534802731, or mute the thread https://github.com/notifications/unsubscribe-auth/AARP5MVDNGXY3AETAFQDRODQLKYD7ANCNFSM4IHXNHKQ .

aroach avatar Sep 25 '19 00:09 aroach

Maybe @thinkingserious or @ben-grid have some thoughts here.

aroach avatar Sep 25 '19 01:09 aroach

Thanks for your persistence. I created a new key in both our staging and production SendGrid accounts with full access, but the 403 error persists in the "Try it Out" section for both. Hoping one of the others you've brought to the conversation might be able to help. πŸ™

ZenPylon avatar Sep 25 '19 01:09 ZenPylon

I remember I have created a separated key just to call that endpoint and a new one with full access to temporarily test that issue, but still did not work.

MatteoGioioso avatar Sep 25 '19 02:09 MatteoGioioso

This the request that I am doing now:

  const request = {
    method: "PUT",
    url: "/v3/marketing/contacts",
    body: {
      contacts: [
        {
          email
        }
      ]
    }
  };
  await client.request(request);

wcandillon avatar Sep 26 '19 05:09 wcandillon

@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.

ZenPylon avatar Sep 26 '19 16:09 ZenPylon

Hi, I've tried the default example given at https://sendgrid.api-docs.io/v3.0/contacts/add-or-update-a-contact with a fresh API key and all I'm getting is "invalid JSON", even though the JSON payload hasn't been edited, it's just the default example.

Screen Shot 2019-11-21 at 11 43 23 PM

Anyone else going through this?

alfredoreduarte avatar Nov 22 '19 02:11 alfredoreduarte