Sendgrid-nodejs: Unable to add recipients - client is BROKEN for new API endpoints

Created on 25 Sep 2019  路  9Comments  路  Source: sendgrid/sendgrid-nodejs

Issue Summary

Hi. I'm trying to add recipients via the client using NodeJS. I'm being told by SendGrid level 2 support that the client doesn't support the API endpoints for the new marketing campaigns functionality. Also the old endpoints don't work either. So now it seems there is no way to add recipients.

Steps to Reproduce

  1. I tried using the steps here:
    https://github.com/sendgrid/sendgrid-nodejs/blob/master/packages/client/USAGE.md#add-recipients

That didn't work after going through a lot of pain. I reached out to SendGrid support who was initially also very confused. Then level 2 was able to discover that the new endpoints are not supported. I got this:

Thank you for reaching out, my name is Dustin, and I am part of the Tier 2 team here at SendGrid. I am very sorry to hear about your experience thus far with adding a contact over the API. It appears that you are trying to call our new Marketing Campaigns API. Unfortunately, our Code Libraries are not up-to-date to reflect these new endpoints. Additionally, the code that gets generated from the "Try It Out" section, is not valid code as well. I understand that that is not ideal at all and I do apologize about that.

Do you know when the client will be updated? In the meantime, I am trying to use Firebase Cloud Functions which is NodeJS based to add a recipient to SendGrid. Any ideas on how I can do this while the client is being updated?

It's rather tragic because the whole reason I chose SendGrid was because it is supposed to be the most developer friendly and API-advanced. And now a very basic piece of functionality is just unable to be accomplished via the NodeJS client. Any help would be really appreciated.

Another thing to note. Apparently the new endpoint and JSON is as follows:

PUT to https://api.sendgrid.com/v3/marketing/contacts
{
"contacts": [{
"email": "{email}",
"first_name": "{firstname}",
"last_name": "{lastname}"
}]
}

The old one that I think the client is using is:
POST to /contactdb/recipients

Obivously, this last endpoint is the one that support is saying is no longer supported.

Thanks!

Technical details:

  • sendgrid-nodejs Version: master (latest commit: [commit number])
  • Node.js Version: 4.1.2
question

Most helpful comment

The old and new APIs should work fine when using the client. Example using the new API:

const sgClient = require('@sendgrid/client');
sgClient.setApiKey(process.env.SENDGRID_API_KEY);

const data = {
    "contacts": [
        {
            "age": "25",
            "email": "[email protected]",
            "first_name": "",
            "last_name": "User"
        },
        {
            "age": "25",
            "email": "[email protected]",
            "first_name": "Example",
            "last_name": "User"
        }
    ]
};
const request = {};
request.body = data;
request.method = 'PUT';
request.url = '/v3/marketing/contacts';
sgClient.request(request)
    .then(([response, body]) => {
        console.log(response.statusCode);
        console.log(response.body);
    }).catch(function (error) {
        console.error(error.response.body);
    }
);

All 9 comments

Also have the same issue, was working a few weeks ago, now i get 400 with the error:

{field: "", message: "invalid input"}

I also sent a request using just the standard node https module, i get back a success and a {job_id: "job-id"}, but nothing ever was added to a list

found out it was because i was passing in a non-standard field ... id ... ??, works as expected using sendgrind client

@jclackett were you able to figure it out?

@alxcalx yeah make sure you pass only the fields that they allow as per the docs, id isnt one of them!

The old and new APIs should work fine when using the client. Example using the new API:

const sgClient = require('@sendgrid/client');
sgClient.setApiKey(process.env.SENDGRID_API_KEY);

const data = {
    "contacts": [
        {
            "age": "25",
            "email": "[email protected]",
            "first_name": "",
            "last_name": "User"
        },
        {
            "age": "25",
            "email": "[email protected]",
            "first_name": "Example",
            "last_name": "User"
        }
    ]
};
const request = {};
request.body = data;
request.method = 'PUT';
request.url = '/v3/marketing/contacts';
sgClient.request(request)
    .then(([response, body]) => {
        console.log(response.statusCode);
        console.log(response.body);
    }).catch(function (error) {
        console.error(error.response.body);
    }
);

@childish-sambino

What is the API access level requirements for this endpoint. I have set it to Full Access but still get message: 'authorization required'

@thecodelayeriser I recommend checking the API key that you're using and make sure it's being set properly. E.g.,

console.log(`API key=${process.env.SENDGRID_API_KEY}`);

@childish-sambino Hmm - I should have checked this. Found the issue. Thx

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nicoasp picture nicoasp  路  3Comments

thinkingserious picture thinkingserious  路  4Comments

danielflippance picture danielflippance  路  4Comments

amlcodes picture amlcodes  路  4Comments

umarhussain15 picture umarhussain15  路  3Comments