Guide 2.6: Developer Guide

Fetching Subjects

Before you can query for specific past questions, your application needs to know which subjects are available in the SdashAPI database. Hardcoding subjects in your frontend can lead to bugs if we add new subjects later. Instead, you should fetch the available subjects dynamically.

The Subjects Endpoint

2.6.1

SdashAPI provides a dedicated endpoint to retrieve the master list of all supported subjects. You can access it via a standard GET request.

GET https://sdashapi.com/api/v1/subjects

Understanding the Response

2.6.2

The API will return a JSON array containing objects. Each object represents a single subject, providing its human-readable name and the URL-friendly slug.

{
  "status": 200,
  "data": [
    { "id": 1, "name": "Biology", "slug": "biology" },
    { "id": 2, "name": "Chemistry", "slug": "chemistry" },
    { "id": 3, "name": "Computer Studies", "slug": "computer" }
    // ... more subjects
  ]
}

Why the Slug Matters

2.6.3

The name property (e.g., "Computer Studies") is what you should display to your users in dropdown menus or lists. However, the slug property (e.g., "computer") is the exact string you must use as the subject parameter when querying the /q endpoints later. Never use the human-readable name in your API queries!

Implementation Example

2.6.4

Here is how you might populate an HTML <select> dropdown using JavaScript and the Fetch API.

fetch('https://sdashapi.com/api/v1/subjects', {
  headers: { "AccessToken": "YOUR_KEY" }
})
.then(res => res.json())
.then(json => {
  const select = document.getElementById('subjectDropdown');
  json.data.forEach(subject => {
    // Value is the slug, text is the human-readable name
    const option = new Option(subject.name, subject.slug);
    select.add(option);
  });
});

Want to filter by year?

Next, we will look at how to retrieve the available examination years.

Next Guide: Fetching Exam Years →
Avatar

How can we help?

We reply immediately

Hello! 👋 How can we help you today?