silviubogan
silviubogan

Reputation: 3461

What are the possible error messages in the response JSON when sending email using the official Node.js SendGrid API?

I come from Mandrill which gives me error messages such as success, rejected or invalid in the callback corresponding to the callback in the source code snippet below. In Mandrill, for example, in the Send call, you can get success JSON responses such as:

[
    {
        "email": "[email protected]",
        "status": "sent",
        "reject_reason": "hard-bounce",
        "_id": "abc123abc123abc123abc123abc123"
    }
]

or error JSON responses such as:

{
    "status": "error",
    "code": 12,
    "name": "Unknown_Subaccount",
    "message": "No subaccount exists with the id 'customer-123'"
}

I saw the code here from the official SendGrid Node.js API implementation and this page about the SendGrid Web API v2 and I am wondering whether there can be JSON responses (in the json variable below) such as { message: 'error', ... }, for example when the err variable below is null.

My code looks like this (it is inspired from this page):

sendgrid.send(email, function (err, json) {
    if (err) { return console.error(err); }

    console.log(json);
});

In this code, from my tests,

These are some of the web pages I have read but they did not help me:

Google queries I tried:

So my question is, what are the possible error messages in the response JSON (in the value of the message property in the given example of response JSON) when sending email using the official SendGrid Node.js API? I think about something similar to rejected from Mandrill, without using a webhook.

Upvotes: 0

Views: 649

Answers (1)

bwest
bwest

Reputation: 9814

Mandrill has a "synchronous" sending mode, which it sounds like you were using. SendGrid does not. We accept the API request (as long as it is well-formed), then hand it off for processing. So the answer to your question is that there are no possible email-related errors in the response payload, only errors when the request itself is bad.

The next version of this endpoint will have better validation and error reporting, but will still be entirely async. However, the response body will return a message ID that you can use to check status later without having to use a webhook. Stay tuned for that.

Upvotes: 1

Related Questions