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.1SdashAPI 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.2The 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.3The 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.4Here 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);
});
});