Partner API
Read-only access to Digital Mandi's crop, feed mill and sugar mill rates from across Pakistan, for integration into your own products.
| Base URL | https://partners.digitalmandi.online |
|---|---|
| Format | JSON over HTTPS. Only GET requests are used. |
| Authentication | API key in the X-API-Key header |
| Prices | Pakistani Rupees (PKR). Crop rates are PKR per 40 kg (maund). |
| Time zone | Dates and quota resets use Asia/Karachi (PKT, UTC+5). |
Getting access
API keys are issued by the Digital Mandi team.
Each key has:
- a set of endpoints it may call (calling any other returns
403 endpoint_not_allowed), - a per-minute rate limit and, usually, a daily and/or monthly quota,
- optionally, an IP allowlist and an expiry date.
Call GET /v1/me any time to see your key's current settings and usage.
Authentication
Send your key with every request in the X-API-Key header. Authorization: Bearer <key> is also accepted. Keys start with dm_live_.
curl -H "X-API-Key: dm_live_your_key_here" \
"https://partners.digitalmandi.online/v1/crop-rates/latest?crop_id=1"$ch = curl_init('https://partners.digitalmandi.online/v1/crop-rates/latest?crop_id=1');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['X-API-Key: ' . getenv('DIGITAL_MANDI_API_KEY')],
CURLOPT_TIMEOUT => 15,
]);
$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);
$json = json_decode($body, true);
if ($status !== 200) {
throw new RuntimeException($json['error']['code'] . ': ' . $json['error']['message']);
}
foreach ($json['data'] as $rate) {
echo $rate['crop_type']['name'], ' @ ', $rate['city']['name'], ': ',
$rate['min_price'], ' - ', $rate['max_price'], PHP_EOL;
}const res = await fetch('https://partners.digitalmandi.online/v1/crop-rates/latest?crop_id=1', {
headers: { 'X-API-Key': process.env.DIGITAL_MANDI_API_KEY },
});
const json = await res.json();
if (!res.ok) throw new Error(`${json.error.code}: ${json.error.message}`);
for (const rate of json.data) {
console.log(rate.crop_type.name, rate.city.name, rate.min_price, rate.max_price);
}import os, requests
res = requests.get(
"https://partners.digitalmandi.online/v1/crop-rates/latest",
params={"crop_id": 1},
headers={"X-API-Key": os.environ["DIGITAL_MANDI_API_KEY"]},
timeout=15,
)
json = res.json()
if not res.ok:
raise RuntimeError(f"{json['error']['code']}: {json['error']['message']}")
for rate in json["data"]:
print(rate["crop_type"]["name"], rate["city"]["name"], rate["min_price"], rate["max_price"])Responses & data
Successful responses are 200 OK with a JSON object. The result is in data (a list, or an object for /v1/me), and meta holds the row count and context such as currency and unit.
{
"data": [ ... ],
"meta": { "count": 42, "currency": "PKR", "unit": "PKR per 40 kg (maund)" }
}
- Names are given in English (
name) and Urdu (name_ur). min_price/max_priceare the lowest and highest price reported for that day.previous_min_price/previous_max_priceare from the previous reported day, so you can show the change.- Dates are
YYYY-MM-DD. Timestamps are ISO 8601 with offset. - Mandi rates are reported throughout the day, mostly in the morning. Responses can be up to 5 minutes behind the latest update.
- Fields may be added to responses in v1 at any time. Make your parser ignore fields it does not know.
Rate limits & quotas
Every successful response includes headers that show where you stand:
| Header | Meaning |
|---|---|
X-RateLimit-Limit | Requests allowed per minute for your key. |
X-RateLimit-Remaining | Requests left in the current minute. |
X-Quota-Daily-Limit | Requests allowed per day (only if your key has a daily quota). |
X-Quota-Daily-Remaining | Requests left today. |
When a limit is reached the API returns 429 Too Many Requests with a Retry-After header (seconds). Wait that long before retrying. Daily quotas reset at midnight PKT and monthly quotas on the 1st of the month. Requests rejected by authentication or limits (401, 403 and 429 responses) do not count towards your quota. All other requests do, including 422 validation errors.
Errors
Errors use the matching HTTP status and a body like this:
{
"error": {
"code": "endpoint_not_allowed",
"message": "This API key does not have access to this endpoint."
}
}
Validation errors (422) also include fields, with the messages for each invalid parameter. Branch on code, not on the message text.
| Status | code | What to do |
|---|---|---|
| 401 | missing_api_key | Send the X-API-Key header. |
| 401 | invalid_api_key | Check the key. It may have been replaced by a new one. |
| 403 | key_suspended | Your access is paused. Contact Digital Mandi. |
| 403 | key_expired | Your key's validity period has ended. Contact Digital Mandi. |
| 403 | ip_not_allowed | Call from an allowlisted server IP, or ask for your IP to be added. |
| 403 | endpoint_not_allowed | Your key cannot use this endpoint. Ask for access if you need it. |
| 404 | not_found | Unknown URL, or an id (e.g. crop_type_id) that does not exist. |
| 422 | validation_failed | Fix the parameters listed in fields. |
| 429 | rate_limited | Per-minute limit reached. Wait for Retry-After. |
| 429 | daily_quota_exceeded | Daily quota used up. It resets at midnight PKT. |
| 429 | monthly_quota_exceeded | Monthly quota used up. It resets on the 1st. |
| 429 | too_many_failed_attempts | Too many requests with an invalid key from your IP. Fix the key and wait a minute. |
| 5xx | server_error / unavailable | Our problem. Retry with exponential backoff (e.g. 2s, 4s, 8s). |
Best practices
- Cache on your side. Rates change a few times a day, so polling every 5 to 15 minutes is plenty. Cache
/v1/cropsand/v1/citiesfor a day. - Use filters (
crop_id,city_id) instead of downloading everything and filtering locally. - Honour
Retry-Afteron 429s, and back off on 5xx errors. Do not retry 4xx errors other than 429 without changing the request. - Store the key in an environment variable or secret manager, not in code.
- Show attribution to Digital Mandi wherever the rates are displayed, unless your agreement says otherwise.
Your key and usage
Details of the key making the request: its status, which endpoints it can call, its limits, and how much of its quota is used. Every valid key can call this, and calls to it count towards the quota like any other request.
Query parameters
None.
Example request
curl -H "X-API-Key: $DIGITAL_MANDI_API_KEY" "https://partners.digitalmandi.online/v1/me"
Example response
{
"data": {
"name": "Acme Agri Integration",
"company": "Acme Pvt Ltd",
"key_prefix": "dm_live_a1b2c3",
"status": "active",
"expires_at": null,
"allowed_endpoints": [
"crops",
"cities",
"crop-rates.latest"
],
"limits": {
"requests_per_minute": 60,
"daily_quota": 5000,
"monthly_quota": null
},
"usage": {
"today": 132,
"this_month": 2841
}
}
}
crops
List crops and crop types
All active crops with their types (varieties). Use the type ids as crop_type_id in the rate endpoints. This list changes rarely, so cache it on your side for a day.
Query parameters
None.
Example request
curl -H "X-API-Key: $DIGITAL_MANDI_API_KEY" "https://partners.digitalmandi.online/v1/crops"
Example response
{
"data": [
{
"id": 1,
"name": "Wheat",
"name_ur": "گندم",
"types": [
{
"id": 4,
"name": "Wheat (New)",
"name_ur": "گندم نئی"
}
]
}
],
"meta": {
"count": 1
}
}
cities
List cities (mandis)
All cities (mandis) that rates are reported for. Use the ids as city_id. Cache this on your side for a day.
Query parameters
None.
Example request
curl -H "X-API-Key: $DIGITAL_MANDI_API_KEY" "https://partners.digitalmandi.online/v1/cities"
Example response
{
"data": [
{
"id": 12,
"name": "Okara",
"name_ur": "اوکاڑہ"
}
],
"meta": {
"count": 1
}
}
crop-rates.latest
Latest crop rates per city
Current mandi rates: one row per crop type per city. For each crop type, the rows are from the most recent day that type had any rate reported (filtered by your city_id if given), so different crop types can have different rate_date values. Pass date to get a specific day instead.
Query parameters
| Name | Type | Required | Description |
|---|---|---|---|
crop_id | integer | No | Only types of this crop. |
crop_type_id | integer | No | Only this crop type. |
city_id | integer | No | Only this city. The latest day is then the latest day for this city. |
date | YYYY-MM-DD | No | Rates for this exact day instead of the latest day. |
Example request
curl -H "X-API-Key: $DIGITAL_MANDI_API_KEY" "https://partners.digitalmandi.online/v1/crop-rates/latest?crop_id=1&city_id=12"
Example response
{
"data": [
{
"rate_date": "2026-11-23",
"crop": {
"id": 1,
"name": "Wheat",
"name_ur": "گندم"
},
"crop_type": {
"id": 4,
"name": "Wheat (New)",
"name_ur": "گندم نئی"
},
"city": {
"id": 12,
"name": "Okara",
"name_ur": "اوکاڑہ"
},
"min_price": 3850,
"max_price": 4000,
"previous_min_price": 3800,
"previous_max_price": 3950
}
],
"meta": {
"count": 1,
"currency": "PKR",
"unit": "PKR per 40 kg (maund)"
}
}
crop-rates.summary
Latest national min/max per crop type
One row per crop type with the nationwide lowest and highest price on that type's most recent market day, and how many cities reported. This is the headline rate shown in the Digital Mandi app.
Query parameters
| Name | Type | Required | Description |
|---|---|---|---|
crop_id | integer | No | Only types of this crop. |
Example request
curl -H "X-API-Key: $DIGITAL_MANDI_API_KEY" "https://partners.digitalmandi.online/v1/crop-rates/summary?crop_id=1"
Example response
{
"data": [
{
"rate_date": "2026-11-23",
"crop": {
"id": 1,
"name": "Wheat",
"name_ur": "گندم"
},
"crop_type": {
"id": 4,
"name": "Wheat (New)",
"name_ur": "گندم نئی"
},
"min_price": 3700,
"max_price": 4100,
"previous_min_price": 3650,
"previous_max_price": 4050,
"cities_reported": 18
}
],
"meta": {
"count": 1,
"currency": "PKR",
"unit": "PKR per 40 kg (maund)"
}
}
crop-rates.history
Daily rate history for a crop type
Daily lowest and highest price for one crop type over a date range, for one city or across all cities. Days with no reported rate are left out. Defaults to the last 30 days.
The range may cover at most 366 days per request.
Query parameters
| Name | Type | Required | Description |
|---|---|---|---|
crop_type_id | integer | Yes | The crop type. |
city_id | integer | No | One city. Leave out for all cities combined. |
from | YYYY-MM-DD | No | First day (default: 29 days before "to"). |
to | YYYY-MM-DD | No | Last day (default: today). |
Example request
curl -H "X-API-Key: $DIGITAL_MANDI_API_KEY" "https://partners.digitalmandi.online/v1/crop-rates/history?crop_type_id=4&from=2026-11-01&to=2026-11-23"
Example response
{
"data": [
{
"rate_date": "2026-11-22",
"min_price": 3650,
"max_price": 4050,
"cities_reported": 16
},
{
"rate_date": "2026-11-23",
"min_price": 3700,
"max_price": 4100,
"cities_reported": 18
}
],
"meta": {
"count": 2,
"crop": {
"id": 1,
"name": "Wheat",
"name_ur": "گندم"
},
"crop_type": {
"id": 4,
"name": "Wheat (New)",
"name_ur": "گندم نئی"
},
"city": null,
"from": "2026-11-01",
"to": "2026-11-23",
"currency": "PKR",
"unit": "PKR per 40 kg (maund)"
}
}
feed-mill-rates
Latest feed mill rates
The latest rate posted by each active feed mill.
Query parameters
| Name | Type | Required | Description |
|---|---|---|---|
city_id | integer | No | Only mills in this city. |
Example request
curl -H "X-API-Key: $DIGITAL_MANDI_API_KEY" "https://partners.digitalmandi.online/v1/feed-mill-rates"
Example response
{
"data": [
{
"id": 3,
"name": "Example Mills",
"name_ur": "مثال ملز",
"city": {
"id": 7,
"name": "Faisalabad",
"name_ur": "فیصل آباد"
},
"min_price": 4100,
"max_price": 4250,
"previous_min_price": 4050,
"previous_max_price": 4200,
"updated_at": "2026-11-23T10:15:00+05:00"
}
],
"meta": {
"count": 1,
"currency": "PKR"
}
}
sugar-mill-rates
Latest sugar mill rates
The latest rate posted by each active sugar mill.
Query parameters
| Name | Type | Required | Description |
|---|---|---|---|
city_id | integer | No | Only mills in this city. |
Example request
curl -H "X-API-Key: $DIGITAL_MANDI_API_KEY" "https://partners.digitalmandi.online/v1/sugar-mill-rates"
Example response
{
"data": [
{
"id": 3,
"name": "Example Sugar Mills",
"name_ur": "مثال ملز",
"city": {
"id": 7,
"name": "Faisalabad",
"name_ur": "فیصل آباد"
},
"min_price": 4100,
"max_price": 4250,
"previous_min_price": 4050,
"previous_max_price": 4200,
"updated_at": "2026-11-23T10:15:00+05:00"
}
],
"meta": {
"count": 1,
"currency": "PKR"
}
}
Versioning & changes
The version is part of the URL (/v1). Within v1 we only make backward-compatible changes: new endpoints, new optional parameters and new response fields. Anything that would break existing integrations, such as removing or renaming a field or changing its type, will ship as /v2, and v1 will keep running alongside it for a notice period.