sendgrid-nodejs: Unexpected Error when trying to send transactional email
Issue Summary
Getting a ‘Bad Request’ error with the following payload.
Request
cosnt msg = {
"to": "ian.reis@gmail.com",
"from": "invitations@paycheck.fyi",
"subject": "Support Pay Transparency at PayCheck",
"templateId": "24ae3147-4faa-4380-8613-c5be144f4542",
"customArgs": {
"ally_id": "cj6zlh7yd000001qir4r5suuk"
}
};
sgMail.send(msg)
Response
{
"message": "Bad Request",
"code": 400,
"response": {
"headers": {
"server": "nginx",
"date": "Wed, 30 Aug 2017 22:30:41 GMT",
"content-type": "application/json",
"content-length": "365",
"connection": "close",
"access-control-allow-origin": "https://sendgrid.api-docs.io",
"access-control-allow-methods": "POST",
"access-control-allow-headers": "Authorization, Content-Type, On-behalf-of, x-sg-elas-acl",
"access-control-max-age": "600",
"x-no-cors-reason": "https://sendgrid.com/docs/Classroom/Basics/API/cors.html"
},
"body": {
"errors": [
{
"message": "Unless a valid template_id is provided, the content parameter is required. There must be at least one defined content block. We typically suggest both text/plain and text/html blocks are included, but only one block is required.",
"field": "content",
"help": "http://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/errors.html#message.content"
}
]
}
}
}
Notes
In the documentation it says templateId but in the error message it says template_id. I’ve tried both and received the same error message. I attached a screenshot of my template screen as a sanity check to make sure I have it configured correctly in sendgrid.
Technical details:
- sendgrid-nodejs Version: master (latest commit: [commit number])
- Node.js Version: 6.10.3
- Running in an AWS Lambda function

About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 24 (14 by maintainers)
Thanks for the help peeps. I was literally losing my mind. I finally figured out a workaround late last night and was coming here to report more information, but it seems like you all are already on it 😃
Sorry about that @onesien,
The fix has just been pushed to npm (v6.1.2).
PR is up, this should fix the issue and not send the content field with the request if there is no content provided.
@thinkingserious I think you’re right. I read the API docs and thought the field was mandatory. It only has a well hidden comment (which is amazingly styled!) that I missed:
I will create a PR to address this!
I know this is an old issue, but I’m getting this same error. Using the suggestion by @cbilliau works… The catch here is that I’m not using Javascript… I’m using a Crystal adapter.
These docs say
contentis requiredso in my case, I was sending an empty array along with the template id
{"content": [], "template_id": "abc123"}. If anyone else lands here,{content: [{ type: "text/html", value: "0" }], template_id: "abc123"}works. Possibly also removing thecontentkey iftemplate_idexists, but I haven’t been able to test that theory.kk - confirming its working now, especially using the
content: [{ type: "text/html", value: "0" }]line that @cbilliau mentioned 👍wow let me bow out for a sec @cbilliau 🤣 i just was rushing thru stuff and didn’t pay more attention. I realized i was grabbing the unique ID for a template i made under “marketing” but not under “transactional templates”. I don’t use the sendgrid UI much and just totally botched this one lol
Total face palm, fixing on my end and then hopefully expecting it to work.
I had to add the content block to get the template to be sent. I was getting a Bad Request (400) “Unless a valid template_id is provided, the content parameter is required. There must be at least one defined content block…” while using template created in the new html editor.
If I add the content block, the template email is sent as formatted in the html editor.