Integration
Automating Calculations
Price records from your own systems (meter exports, fuel cards, travel bookings) by calling the calculate endpoints from a script or a job.
How it works
- Send one request per record. Each record maps to one endpoint: electricity, fuel, flight or spend.
- Keep the response next to the record: the factor, its source and the formula are what an auditor will ask for.
- Treat a
422refusal as data to fix, not an error to retry: itscodeandguidancesay what is missing. - With an API key you can send 120 requests per minute per endpoint. Without one, about 100 per hour per IP.
The API calculates; it does not write to your company's ledger. Recording activity in ZeroCarbon is done in the app.
Example: a CSV of fuel purchases
fuel.csvbash
date,fuel_type,amount,unit
2026-09-03,diesel,420,L
2026-09-10,lpg,95,kg
2026-09-17,kerosene,30,Lprice_fuel.pypython
import csv, os, time
import requests
URL = "https://zerocarbon.org.in/api/v1/calculate/fuel"
headers = {}
if os.environ.get("ZEROCARBON_API_KEY"):
headers["Authorization"] = "Bearer " + os.environ["ZEROCARBON_API_KEY"]
with open("fuel.csv", newline="") as f:
for row in csv.DictReader(f):
payload = {"fuel_type": row["fuel_type"], "amount": float(row["amount"]),
"unit": row["unit"], "country": "IN"}
res = requests.post(URL, json=payload, headers=headers, timeout=30)
body = res.json()
if res.status_code == 429:
raise SystemExit("Rate limit reached; retry later or use an API key")
if body.get("success"):
d = body["data"]
print(row["date"], d["emissions_kg_co2e"], "kg CO2e |", d["formula"])
else:
code = body["code"] if isinstance(body.get("error"), str) else body["error"]["code"]
print(row["date"], "REFUSED", code)
time.sleep(0.5) # stays under 120 requests/minuteoutputbash
2026-09-03 1128.941 kg CO2e | 420 liter × 2.687954 kgCO2e/liter = 1128.9410 kgCO2e
2026-09-10 283.752 kg CO2e | 95 kg × 2.986866 kgCO2e/kg = 283.7523 kgCO2e
2026-09-17 REFUSED unsupported_inputKerosene is refused because the library holds no published factor for it yet; the record is reported, not estimated.