Using Sendy API for a Dashboard

Sendy API for Dashboard Metrics

The documented cases to use the Sendy API are few, but in our case we use it every 5 minutes. In my company we don’t run a bunch of mysql statements to get information from the database. We don’t track our Facebook likes, Twitter followers, or any other important metric with a manual check.  Instead we simply write a script and dump that information into Graphite. If you aren’t familiar with Graphite and Grafana, get on board if you like having a dashboard to reference for metrics at a glance.

Sendy API Subscriber Growth in Grafana

I would like to share the method I am using to create the graph you see above. The code being used is

#!/bin/bash
#set -x
HOSTNAME="${COLLECTD_HOSTNAME:-`hostname -f`}"
INTERVAL="${COLLECTD_INTERVAL:-60}"
DATE=`date +%s`
GRAPHITE=127.0.0.1
GRAPHITE_PORT=2003
subscribers=$(curl -X POST -H "Content-Type: multipart/form-data" -F "api_key=YOURAPIKEY" -F "list_id=YOURLISTID" "https://www.YOURWEBSITE.com/sendy/api/subscribers/active-subscriber-count.php")
echo "$subscribers"
echo "collectd.sendy-metrics.numberOfsubs $subscribers $DATE" | nc $GRAPHITE $GRAPHITE_PORT

On your server, if you create this as a shell script and update the fields specified above you will be able to get a subscriber count back from the Sendy API.

You should already know the URL for your installation but I will explain how to get the api_key and the list_id from your Sendy install.

Your Sendy API key can be found by going to your Sendy URL and logging in. In the upper right hand corner, select your name and then settings. Directly under the settings menu, you will see your key. You can copy this and put it into your script.

Screenshot 2016-06-04 16.26.43

Your ListID should be easier to get than it currently is, but it still isn’t hard. Click on the Brand you manage, then click Lists. Put your mouse over the ID field and it will give you the ListID so you can use it in your script

Screenshot 2016-06-04 16.29.43

Your script will need to made executable but after updating the fields, you will be able to get the number of subscribers for your list. In my script I am putting the value in to Graphite and then displaying growth. The script is running every 5 minutes and gives us a great dashboard for metrics at a glance. Quite handy if you would like to see your list growth outside of the Sendy UI.

Leave a Reply