Search code examples
node.jssendgrid

SendGrid 403 Response for /v3/contactdb/recipients - Permissons needed


What permissions do I need or what am I doing wrong with this SendGrid API call?

I'm trying to post a new recipient ( /contactdb/recipients ) to Send Grid but keep getting a 403 response:

I get this even when calling the API from the SendGrid Explorer

Contacts API - Recipients

  • POST -> Add recipients
{
  "errors": [
    {
      "field": null,
      "message": "access forbidden"
    }
  ]
}

This makes me think that my API Key doesn't have enough permissions but it has Full Access.

Here is my client code as well.

require("dotenv").config();
const client = require("@sendgrid/client");

exports.handler = function(event, context, callback) {
  const body = JSON.parse(event.body);
  const email = body.email;

  if (!process.env.SENDGRID_API_KEY) {
    callback("No API Key");
  }

  client.setApiKey(process.env.SENDGRID_API_KEY);
  const request = {
    method: "POST",
    url: "/v3/contactdb/recipients",
    body: JSON.stringify([{ email }])
  };

  client
    .request(request)
    .then(([response, body]) => {
      // console.log(response.statusCode);
      // console.log(body);
      callback(null, response, body);
    })
    .catch(error => {
      // console.log(JSON.stringify(error.response.body.errors));
      callback(error);
    });

};

Solution

  • Per support:

    We have just very recently released a "New Marketing Campaigns" experience and the endpoints have changed from our "Legacy Marketing Campaigns".

    Try this endpoint:

    https://api.sendgrid.com/v3/marketing/contacts

    I pulled it from our documentation here:

    https://sendgrid.api-docs.io/v3.0/contacts/add-or-update-a-contact