Skip to content

Error message when trying to send transactional email #337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tommaton opened this issue Nov 11, 2016 · 3 comments
Closed

Error message when trying to send transactional email #337

tommaton opened this issue Nov 11, 2016 · 3 comments
Labels
type: question question directed at the library

Comments

@tommaton
Copy link

tommaton commented Nov 11, 2016

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

@thinkingserious
Copy link
Contributor

Hello Tom,

I believe you should either remove the content block or add a value.

You might also try working through this example: https://github.com/sendgrid/sendgrid-nodejs/blob/master/USE_CASES.md#without-mail-helper-class

With Best Regards,

Elmer

@thinkingserious thinkingserious added the type: question question directed at the library label Nov 14, 2016
@tommaton
Copy link
Author

@thinkingserious I forgot to update this, I found the issue.

The value of productDetails.price was a number (189.95) once I converted this to a string it now works.

@thinkingserious
Copy link
Contributor

@tommaton,

Sorry you had to work through that and you are not the first one :(

One of the things we will be adding to the new version of the mail helper is auto-conversion to string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question question directed at the library
Projects
None yet
Development

No branches or pull requests

2 participants