Skip to content

Attachments in payload cause Novu email trigger to fail (500 error) #9178

@shanil-sasikumar

Description

@shanil-sasikumar

📜 Description

When attempting to send an email using Novu with an attachment, the request fails with a 500 Internal Server Error. The same code works correctly when the attachments object is removed from the payload.

According to the Novu documentation, attachments should be passed in the payload under the key attachments, but this seems to cause issues in practice.

👟 Reproduction steps

  1. Create an Astro API endpoint that calls Novu’s trigger API.
  2. Pass a payload including an attachments object, for example:
const attachment = {
  file: Buffer.from(JSON.stringify({ test: "data" })).toString("base64"),
  name: "test.json",
  mime: "application/json",
};

await fetch(`${import.meta.env.PUBLIC_NOVU_API_URL}`, {
  method: "POST",
  headers: {
    Authorization: `ApiKey ${import.meta.env.PUBLIC_NOVU_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    name: "test-template",
    to: {
      subscriberId: import.meta.env.PUBLIC_NOVU_SUBSCRIBER_ID,
      email: "user@example.com",
    },
    payload: {
      foo: "bar",
      attachments: [attachment], // <-- adding this breaks request
    },
  }),
});
  1. Observe the response:
{
  "statusCode": 500,
  "message": "Internal server error"
}
  1. Remove the attachments key and re-run — email sends successfully.

👍 Expected behavior

Emails should send successfully when including valid attachments (buffer or base64 encoded, with file name, and mime fields).

👎 Actual Behavior with Screenshots

  • With attachments: Novu returns a 500 Internal Server Error.
  • Without attachments: Email sends as expected.

Novu version

0.22.0

npm version

No response

node version

No response

📃 Provide any additional context for the Bug.

Environment

  • Framework: Astro
  • Runtime: Node.js
  • Novu SDK/API: @novu/api
  • Deployment: Custom Novu instance

Additional Context

  • Using JSON (application/json) and image (image/jpeg) attachments produces the same error.
  • Confirmed that the base64 content is valid.
  • Issue seems specific to how the API parses the attachments field inside payload.

👀 Have you spent some time to check if this bug has been raised before?

  • I checked and didn't find a similar issue

🏢 Have you read the Contributing Guidelines?

Are you willing to submit PR?

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions