useplunk / node

Helper library for interacting with Plunk in Node.js
https://www.npmjs.com/package/@plunk/node
20 stars 4 forks source link

Plunk Node.js

This project contains the helper library for interacting with the Plunk API using Node.js.

Table of contents

Card

Installation

Installing the latest version can be done through your package manager.

npm i @plunk/node

yarn add @plunk/node

Getting started

Any interaction you want to make with the Plunk API needs to be done through the Plunk client. You can use a default import to get started.

import Plunk from '@plunk/node';

// Using the default API URL
const plunk = new Plunk("Your secret key");

// Or specifying a custom API URL
const plunkCustom = new Plunk("Your secret key", { baseUrl: "https://selfhosted.example.com/api/v1/" });

API

Events

track()

Used to publish an event

Parameters
const success = await plunk.events.track({
  event: "new-project",
  email: "hello@useplunk.com",
  data: {
    company: "Plunk"
  }
});

Emails

send()

Used to send a transactional email

Parameters
const success = await plunk.emails.send({
  to: "hello@useplunk.com",
  subject: "Welcome to Plunk",
  body: "Hello world!",
});