Skip to content

Error message when trying to send transactional email #337

@tommaton

Description

@tommaton

Hi,

I keep on getting the following error when trying to send a transactional email using a template I've setup within sendGrid.

Status code: 400
Error message: message: 'Bad Request', field: null, help: null

I've followed the following example: https://github.com/sendgrid/sendgrid-nodejs#without-mail-helper-class and have developed the following, its probably something simple i've missed or missunderstood.

            const subject = 'Email subject';
            const templateId = 'myTemplateId';
            const sg = require('sendgrid')(myapikey);
            const request = sg.emptyRequest({
                method: 'POST',
                path: '/v3/mail/send',
                body: {
                    "personalizations": [
                        {
                            "to": userEmails, // aray of user emails
                            "substitutions": {
                                "-userName-": userDetails.name,
                                "-productPrice-": productDetails.price,
                                "-productUrl-": productDetails.url,
                                "-productName-": productDetails.name,
                            },
                            "subject": subject
                        }
                    ],
                    "from": {
                        "email": "myemail",
                        "name": "myname"
                    },
                    "content": [
                        {
                            "type": "text/html"
                        }
                    ],
                    "template_id": templateId
                }
            });

            sg.API(request, function (error, response) {
                if (error) {
                    console.log('Error response received');
                }
                console.log(response.body.errors);
            });

Technical details:

  • sendgrid-nodejs Version: 4.7.1
  • Node.js Version: 6.6

Thanks in advance.
Tom

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: questionquestion directed at the library

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions