Skip to main content

buildNSupplyRequest

@nmi-agro/fdm-source


@nmi-agro/fdm-source / fdm-calculator/src / buildNSupplyRequest

Function: buildNSupplyRequest()

buildNSupplyRequest(field, soilData, cultivations, method, timeframe): Record<string, unknown>

Defined in: fdm-calculator/src/mineralization/builders.ts:139

Builds the JSON request body for POST /bemestingsplan/nsupply.

Maps FDM field, soil, and cultivation data to the flat parameter structure expected by the NMI nsupply endpoint.

Soil parameter mapping:

FDM parameterAPI fieldUnit
a_som_loia_som_loi%
a_clay_mia_clay_mi%
a_silt_mia_silt_mi%
a_sand_mia_sand_mi%
a_c_ofa_c_ofg C/kg
a_cn_fra_cn_fr
a_n_rta_n_rtmg N/kg
a_n_pmna_n_pmnmg N/kg
b_soiltype_agrb_soiltype_agr
a_depth_lowera_depthm (default 0.3)

The BRP crop code is extracted from b_lu_catalogue of the main crop in the requested timeframe. We strip the "nl_" prefix and convert to an integer.

Parameters

field

Basic field geometry (centroid required for lat/lon).

b_area?

number | null

b_centroid?

[number, number] | null

[longitude, latitude] in WGS84

soilData

Record<string, number | string | null | undefined>

Flat map of soil parameter values from getCurrentSoilData.

cultivations

object[]

Cultivations on the field (used to derive BRP code).

method

NSupplyMethod

Mineralization model to request.

timeframe

Timeframe

Calendar year timeframe; start and end set d_start/d_end.

Returns

Record<string, unknown>

A plain object suitable for JSON.stringify and sending to the API.

Example

const body = buildNSupplyRequest(
{ b_centroid: [5.585, 53.288] },
{ a_som_loi: 3.5, a_clay_mi: 10, a_silt_mi: 20, a_depth_lower: 0.3 },
[{ b_lu_catalogue: "nl_256", b_lu_start: new Date("2026-04-01") }],
"minip",
{ start: new Date("2026-01-01"), end: new Date("2026-12-31") },
)