In SmartyStreets, I can view my subscription balance while logged in on the portal. There's no way to check my subscription balance via the API. Our app requires address validation in order to sell. As part of operationalizing SmartyStreets, I want to monitor my subscription balance, so I can be alerted to renew before I run out of address validations.
Available monitoring tools are Nagios, Nimsoft and CA APM.
Has anyone built such a monitor?
SmartyStreets subscriptions renew on 2 occasions:
The second trigger is there so that you don't have to worry about how used up your subscription is; if you run out, it just fills up with more without interrupting your service.
As for monitoring, it's kind of built-in. You should get emails when your subscription is running low, when it is about to renew, and when it actually does renew.
Screen-scraping using curl is one approach. Try:
This command will save your auth cookies in the SSCookies file:
$ curl -c SSCookies 'http://smartystreets.com/apps/accounting/auth' -d email=myEmail -d password=myPassword
Now use the cookie jar to auth with the subscription app. These commands will fetch your subscriptions:
$ subs=https://smartystreets.com/apps/accounting/subscription
$ curl -s -b @SSCookies $subs | python -mjson.tool
(The | python part makes the output pretty)
The resulting JSON will list your whole account history, including subscriptions that are no longer active and any that may be coming up for renewal. Look for the entry that has a status of "active":
[
{
"free": true,
"id": nnnnn,
"issued": 250.0,
"lapse_date": "2013-06-15T08:15:00Z",
"name": "LiveAddress API (Free)",
"sku": nnnnn,
"start_date": "2013-06-03T21:56:00Z",
"status": "expired",
"used": 250
},
{
"autorenew": true,
"id": nnnnn,
"issued": 1200000.0,
"lapse_date": "2015-06-20T20:11:00Z",
"name": "LiveAddress API (Yearly)",
"sku": nnnnn,
"start_date": "2014-06-20T20:11:00Z",
"status": "active",
"used": 934
},
{
"autorenew": true,
"cart_id": 0,
"issued": 1200000.0,
"lapse_date": "2016-07-20T20:11:00Z",
"name": "LiveAddress API (Yearly)",
"sku": nnnnn,
"start_date": "2015-07-20T20:11:00Z",
"status": "proposed"
}
]
My active subscription is #2 (index 1). Some Python to extract the vitals (I named this SSMonitor.py):
import json,sys;
obj=json.load(sys.stdin);
keys=obj[1].keys();
values=obj[1].values();
for i,key in enumerate(keys):
if (key=="used"): used=values[i];
if (key=="issued"): issued=values[i];
print "SmartyStreets subscription usage: {0}/{1}".format(used, issued);
$ curl -s -b @SSCookies $subs | python SSMonitor.py
SmartyStreets subscription usage: 934/1200000.0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With