I am trying to achieve send of mail via SendGrid API.
Following is the JSON I am sending as a body of the POST Method
{
"content" : [
{
"type" : "text\/plain",
"value" : "Hello, World!"
}
],
"personalizations" : [
{
"to" : [
{
"email" : "[email protected]"
}
],
"subject" : "Hello, World!"
}
],
"from" : {
"email" : "[email protected]"
}
}
and following is the return that I am getting
{"message":"Bad Request","field":null,"help":null}
This piece of info doesn't help much.
The authorization is in place, and I believe correctly.
Perhaps, I might have missed some sort of settings in the SendGrid App
If it helps im using Objective-C.
Please help!!
I experienced the same issue and the problem was actually that all substitutions in the personalizations
field need to be string values (see https://github.com/sendgrid/sendgrid-php/issues/264)
"personalizations": [{
"to": [{
"email": "[email protected]"
}],
"substitutions": {
"{myFloatVal}": 16.5,
"{firstname}": "Thomas"
}
}]
Why you are getting 400 BAD REQUEST
from SendGrid one can only guess. 400 BAD REQUEST
means oh we know what happened we are just not telling you.
This is a common 'error handling' 'technique' where the developer catches the error and simply returns false, hiding any of the details or reasons for the failure.
One possible reason, as was in my case, one of the CC addresses was also the TO address. You see among many other things, SendGrid does not allow an email address to occur more than once in a send request, and if you happen to list an email recipient more than once in any of the TO,CC, or BCC lists SendGrid just sends back 400 BAD REQUEST.
There are dozens of other poorly documented reason for 400 BAD REQUEST and I sincerely wish you luck in finding out why SendGrid rejected yours.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With