southern-company-api
v4.0.0-rc.0
Published
A Library for pulling power usage data from Southern Company or Southern Company subcompanies
Readme
Southern Company API
Node.js Library to access utility data from Southern Company power utilities (Alabama Power, Georgia Power, Mississippi Power)
Example
/* Importing Library */
import {SouthernCompanyAPI} from 'southern-company-api';
/* Or requiring for a script */
var SouthernCompanyAPI = require('../southern-company-api').SouthernCompanyAPI;
/* Instantiating API */
const SouthernCompany = new SouthernCompanyAPI({
username: 'username',
password: 'password',
accounts: ['123123123']
});
const accounts = await API.getAccounts();
console.log("Accounts", JSON.stringify(accounts));
/* Grabbing Monthly Data */
const data = await API.getMonthlyData();
console.log("Monthly Data", JSON.stringify(data));
/* GettiGrabbingng Daily Data */
const servicePointNumber = accounts[0].servicePoints[0].servicePointNumber;
const startDate = new Date(2020, 2, 1);
const endDate = new Date();
const dailyData = await SouthernCompany.getDailyData(startDate, endDate, servicePointNumber);API
Login
Login by passing username and password as a config object when instantiating.
/* Instantiating API */
const API = new SouthernCompanyAPI({
username: 'username',
password: 'password'
});Data methods
getMonthlyData()
Description This method collects all monthly data on all accounts from the earliest available to the last complete month of data.
Arguments
- None
Returns
- Promise
Promise Return
dataEach index of array is an account retrievednameName of the accountaccountNumberAccount numberdataEach object of array is a month of datadateM/YYYY of datacostTotal energy cost for the monthkWhTotal amount of kWh used during the monthbillAmount billed for the month
errorDescription of error
Example
/* Getting Monthly Data */
const monthlyData = await API.getMonthlyData();
/* Printing monthly data */
console.info('Monthly Data', JSON.stringify(monthlyData));
/* Result */
[{
"accountNumber": 0000000000,
"data":[
{"startDate": "2024-02-16T00:00:00.000Z", "endDate": "2024-03-19T00:00:00.000Z", "cost":66.66,"kWh":416},
{"startDate": "2024-03-19T00:00:00.000Z", "endDate": "2024-04-17T00:00:00.000Z",,"cost":62.23,"kWh":380},
{"startDate": "2024-04-17T00:00:00.000Z", "endDate": "2024-05-17T00:00:00.000Z",,"cost":65.42,"kWh":406}
]
}]getDailyData()
Description
This method collects daily data from the startDate provided to the endDate provided.
Arguments
startDateFirst date (Date) to include in collectionendDateLast date (Date) to include in collection
Returns
- Promise
Promise Return
dataEach index of array is an account retrievednameName of the accountaccountNumberAccount numberdataEach object of array is a month of datadateM/D/YYYY of datakWhTotal amount of kWh used during the datecostTotal energy cost for the date
Example
/* Getting Daily Data */
const startDate = new Date(2017, 05, 01);
const endDate = new Date(2017, 05, 02);
const dailyData = await SouthernCompany.getDailyData(startDate, endDate);
/* Printing daily data */
console.info('Daily Data', JSON.stringify(data));
/* Result */
[{
"accountNumber": 0000000000,
"data":[
{"date":"2017-05-01T06:00:00.000Z", "cost":2.17, "kWh":12.76},
{"date":"2017-05-02T06:00:00.000Z", "cost":77, "kWh":77}
]
}]How Authentication Works
- Login Page is loaded
MethodGETURLhttps://webauth.southernco.com/account/login
- Grab the
RequestVerificationTokenfrom the login Page
RequestVerificationTokencan be found at the bottom of the page in a script tag. Inside the tag theRequestVerificationTokenis assigned towebauth.aft
- Login Request is initialized
MethodPOSTURLhttps://webauth.southernco.com/api/loginHeadersRequestVerificationToken:RequestVerificationTokenContent-Type: application/json
Body(JSON Object):username:usernamepassword:passwordparamsReturnUrl'null'
- Grab the
ScWebTokenfrom the JSON response. Can be found in theresponse.data.htmlas a value on a hidden input with the name ScWebToken - Grab the new
ScWebTokenfrom the set cookies from a secondary LoginComplete request. - This secondary Southern Company Web Token can be traded in for a Southern Company JSON Web Token (
ScJwtToken) that can be used with the API.
MethodGETURLhttps://customerservice2.southerncompany.com/Account/LoginValidated/JwtTokenHeadersCookieScWebToken=ScWebToken
- Grab the
ScJwtTokenfrom the response's cookies
- Cookie's name is ScJwtToken and contains the ScJwtToken
- This
ScJwtTokencan be used to authenticate all other API requests.
