Buttondown

Get all subscribers.

B
import fetch from 'isomorphic-unfetch';

export default async (_, res) => {
  const API_KEY = process.env.BUTTONDOWN_API_KEY;
  const response = await fetch('https://api.buttondown.email/v1/subscribers', {
    headers: {
      Authorization: `Token ${API_KEY}`,
      'Content-Type': 'application/json'
    },
    method: 'GET'
  });

  const { count } = await response.json();

  return res.status(200).json({ count });
};
import fetch from 'isomorphic-unfetch';

exports.handler = async (event, context, callback) => {
  const API_KEY = process.env.BUTTONDOWN_API_KEY;
  const response = await fetch('https://api.buttondown.email/v1/subscribers', {
    headers: {
      Authorization: `Token ${API_KEY}`,
      'Content-Type': 'application/json'
    },
    method: 'GET'
  });

  const { count } = await response.json();

  return {
    statusCode: 201,
    body: JSON.stringify({ count })
  };
};

Usage#

1

Create Buttondown Account

First, create a Buttondown account.

2

Find API Key

From the Settings page, retrieve your API key.

3

Add Environment Variables

To securely access the API, we need to include the secret with each request. We also do not want to commit secrets to git. Thus, we should use an environment variable.

  • Netlify: Settings -> Build & deploy -> Environment -> Environment variables.
  • Vercel: Settings -> General -> Environment Variables.

Alternatively, you can add the enviornment variable to your vercel.json or netlify.toml file.

New functions in your inbox

Get access to functions when they're added.