Skip to content
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

invalid json response body at https://api.mailersend.com/v1/email #57

Closed
andrscyv opened this issue Jan 6, 2023 · 3 comments
Closed

Comments

@andrscyv
Copy link

andrscyv commented Jan 6, 2023

Hello, I'm testing out the sdk but I'm getting the following error:

FetchError: invalid json response body at https://api.mailersend.com/v1/email reason: Unexpected end of JSON input
at /Users/cruzyv/repos/personal-artist-backend/node_modules/node-fetch/lib/index.js:273:32
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
type: 'invalid-json'
}

This is my code

`
const Recipient = require('mailersend').Recipient;
const EmailParams = require('mailersend').EmailParams;
const MailerSend = require('mailersend');

const mailersend = new MailerSend({
api_key: process.env.MAILERSEND_API_KEY,
});

const recipients = [new Recipient('XXXX', 'Andrés')];

const emailParams = new EmailParams()
.setFrom('hello@XXX')
.setFromName('test')
.setRecipients(recipients)
.setReplyTo('reply@XXX')
.setReplyToName('Reply to name')
.setSubject('Hello there.')
.setHtml('This is the HTML content')
.setText('This is the text content');

mailersend
.send(emailParams)
.then((response) => {
return response.json();
})
.catch((error) => {
console.log(error);
});`

I've got a dependency that has me pin down to node 16... could that be it ?

@andrscyv
Copy link
Author

andrscyv commented Jan 6, 2023

The test email was sent successfully

@andrscyv
Copy link
Author

andrscyv commented Jan 6, 2023

My bad, that endpoint returns an empty body and I guess thats why response.json() throws

@opheus2
Copy link
Contributor

opheus2 commented Jan 10, 2023

@andrscyv I'm closing this issue as fixed. Please feel free to open one if you have any other concerns. Thanks

@opheus2 opheus2 closed this as completed Jan 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants