- Use Our Data
- Integrations
- Azure
Power Outage Data in Azure
To get power outage data into Azure, run a timer-triggered Azure Function that calls the PowerOutage.us v2 REST API every 15 minutes, with the API key held in Key Vault and exposed to the function as a Key Vault reference. The Azure SQL output binding upserts county counts into a table, and a Blob Storage output binding keeps a GeoJSON snapshot of active outages from every run. If you would rather not write code, an Azure Data Factory pipeline with the REST connector can copy the same data on a schedule.
What you'll have
- A
dbo.CountyOutagestable in Azure SQL, upserted every 15 minutes, ready for Power BI or your own apps. - A GeoJSON snapshot of active outages in Blob Storage from every run, for maps, Fabric or Synapse.
- An API key that lives in Key Vault and reaches the function through its managed identity, never in code or settings files.
- A no-code alternative with Data Factory for teams that already run pipelines there.
What you need
An API key (request one with the form below) and these endpoints. Full details are in the API reference.
| Endpoint | Method | Used for | Package |
|---|---|---|---|
/outages/counties | GET | County customersOut, customersTracked and lastUpdatedAt for a state, upserted into Azure SQL. | Core |
/geojson/outages | GET | Active outages as a GeoJSON FeatureCollection, saved to Blob Storage as returned. | Standard |
Step 1: Put the key in Key Vault and reference it
Store the key as a Key Vault secret, give the function app a system-assigned managed identity, and grant that identity the Key Vault Secrets User role (or the Get secrets permission if your vault uses access policies). An app setting whose value is @Microsoft.KeyVault(VaultName=...;SecretName=...) then resolves to the key, and the code reads it as an ordinary environment variable. The same identity connects to Azure SQL, so no database password is stored either.
read -rs POWEROUTAGE_API_KEY # paste the key; it is not echoed or saved to history
az keyvault secret set --vault-name outage-kv --name poweroutage-api-key \
--value "$POWEROUTAGE_API_KEY"
# Give the function app an identity that can read the secret
principal=$(az functionapp identity assign --name outage-sync \
--resource-group rg-outages --query principalId --output tsv)
az role assignment create --assignee "$principal" --role "Key Vault Secrets User" \
--scope "$(az keyvault show --name outage-kv --query id --output tsv)"
# The key as a Key Vault reference, and Azure SQL through the same identity
az functionapp config appsettings set --name outage-sync --resource-group rg-outages \
--settings \
"POWEROUTAGE_API_KEY=@Microsoft.KeyVault(VaultName=outage-kv;SecretName=poweroutage-api-key)" \
"SqlConnectionString=Server=tcp:outage-sql.database.windows.net,1433;Database=outages;Authentication=Active Directory Managed Identity;" Step 2: Create the Azure SQL table
The SQL output binding upserts with a T-SQL MERGE on the primary key, so CountyId must be the primary key and each run updates the same rows instead of adding new ones. Timestamps arrive as ISO 8601 strings in UTC, which DATETIMEOFFSET stores as-is. Add the function app as a database user from Microsoft Entra ID; the user name is the app name. Run these statements connected to the outages database as the server's Microsoft Entra admin, because only a Microsoft Entra sign-in can run CREATE USER ... FROM EXTERNAL PROVIDER. The server must also accept connections from the function app: turn on Allow Azure services and resources to access this server in its networking settings, or use virtual network integration with a private endpoint.
CREATE TABLE dbo.CountyOutages (
CountyId INT NOT NULL PRIMARY KEY,
Name NVARCHAR(100) NOT NULL,
StateId INT NOT NULL,
Fips CHAR(5) NULL,
CustomersOut INT NOT NULL,
CustomersTracked INT NOT NULL,
LastUpdatedAt DATETIMEOFFSET NULL,
GeneratedAt DATETIMEOFFSET NOT NULL
);
-- Let the function app's managed identity upsert rows
CREATE USER [outage-sync] FROM EXTERNAL PROVIDER;
ALTER ROLE db_datareader ADD MEMBER [outage-sync];
ALTER ROLE db_datawriter ADD MEMBER [outage-sync]; Step 3: Write the timer-triggered function
This uses the Python v2 programming model in function_app.py. The NCRONTAB schedule 0 */15 * * * * runs at second 0 of every 15th minute, in UTC. The key goes in an Authorization: Bearer header, and a 429 waits the Retry-After seconds before trying again. {DateTime} in the blob path names each snapshot after the run time; create the outage-snapshots container in the storage account first. List azure-functions and requests in requirements.txt, and keep the extension bundle in host.json at version 4.x, which includes the SQL binding.
import os
import time
import azure.functions as func
import requests
app = func.FunctionApp()
def fetch(url, params):
"""GET a PowerOutage.us endpoint, waiting out a 429 for as long as Retry-After says."""
headers = {'Authorization': f"Bearer {os.environ['POWEROUTAGE_API_KEY']}"}
for _ in range(3):
response = requests.get(url, params=params, headers=headers, timeout=30)
if response.status_code != 429:
response.raise_for_status()
return response
time.sleep(int(response.headers.get('Retry-After', '10')))
raise RuntimeError(f'Still rate limited after 3 tries: {url}')
@app.timer_trigger(schedule='0 */15 * * * *', arg_name='timer', run_on_startup=False)
@app.sql_output(
arg_name='counties',
command_text='[dbo].[CountyOutages]',
connection_string_setting='SqlConnectionString',
)
@app.blob_output(
arg_name='snapshot',
path='outage-snapshots/{DateTime}.geojson',
connection='AzureWebJobsStorage',
)
def sync_power_outages(
timer: func.TimerRequest,
counties: func.Out[func.SqlRowList],
snapshot: func.Out[str],
) -> None:
# 44 is Florida's stateId. List ids with GET /outages/states.
payload = fetch(
'https://poweroutage.us/api/v2/outages/counties', {'stateId': 44, 'include': 'fips'}
).json()
generated_at = payload['meta']['generatedAt']
counties.set(func.SqlRowList(
func.SqlRow({
'CountyId': c['id'],
'Name': c['name'],
'StateId': c['stateId'],
'Fips': (c['fips'] or {}).get('full'),
'CustomersOut': c['customersOut'],
'CustomersTracked': c['customersTracked'],
'LastUpdatedAt': c['lastUpdatedAt'],
'GeneratedAt': generated_at,
})
for c in payload['data']
))
# Raw GeoJSON of active outages, one blob per run, for maps and lakehouse tools
snapshot.set(fetch('https://poweroutage.us/api/v2/geojson/outages', {'stateId': 44}).text) Step 4: Deploy it and check the data
Publish with func azure functionapp publish outage-sync from the project folder. Only one instance of a timer function runs even when the app scales out, and a new run does not start while one is still going. After the first run, the table should hold every county in the state. The gap between LastUpdatedAt and GeneratedAt shows how long ago each county was reported; a NULL LastUpdatedAt means no utility reports for it.
-- Counties with the most customers out, and minutes since a utility reported
SELECT TOP 20
Name,
CustomersOut,
CustomersTracked,
CAST(100.0 * CustomersOut / NULLIF(CustomersTracked, 0) AS DECIMAL(5, 2)) AS PctOut,
DATEDIFF(MINUTE, LastUpdatedAt, GeneratedAt) AS MinutesSinceReport
FROM dbo.CountyOutages
ORDER BY CustomersOut DESC; Step 5: No-code option: copy with Data Factory
In Azure Data Factory, create a REST linked service with the base URL https://poweroutage.us/api/v2/, authentication type Anonymous, and an auth header named Authorization whose value is Bearer <your key>, kept as a secure string or a Key Vault secret. Point a REST dataset at the relative URL outages/counties?stateId=44&include=fips and copy it into dbo.CountyOutages. In the Copy activity mapping, import schemas and set the collection reference to data so each county becomes a row. Map id to CountyId, name to Name, stateId to StateId, fips.full to Fips, customersOut to CustomersOut, customersTracked to CustomersTracked and lastUpdatedAt to LastUpdatedAt, and map $['meta']['generatedAt'] to GeneratedAt. Fields outside the collection reference repeat on every row. Use Upsert with CountyId as the key column. The REST connector accepts JSON responses only, which is what this endpoint returns by default. A schedule trigger every 15 minutes keeps it current.
Tips for Azure
- Leave
run_on_startupoff. With it on, the function also runs whenever the app restarts or scales out, which adds API calls and cost. - A failed timer run is not retried; the next scheduled run is the retry. Watch failures in Application Insights.
- If a Key Vault reference cannot be resolved, the app setting keeps the literal
@Microsoft.KeyVault(...)text and the API rejects it. Check the reference status under the app setting in the portal. - After you rotate the key in Key Vault, the app picks up the new version within 24 hours. Change any app setting to restart the app and load it at once.
- Each state can include a county named
Unknownfor customers a utility could not place in a county. ItsFipsis null.
Used by
Related integrations
FAQ
Here are some commonly asked questions
Request API access
Tell us what you're building and we'll set you up with a trial key.