> For the complete documentation index, see [llms.txt](https://docs.humdata.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.humdata.org/build/hdx-apis/tabular-data-endpoints/how-to-query-the-tabular-data-endpoints.md).

# How to query the Tabular Data Endpoints

How to use the different Tabular Data endpoints

There are three ways that the Tabular Data endpoints can be queried, each accessed via it's own endpoint. See below:

1. **Schema Information (`datastore_info`):** This endpoint returns information about the data within the resource, including its data dictionary. A data dictionary describes each column in the resource: its name, data type and, where provided by the contributor, a human-readable label and description.
   1. Use `datastore_info` for simple information on the data resources.
2. **Native (`datastore_search`):** This endpoint provides a simple, URL-based interface for querying records within a data resource. If you are starting out with APIs, this is the one you should use. It supports standard functionality including filtering by field values, text search, pagination, field selection, and sorting.
   1. Use `datastore_search` when working with simple filters, browsing data, or building lightweight applications or a Power BI dashboard.
3. **SQL (`datastore_search_sql`):** This endpoint allows for more advanced querying using full SQL syntax. It is useful when complex conditions like aggregations, or joins within multiple resources are needed. It offers greater flexibility but also requires a proper understanding of SQL.
   1. Use `datastore_search_sql` for more analytical purposes or when multiple conditions and calculations are required.

For more detailed information, please see the [CKAN DataStore API documentation](https://docs.ckan.org/en/2.9/maintaining/datastore.html#the-datastore-api).

#### 1. Query requests: Schema information <a href="#id-1.-api-requests-schema-information" id="id-1.-api-requests-schema-information"></a>

This is a basic information endpoint which simply returns information about the data resource. This can be used to learn more about the data dictionary of the resource. More precisely, for each column it returns its column name (`id`), data type (`type`), title (`info.label`) and description (`info.notes`).

In the HDX UI, this information appears in the [data dictionary section of the resource page](https://docs.humdata.org/find/understanding-the-hdx-dataset-page#data-dictionary). Here is how the fields from the API response match the data dictionary table on the resource page:

| Resource page | API response key | Description                                                                                                                     |
| ------------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------- |
| Title         | `info.label`     | A human-readable title for the column.                                                                                          |
| Column name   | `id`             | The column name as it is stored in TDE.                                                                                         |
| Data type     | `type`           | How the column is stored, for example text, numeric or timestamp. This determines which filters and SQL operations you can use. |
| Description   | `info.notes`     | An explanation of what the column represents.                                                                                   |

The API calls the title `label` and the description `notes`, so the names differ from those on the resource page.

Besides the endpoint, you need the token and the `resource_id` to make a query.

**Endpoint**

`GET /datastore_info`

Like the other Tabular Data Endpoints, this request requires your HDX API token in the Authorization header. See [Code examples](https://docs.humdata.org/build/hdx-apis/tabular-data-endpoints/code-examples.md) for how to pass it.

#### 2. Query requests: Native <a href="#id-2.-api-requests-native" id="id-2.-api-requests-native"></a>

With the **endpoint**, **token**, and **resource\_id**, you can now query data using standard API calls by configuring the URL like follows:

**Endpoint**

`https://data.humdata.org/api/3/action/datastore_search`

**Example:** Retrieve the rows in a dataset where the country is “Kenya” for 2024.

`https://data.humdata.org/api/3/action/datastore_search?id=<resource_id>&filters={"country":"Kenya",”year”:2024}`

**Common parameters (see** [**the CKAN DataStore documentation**](https://docs.ckan.org/en/latest/maintaining/datastore.html#ckanext.datastore.logic.action.datastore_search) **for more details)**

| `resource_id` | <mark style="color:$danger;">\[Required] The resource unique identifier</mark>                              |
| ------------- | ----------------------------------------------------------------------------------------------------------- |
| `limit`       | Maximum number of results to return                                                                         |
| `offset`      | Start index for pagination                                                                                  |
| `q`           | Search across all data (can pass as dictionary to limit to a specific column)                               |
| `filters`     | ​[Filter specific fields](https://docs.ckan.org/en/latest/maintaining/datastore.html#filters) (exact match) |
| `fields`      | Limit which columns are returned                                                                            |
| `sort`        | Sort results                                                                                                |

#### 3. Query Requests: SQL <a href="#id-3.-api-requests-sql" id="id-3.-api-requests-sql"></a>

For more advanced API queries, the SQL API supports a full subset of PostgreSQL syntax. It's ideal for advanced queries, aggregations, joins (within limits), and complex filters. It also requires the **endpoint**, **token**, and **resource\_id**.

**Endpoint**

`GET /datastore_search_sql`

**Parameters:** `sql` (Required) A SQL query string. Must reference the correct resource (table name is the `resource_id`).

**Example: WHERE clause**

`https://data.humdata.org/api/3/action/datastore_search_sql?sql=SELECT+*+FROM+"id"+WHERE+country='Kenya'+AND+year=2024`

**Example SQL Query**

`SELECT country, AVG(value) FROM "id" WHERE indicator = 'population' AND year = 2024 GROUP BY country`

Note: Be sure to URL-encode your SQL queries when sending them via GET (e.g. urlib.parse in Python).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.humdata.org/build/hdx-apis/tabular-data-endpoints/how-to-query-the-tabular-data-endpoints.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
