How to Get Started with the data.gov.in API

Quick summary: Querying an API-enabled resource on data.gov.in requires a valid Resource ID, an API key from your data.gov.in account, and standard query parameters such as format=json, offset, and limit. For web apps, always keep your API key on a server-side proxy rather than exposing it in browser JavaScript.
Editorial note: Data Khoj is an independent platform that indexes live metadata from data.gov.in. It is not affiliated with or endorsed by the Government of India.
Workflow diagram showing browser requests routed through a Node.js backend proxy that injects DATA_GOV_IN_API_KEY server-side before calling api.data.gov.in
Figure 1: Recommended server-side proxy pattern used by Data Khoj to keep API keys out of browser bundles.

Step 1: Obtain an Official API Key

To call the upstream Data API directly from your own backend or scripts, register on the official data.gov.in APIs portal and generate an API key in your account dashboard. Treat this key like a password: never commit it to source control, and never embed it in frontend JavaScript or HTML files.

Step 2: Protect the Key with a Backend Proxy

In a browser application, anything included in client-side requests can be inspected by users. Data Khoj routes all browser requests to same-origin endpoints such as /api/resources/{resourceId}/records while the Node.js backend injects DATA_GOV_IN_API_KEY server-side, validates parameters, enforces timeouts and rate limits, and redacts secrets from error messages.

Annotated illustrative JSON response schema showing total, count, offset, limit, fields, records, and metadata
Figure 2: Illustrative JSON response schema returned by the Data Khoj backend proxy.

Step 3: Illustrative Request Structure

The illustrative example below shows how a server-side script structures a request using placeholder values:

GET https://api.data.gov.in/resource/<your-resource-id>?api-key=<YOUR_API_KEY>&format=json&offset=0&limit=20

Understanding the Response Payload

A typical JSON response includes both data rows and structural metadata:

  • fields: Column identifiers, human-readable names, and upstream type hints.
  • records: An array of row objects matching your current page and filters.
  • offset & limit: The pagination window applied to the query.
  • total & count: Total matching records (when provided by upstream) and rows in the current response.
  • metadata: Title, organizations, source, and last-updated timestamp.