Skip to main content

Overview

The GSS StatsBank API is built on PxWeb technology, a standard used by many statistical agencies worldwide. Think of the API like a file explorer on your computer: it has a hierarchy of “folders” (Databases and Levels) that eventually lead to “files” (Tables).

Prerequisites

Before connecting to the API, ensure you have the required R packages installed:
library(httr2)
library(tidyverse)
The httr2 package handles HTTP requests and responses, while tidyverse is used for data manipulation tasks.

Establishing the Connection

1

Define the Base URL

Start by setting up the base URL for the GSS StatsBank API:
URL = "https://statsbank.statsghana.gov.gh:443/api/v1/en/"
request = request(URL)
This creates a request object that you’ll use to interact with the API.
2

Test the Connection

Perform a simple request to verify the connection is working:
response = request |> 
    req_perform()

response |> 
    resp_body_json()
This should return a list of available databases in the StatsBank system.
3

View Available Databases

The response will show all accessible databases:
[[1]]
[[1]]$dbid
[1] "Annual Household Income and Expenditure Survey (AHIES)"

[[2]]
[[2]]$dbid
[1] "Education(Admin)"

[[7]]
[[7]]$dbid
[1] "PHC 2021 StatsBank"

# ... more databases
Each database contains organized datasets on specific topics.

Understanding the API Structure

The GSS StatsBank API follows a hierarchical structure:
  • Root Level: Lists all available databases
  • Database Level: Contains topic folders (e.g., “Water and Sanitation”, “Education”)
  • Topic Level: Contains individual data tables (ending in .px)
  • Table Level: Contains the actual data and metadata
Think of navigating the API like browsing folders on your computer. You start at the root, open a database folder, then a topic folder, and finally access a specific table file.

Common Databases

Here are some frequently used databases available through the API:
DatabaseDescription
PHC 2021 StatsBank2021 Population and Housing Census data
PHC20102010 Population and Housing Census data
GLSS7Ghana Living Standards Survey Round 7
Annual Household Income and Expenditure Survey (AHIES)Household income and expenditure data
Ghana Census of Agriculture (GCA)Agricultural census data
Macroeconomic IndicatorsEconomic indicators and statistics
Some databases may have similar names (e.g., “Macro Economic Indicators” vs “Macroeconomic Indicators”). Always verify the exact dbid value when constructing your API paths.

Next Steps

Now that you’ve established a connection to the API, you’re ready to navigate through databases to find the specific tables you need. See the Navigating Databases guide to learn how to explore the API structure and locate specific data tables.

Build docs developers (and LLMs) love