API Documentation

DairyStash Farm Data API (Read-only)

This API allows authorized clients to retrieve farm data as JSON or CSV. It is strictly read-only (no create/update/delete operations).

Base URL: https://api.dairystash.com/api/ Auth: X-API-Key header Formats: json | csv
  • Read-only

    Only SELECT queries are allowed
  • Per-farm keys

    Keys are scoped to one farm code
  • Exports

    JSON for apps, CSV for analysts

Quick Start

All requests (except /health) require the header: X-API-Key

1) Health (no key required)

GET https://api.dairystash.com/api/health

2) Verify your key

GET https://api.dairystash.com/api/whoami

3) Query data (JSON default)

GET https://api.dairystash.com/api/farms/<farm_code>/events/<event_name>?limit=100

If the farm code in the URL does not match the farm code embedded in the API key, the API returns 403 Forbidden.

Endpoints

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>

Query Parameters

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.

Examples (cURL)

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.csv

Fields + 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"

Examples (Python)

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")

Excel (Power Query)

Best practice: Load CSV for large tables. Excel can also load JSON, but CSV is simpler.

Option 1: CSV (recommended)

  1. Open Excel → Data tab
  2. Click Get DataFrom Other SourcesFrom Web
  3. Paste URL like:
    https://api.dairystash.com/api/farms/93003333/events/inventory?format=csv&limit=1000
  4. When prompted for credentials, choose Anonymous (Power Query will still send headers via Advanced options)
  5. If available, open Advanced options and add a header:
    X-API-Key = FARM.93003333.k1.<signature>
  6. Click OK → Load

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

  1. Download CSV (browser or Python)
  2. Excel → Data → From Text/CSV
  3. Select data.csv → Load

Power BI

Recommended 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.

Responses & Errors

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