This API allows authorized clients to retrieve farm data as JSON or CSV. It is strictly read-only (no create/update/delete operations).
All requests (except /health) require the header:
X-API-Key
1) Health (no key required)
GET https://api.dairystash.com/api/health2) Verify your key
GET https://api.dairystash.com/api/whoami3) Query data (JSON default)
GET https://api.dairystash.com/api/farms/<farm_code>/events/<event_name>?limit=100If the farm code in the URL does not match the farm code embedded in the API key, the API returns 403 Forbidden.
| Method | Path | Description | Requires Key |
|---|---|---|---|
| GET | /health |
Service status | No |
| GET | /whoami |
Returns the farm_code linked to your API key | Yes |
| GET | /farms/<farm_code>/events/<event_name> |
Fetch data from an allowed table/event | Yes |
Header:
X-API-Key: FARM.<farm_code>.<kid>.<signature>
| Parameter | Example | Description |
|---|---|---|
format |
format=json / format=csv |
Output format. Default is json. |
limit |
limit=1000 |
Max rows returned per request. (Server enforces a max limit.) |
offset |
offset=0 |
Pagination start offset. |
order_by |
order_by=-date |
Sort results. Use - for descending (e.g. -created_at). |
fields |
fields=id,date,value |
Comma-separated list of columns to return (only allowed columns). |
filters |
filters=date__gte=2025-01-01 |
Repeatable param. Supported:
=, __gte, __lte, __like.
Example: filters=status=OK
|
Notes:
• If you request fields/filters/order_by on columns not allowed by the server whitelist, the API returns 400 Bad Request.
• If you request an event/table not allowed for that farm, the API returns 404 or 403 depending on configuration.
JSON
curl -H "X-API-Key: FARM.<farm_code>.k1.<signature>" ^
"https://api.dairystash.com/api/farms/<farm_code>/events/inventory?format=json&limit=100"CSV download
curl -H "X-API-Key: FARM.<farm_code>.k1.<signature>" ^
"https://api.dairystash.com/api/farms/<farm_code>/events/inventory?format=csv&limit=1000" ^
-o data.csvFields + filters + ordering
curl -H "X-API-Key: FARM.<farm_code>.k1.<signature>" ^
"https://api.dairystash.com/api/farms/<farm_code>/events/inventory?format=json&fields=id,date,pen&filters=date__gte=2025-01-01&order_by=-date&limit=500"JSON → save to data.json
import requests, json
BASE_URL = "https://api.dairystash.com/api"
FARM_CODE = "93003333"
API_KEY = "FARM.93003333.k1.<signature>"
url = f"{BASE_URL}/farms/{FARM_CODE}/events/inventory?format=json&limit=100"
headers = {"X-API-Key": API_KEY}
r = requests.get(url, headers=headers, timeout=60)
r.raise_for_status()
with open("data.json", "w", encoding="utf-8") as f:
json.dump(r.json(), f, ensure_ascii=False, indent=2)
print("Saved data.json")CSV → save to data.csv
Tip: Use stream=True to avoid “Response ended prematurely” on large downloads.
import requests
BASE_URL = "https://api.dairystash.com/api"
FARM_CODE = "93003333"
API_KEY = "FARM.93003333.k1.<signature>"
url = f"{BASE_URL}/farms/{FARM_CODE}/events/inventory?format=csv&limit=5000"
headers = {"X-API-Key": API_KEY}
with requests.get(url, headers=headers, timeout=300, stream=True) as r:
r.raise_for_status()
with open("data.csv", "wb") as f:
for chunk in r.iter_content(chunk_size=1024 * 256):
if chunk:
f.write(chunk)
print("Saved data.csv")Best practice: Load CSV for large tables. Excel can also load JSON, but CSV is simpler.
Option 1: CSV (recommended)
https://api.dairystash.com/api/farms/93003333/events/inventory?format=csv&limit=1000
X-API-Key = FARM.93003333.k1.<signature>
If you don’t see “Advanced” header options
That depends on your Excel version. Alternative approach:
• Download the CSV via browser or Python, then Excel → Data → From Text/CSV.
Option 2: Import downloaded CSV
data.csv → LoadRecommended approach: Use Web connector with a custom header, or fetch CSV and load it.
Power BI (Web) — add header
let
Source = Web.Contents(
"https://api.dairystash.com/api/farms/93003333/events/inventory?format=csv&limit=1000",
[
Headers = [
#"X-API-Key" = "FARM.93003333.k1.<signature>"
]
]
),
Csv = Csv.Document(Source, [Delimiter=",", Encoding=65001, QuoteStyle=QuoteStyle.Csv]),
Promoted = Table.PromoteHeaders(Csv, [PromoteAllScalars=true])
in
Promoted
If you prefer JSON, you can use Json.Document(Source) — but CSV is usually easier for tables.
| Status | Meaning | Common cause |
|---|---|---|
| 200 | Success | Request accepted |
| 400 | Bad Request | Invalid fields/filters/order_by not allowed |
| 401 | Unauthorized | Missing X-API-Key |
| 403 | Forbidden | API key farm code does not match URL farm code |
| 404 | Not Found | Event/table not allowed or does not exist |
| 500 | Server Error | Unexpected error; contact support |
Need access or help? Email: support@dpnconnect.com