Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

403 access forbidden #957

Closed
MatteoGioioso opened this issue Jul 30, 2019 · 36 comments
Closed

403 access forbidden #957

MatteoGioioso opened this issue Jul 30, 2019 · 36 comments
Labels
type: non-library issue API issue not solvable via the SDK

Comments

@MatteoGioioso
Copy link

MatteoGioioso commented Jul 30, 2019

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
Copy link
Author

Any update on this?

@MatteoGioioso
Copy link
Author

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

@rafaelvicio
Copy link

same problem

@rafaelvicio
Copy link

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

@JClackett
Copy link

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

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

any suggestions?

@wcandillon
Copy link

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.

@ZenPylon
Copy link

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.

@wcandillon
Copy link

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

@ZenPylon
Copy link

Thanks for the suggestion - just tried that, but no luck. 😕

@aroach
Copy link
Contributor

aroach commented Sep 24, 2019 via email

@ZenPylon
Copy link

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.

@aroach
Copy link
Contributor

aroach commented Sep 25, 2019 via email

@ZenPylon
Copy link

It unfortunately gives the same 403.

@aroach
Copy link
Contributor

aroach commented Sep 25, 2019 via email

@aroach
Copy link
Contributor

aroach commented Sep 25, 2019

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

@ZenPylon
Copy link

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

@MatteoGioioso
Copy link
Author

MatteoGioioso commented Sep 25, 2019

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.

@wcandillon
Copy link

This the request that I am doing now:

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

@ZenPylon
Copy link

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

@alfredoreduarte
Copy link

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?

@mbosek
Copy link

mbosek commented Nov 22, 2019

@alfredoreduarte I have the same

@ben-grid
Copy link

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.

@ben-grid
Copy link

@alfredoreduarte @mbosek

This is fixed now. We just had the tech powering our "Try it out" feature misconfigured so it wasn't consuming JSON properly. Works now!

Thanks for reporting the issue!

@alfredoreduarte
Copy link

Thanks! Now I'm able to add contacts. However, it's been like six hours since I successfully added one and it still isn't showing up on my list. I guess I'll report this by opening a different issue.

@alfredoreduarte
Copy link

@ben-grid turns out the /v3/marketing/contacts endpoint does not support an ID field for users, although the "try it out" tool includes that field as an example.

Please get someone to update the example :)

@alfredoreduarte
Copy link

This closes #1004

@ben-grid
Copy link

ben-grid commented Dec 2, 2019

@alfredoreduarte Ah yeah, good call, thanks. I just updated it, which will go out with our next deploy. Thanks for the heads up!

@childish-sambino childish-sambino added the type: non-library issue API issue not solvable via the SDK label Mar 3, 2020
@mrillstone
Copy link

still having this problem with POST mail/send feature in the API docs, any update?

@mavrick
Copy link

mavrick commented Apr 6, 2020

none of my contacts are updating or being added when using the /v3/marketing/contacts endpoint. it just returns a job_id and then nothing is ever updated when i check the dashboard.

attempted to use the contactdb/recipients endpoint and it just results in a 403 error.

@mavrick
Copy link

mavrick commented Apr 6, 2020

A follow up on this.

When using custom fields, if your field is set to text, you can only send text. Ensure your types match, otherwise it will enver update. Being unable to check the job_id or get any kind of field validation is the problem here

@Promessed
Copy link

I also have the same issue with POST mail/send feature in the API docs, any update? @ben-grid

@RobSwish
Copy link

RobSwish commented Apr 9, 2020

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

@childish-sambino
Copy link
Contributor

@RobSwish Could you provide a code sample that illustrates this issue and also the response body?

https://github.com/sendgrid/sendgrid-nodejs/blob/master/docs/use-cases/success-failure-errors.md

@tjoudeh
Copy link

tjoudeh commented Apr 9, 2020

Same happening with the C# SDK (NuGet SendGrid) too, this is what I'm using currently:

 var client = new SendGridClient(apiKey);
            var from = new EmailAddress(fromEmail, fromName);
            var to = new EmailAddress(email);

            var msg = MailHelper.CreateSingleEmail(from, to, subject, message, message);

            // Disable click tracking.
            // See https://sendgrid.com/docs/User_Guide/Settings/tracking.html
            //msg.SetClickTracking(false, false);

            var response = await client.SendEmailAsync(msg);

            return response;

@YJChan
Copy link

YJChan commented Apr 12, 2020

I'm able to do that by verify the sender email. Read this guide.
https://sendgrid.com/docs/for-developers/sending-email/sender-identity/
They need you to verify the sender email before you can send out anything. If you just want to test out the sending feature, you can try to use your personal email to setup first.
This step is a not included in the getting started guide which I think is not very user friendly.

@jayjonah8
Copy link

I am able to get a successful response and a job_id when I hit thehttps://api.sendgrid.com/v3/marketing/contacts end point but on my dashboard there are no contacts showing up. I have the correct list id but nothing seems to work

@sendgrid sendgrid locked as off-topic and limited conversation to collaborators Apr 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: non-library issue API issue not solvable via the SDK
Projects
None yet
Development

No branches or pull requests