Reputation: 3461
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,
err
can take the values [Error: Missing email body]
, [Error: Missing subject]
etc. or null
. When it is null
then there is no error.json
always has the value { message: 'success' }
when there is no error and null
when there is an error.These are some of the web pages I have read but they did not help me:
Google queries I tried:
sendgrid message success
sendgrid web api response
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
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