JavaScript/TypeScript (Node.js) Buttondown API wrapper.
This library allows you to quickly and easily use the Buttondown API v1 via Node.js.
This project is not officially affiliated with Buttondown, it's maintained by community members. For any feedback, questions or issues, please create issues and pull requests or merely upvote or comment on existing issues or pull requests.
- Node.js version 10 or 12
- A Buttondown account, sign up for free free for your first thousand subscribers or check out the pricing page.
Grab your API Key from the Buttondown Setting Page.
Do not hardcode your Buttondown API Key into your code. Instead, use an environment variable or some other secure means of protecting your Buttondown API Key. Following is an example of using an environment variable.
Update the development environment with your BUTTONDOWN_API_KEY, for example:
echo "export BUTTONDOWN_API_KEY='YOUR_API_KEY'" > buttondown.env
echo "buttondown.env" >> .gitignore
source ./buttondown.envThe following recommended installation requires npm. If you are unfamiliar with npm, see the npm docs. Npm comes installed with Node.js since node version 0.8.x, therefore, you likely already have it.
npm install --save buttondownYou may also use yarn to install.
yarn add buttondownThe following is the minimum needed code to create a new draft email. Use this example, and modify the to and from variables:
For more complex use cases, please see USE_CASES.md.
const buttondown = require('buttondown');
buttondown.setApiKey(process.env.BUTTONDOWN_API_KEY);
const draft = {
subject: 'Creating a new Buttondown draft',
body: '<strong>and easy to do from Node.js</strong>',
};
//ES6
buttondown.drafts.create(draft)
.then(() => {}, error => {
console.error(error);
if (error.response) {
console.error(error.response.body)
}
});
//ES8
(async () => {
try {
await buttondown.drafts.create(draft);
} catch (error) {
console.error(error);
if (error.response) {
console.error(error.response.body)
}
}
})();After executing the above code, you should have a draft in your Buttondown account. You view it in the UI.
If you are interested in the future direction of this project, please take a look at the open issues and pull requests. I would love to hear your feedback!
- Node 10
- Yarn 1.x or npm
- Clone the repository
- Run
yarnornpm installinstalls all required dependencies. - Run
yarn buildto build from TypeScript to common JavaScript distribution formats. - Run
yarn testto run all tests :D.
Equivalent
npm run <script>should also work
yarn testrun tests against built output with ava. Important: runs against build output so runyarn buildbeforehand.yarn buildrun build from TypeScript to UMD, CJS, ESM with microbundleyarn watchruns build in watch mode with microbundleyarn lintwill lint all of the files with xoyarn formatwill run lint with--fixoption on all the examples files (and tests).yarn release, run clean, production build and release withnp.
The auto-generated SDK contains TS errors, eg. _gen/services/SubscribersService.ts has
To re-generate:
- Fetch the schema from the API docs
curl https://api.buttondown.email/v1/schema\?format\=openapi >> schema.json- Convert using openapi-typescript-codegen
npx openapi-typescript-codegen --input schema.json --output ./_gen- Keep only the
servicesfolder
rm -rf _gen/core _gen/index.ts _gen/modelsThis package is maintained by Hugo from Code with Hugo and Alpine.js Weekly.
Special thanks to:
- Justin Duke for creating Buttondown
- The Twilio SendGrid team for the inspiration on how to structure this package and docs
- The developers behind
Code is licensed under the MIT License.