Custom Connector
Swedish Energy Agency Statistics
Sweden
The Swedish Energy Agency Statistics Connector is a specialized middleware service providing streamlined access to Sweden’s official energy statistics. It enables users to discover and explore statistical databases containing critical energy data — from consumption patterns to production figures — browsing tables, retrieving metadata, and executing queries without exposing backend complexity.
Overview
Integration Overview
This document covers the connector’s architecture, configuration, and endpoints. It supports HTTP GET and POST with automatic header propagation, parameter forwarding, and secure API-key management via environment variables.
- list_databases. Retrieves a list of available databases from the Energy API.
- list_tables. Retrieves a list of tables within a specified database.
- get_table_metadata. Retrieves metadata for a specific table within a database.
- query_table. Executes queries against a specific table using POST requests.
Documentation
Detailed Integration Documentation
Environment Configuration
| Purpose | Configures the connector with essential environment variables for API endpoints, ports, and authentication — flexible deployment without code changes. |
|---|---|
| Parameters | Required: CONNECTOR_ENV_ENERGY_BASE_URL (base URL); CONNECTOR_ENV_PORT (Flask port, e.g. 8081). Optional: CONNECTOR_ENV_ENERGY_API_KEY. |
| Behavior | The app reads configuration at startup; endpoints are configured with the specified base URL and port. |
| Workflow example | Set environment variables in the deployment environment; the application configures endpoints automatically. |
Request Forwarding Infrastructure
| Core functions | forward_get() and forward_post() |
|---|---|
| Purpose | Forwards HTTP requests to the target API, managing headers, parameters, API-key injection, and response handling. |
| Parameters | forward_get: path (required); headers; params. forward_post: path (required); headers; json_data. |
| Authentication | Automatically injects the API key from CONNECTOR_ENV_ENERGY_API_KEY into headers (Ocp-Apim-Subscription-Key) and query parameters (subscription-key). |
| Output | Successful: a Flask Response with original content, status code, and Content-Type. Failure: propagates the target API’s error response. (Note: SSL verification is disabled for debugging — enable in production.) |
Database Listing
| Action | list_databases |
|---|---|
| Endpoint | GET /api/v1/en/ |
| Purpose | Retrieves a list of available databases from the Energy API — the primary entry point for discovering data sources. |
| Parameters | Query: subscription-key. Headers: Accept (default application/json). |
| Output | Successful: JSON with the database list. Failure: error response with status code from the Energy API. |
| Workflow example | Send GET /api/v1/en/; the connector forwards with authentication and returns the response. |
Table Listing
| Action | list_tables |
|---|---|
| Endpoint | GET /api/v1/en/{database} |
| Purpose | Retrieves a list of tables within a specified database for data discovery. |
| Parameters | Path: database (required). Query: subscription-key. Headers: Accept. |
| Output | Successful: JSON with the table list. Failure: error for invalid database or authentication issues. |
| Workflow example | GET /api/v1/en/energy_db; the connector forwards to the Energy API and returns the table list. |
Table Metadata
| Action | get_table_metadata |
|---|---|
| Endpoint | GET /api/v1/en/{database}/{table} |
| Purpose | Retrieves detailed metadata for a table — columns, data types, and structure. |
| Parameters | Path: database (required); table (required). Query: subscription-key. Headers: Accept. |
| Output | Successful: JSON with the table schema and metadata. Failure: error for invalid table or access restrictions. |
| Workflow example | GET /api/v1/en/energy_consumption/household_usage to analyze columns for query planning. |
Table Query Execution
| Action | query_table |
|---|---|
| Endpoint | POST /api/v1/en/{database}/{table} |
| Purpose | Executes queries against a table using POST with a JSON payload for filters and parameters. |
| Parameters | Path: database (required); table (required). Headers: Content-Type (default application/json), Accept. Body: JSON payload with query parameters and filters. |
| Output | Successful: JSON results from the Energy API query. Failure: error response with query execution details. |
| Workflow example | POST a JSON payload to /api/v1/en/energy_consumption/household_usage with filters, sorting, and aggregation. |
Example Workflow: Energy Statistics Integration
| Discover sources | Use list_databases to fetch available databases (e.g. energy_consumption). |
|---|---|
| Explore structure | Use list_tables with database=energy_consumption to review available tables. |
| Understand schema | Use get_table_metadata for a table to analyze columns and data types. |
| Query & integrate | Use query_table with a JSON payload, then connect BI tools and automate reporting pipelines. |
Support
For technical support, contact custom-connectors-support@isolutions.sa.