Skip to content

Jobs API

POST /jobs

Submit a transport job and receive an NGER Method 1 emission calculation.

POST https://<project-ref>.supabase.co/functions/v1/jobs-api/jobs
Authorization: Bearer ew_<your-api-key>
Content-Type: application/json

Request body

json
{
  "job": {
    "origin": "string",
    "destination": "string",
    "reference_number": "string (optional)",
    "client_id": "uuid (optional)",
    "distance": 0,
    "departure_date": "2024-08-01T06:00:00Z",
    "arrival_date": "2024-08-01T18:00:00Z",
    "cargo_weight_tonnes": 0
  },
  "calculation": {
    "transport_mode": "road",
    "fuel_type": "diesel",
    "vehicle_class": "heavy_vehicle_euro4",
    "fuel_quantity": 85.4
  }
}

job object fields

FieldTypeRequiredConstraintsDescription
originstringYesNon-emptyOrigin location
destinationstringYesNon-emptyDestination location
reference_numberstringNoIdempotency key. Duplicate submissions with the same value return the original result
client_idUUIDNoMust exist in your orgLinks the job to a client for per-client reporting
distancenumberNo0–99,999Distance in km (stored, not used in calculation)
departure_dateISO 8601NoUsed to determine the NGER reporting year. Preferred over arrival_date
arrival_dateISO 8601NoFallback date for reporting year if departure_date is absent
cargo_weight_tonnesnumberNoCargo weight in tonnes (stored, not used in calculation)

calculation object fields

FieldTypeRequiredConstraintsDescription
transport_modestringYesSee table belowTransport mode code
fuel_typestringYesMust be valid for the modeFuel type code
fuel_quantitynumberYes> 0, ≤ 999,999Fuel consumed in kilolitres (kL)
vehicle_classstringConditionalSee table belowRequired for road diesel; recommended for all

Valid transport mode / fuel type / vehicle class combinations

transport_modefuel_typevehicle_classNotes
roaddieselheavy_vehicle_euro4Euro IV+ heavy vehicles (post-2006)
roaddieselheavy_vehicle_euro3Euro III heavy vehicles (~2001–2006)
roaddieselheavy_vehicle_euro1Euro I heavy vehicles (~pre-2001)
roaddiesellight_vehicle_post2004_dieselDiesel light vehicles post-2004
roaddieselroad_vehicle_unspecified_dieselDiesel vehicles, pre-2004 or unknown standard
roadpetrollight_vehicle_post2004_petrolPetrol light vehicles post-2004
roadpetrolroad_vehicle_unspecified_petrolPetrol vehicles, pre-2004 or unknown
roadlpglight_vehicle_post2004_lpgLPG light vehicles post-2004
raildiesel_raildiesel_locomotiveDiesel rail traction
aviationjet_a1jet_aircraftJet kerosene aircraft
aviationavgasturbopropAvgas / turboprop aircraft
seahfovessel_fuel_oilHeavy fuel oil vessels
seamdovessel_dieselMarine diesel oil vessels

The API accepts both type codes (e.g. road) and display names (e.g. Road) — matching is case-insensitive.

Success response — 201 Created

json
{
  "success": true,
  "idempotent": false,
  "job_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
  "calculation_id": "7c9e6679-7425-40de-944b-e07fc1f90ae7",
  "reporting_year": 2025,
  "emissions": {
    "total_emissions": 22.87,
    "scope1_emissions": 22.20,
    "scope3_emissions": 0.67,
    "co2_emissions": 22.07,
    "ch4_emissions": 0.02,
    "n2o_emissions": 0.13,
    "energy_content": 3296.44
  },
  "transport_info": {
    "transport_mode": "Road",
    "transport_code": "road",
    "fuel_type": "Diesel",
    "fuel_code": "diesel"
  }
}

All emission values are in tonnes CO₂-e. energy_content is in GJ.

When an idempotent duplicate is detected, the response is 200 OK with "idempotent": true and the original job_id, calculation_id, and emission values.

Example request

bash
curl -X POST https://<project-ref>.supabase.co/functions/v1/jobs-api/jobs \
  -H "Authorization: Bearer ew_abc123..." \
  -H "Content-Type: application/json" \
  -d '{
    "job": {
      "origin": "Sydney",
      "destination": "Melbourne",
      "reference_number": "TRP-20240801-001",
      "distance": 869,
      "departure_date": "2024-08-01T06:00:00Z",
      "cargo_weight_tonnes": 22.5
    },
    "calculation": {
      "transport_mode": "road",
      "fuel_type": "diesel",
      "vehicle_class": "heavy_vehicle_euro4",
      "fuel_quantity": 85.4
    }
  }'

Error responses

401 — Missing or invalid API key

json
{
  "error": "Missing Authorization header",
  "code": "UNAUTHORIZED",
  "details": {}
}

400 — Validation error

json
{
  "error": "fuel_quantity must be greater than 0",
  "code": "VALIDATION_ERROR",
  "details": {
    "fields": [
      { "field": "fuel_quantity", "message": "fuel_quantity must be greater than 0" }
    ]
  }
}

422 — Vehicle class required

json
{
  "error": "Multiple factors exist — specify vehicle_class",
  "code": "VEHICLE_CLASS_REQUIRED",
  "details": {
    "available_classes": [
      { "class_code": "heavy_vehicle_euro4", "display_name": "Heavy vehicle — Euro IV or higher" },
      { "class_code": "heavy_vehicle_euro3", "display_name": "Heavy vehicle — Euro III" },
      { "class_code": "heavy_vehicle_euro1", "display_name": "Heavy vehicle — Euro I" },
      { "class_code": "light_vehicle_post2004_diesel", "display_name": "Light vehicle — post-2004 (diesel)" },
      { "class_code": "road_vehicle_unspecified_diesel", "display_name": "Road vehicle — unspecified/pre-2004 (diesel)" }
    ]
  }
}

422 — No emission factor found

json
{
  "error": "No emission factor found for reporting year 2022",
  "code": "FACTOR_NOT_FOUND",
  "details": {
    "reporting_year": 2022,
    "transport_mode": "road",
    "fuel_type": "diesel"
  }
}

429 — Rate limit exceeded

json
{
  "error": "Rate limit exceeded. Maximum 1000 requests per hour per API key.",
  "code": "RATE_LIMITED",
  "details": {
    "limit": 1000,
    "reset": "2024-08-01T09:00:00.000Z"
  }
}

NGER Transport Emissions Platform