mailersend / mailersend-nodejs

The official MailerSend Node.js SDK
https://developers.mailersend.com
MIT License
125 stars 17 forks source link

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

Closed andrscyv closed 1 year ago

andrscyv commented 1 year ago

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 commented 1 year ago

The test email was sent successfully

andrscyv commented 1 year ago

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

opheus2 commented 1 year ago

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