unsend-dev / unsend

Open source alternative to Resend,Sendgrid, Postmark etc.
https://unsend.dev
GNU Affero General Public License v3.0
247 stars 19 forks source link

Self-hosted: Invalid API token #48

Closed jaaneh closed 2 months ago

jaaneh commented 2 months ago

Docs shows you should init Unsend SDK with new Unsend({ apiKey: "<key>" }) however the constructor only accepts a string: Unsend(key?: string | undefined, url?: string):

import { Unsend } from "unsend"
export const unsend = new Unsend("<key>")

// Simplified example
const { error } = await unsend.emails.send({
  from: "mail@domain.com",
  to: "my@email.com",
  subject: "Subject",
  html: "<h1>Hello!</h1>"
})

This logs this:

{
  error: {
    code: 'FORBIDDEN',
    message: 'Invalid API token'
  }
}

I am using the API token which was generated in the dashboard in developer settings tab. Both the domain and SES have been verified

KMKoushik commented 2 months ago

@jaaneh sorry for that, i'll update the document. for self-hosted version you should pass the url as well, it will be the url of the hosted solution.

Lemme know if that fixes the issue

jaaneh commented 2 months ago

@KMKoushik that seems to work, yeah. Thanks! Was just a tad confused reading the SDK needing an object passed.

Any clue why I may be getting this? BadRequestException: 1 validation error detected: Value at 'content.simple.body.text.data' failed to satisfy constraint: Member must not be null Sending same payload as above

KMKoushik commented 2 months ago

@jaaneh this issue will be fixed in upcoming release, as interim just pass text variable while sending email.

// Simplified example
const { error } = await unsend.emails.send({
  from: "mail@domain.com",
  to: "my@email.com",
  subject: "Subject",
  html: "<h1>Hello!</h1>",
  text: "hello"
})

sorry again!

jaaneh commented 2 months ago

@KMKoushik works like a charm. thanks so much! I'll see if I can contribute some to docs in the coming days :-)

KMKoushik commented 2 months ago

@jaaneh legend! thank you.

KMKoushik commented 2 months ago

closing this in favour of #49