Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Can I access the payload object from a custom endpoint on a collection?

default discord avatar
notchr2 years ago
2

Wanted to access the Payload object on a custom endpoint on a collection to send an email through Payload. Is this better suited for the local API?

  • discord user avatar
    jarrod_not_jared
    2 years ago

    What do you mean exactly? The req should have payload object on it right? And in that case you would be able to us the local API to send the email

  • default discord avatar
    notchr2 years ago

    Ah, for some reason I didn't realize the payload object is on the req!



    Thanks

    @281120856527077378

    For anyone who finds this, I did...



      endpoints: [
        {
          path: "/verify",
          method: "post",
          handler: async (req, res, next) => {
            try {
              const msg: Message = {
                from: "noreply@example.com",
                to: req.body.email,
                subject: "Example",
                html: `The id posted was ${req.body.id}`,
              };
              await req.payload.sendEmail(msg);
            } catch (error) {
              res.json({
                ok: false,
                error: "Error while sending verification email.",
              });
            }
          },
        },
      ],
Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.