When to use this endpoint

Use ScheduleOfRates_setStock for CRM1’s stock editor. Supply the complete encoded stock list.

Authentication and permissions

The request must establish tenant context with signed API credentials or a logged-in CRM session. The handler checks for the tenant database prefix rather than calling the normal login guard.

No additional page or role permission is checked. The CRM screens apply their own client-side Schedule of Rates permissions.

Parameters

ParameterTypeRequiredDescription
idInteger stringYesPositive rate ID.
valJSON stringNoComplete stored value, normally [[stockId, quantity], ...]. Omission stores []. Unlike the labour setter, a native array is not encoded and can cause a runtime type error.

Example request

FM_api('ScheduleOfRates_setStock', [
	'id' => '430001',
	'val' => json_encode([[74, 1], [91, 2.5]]),
]);

Example response

{
  "ok": 1
}

Errors and unusual responses

ResponseCondition
{"error":"not logged in"}No authenticated tenant context is available. Invalid signed credentials can be rejected by the dispatcher before the handler runs.
{"error":"missing or invalid parameter: id"}The ID is absent or not positive.
{"error":"schedule of rates does not exist"}The ID has no row.
{"ok":1,"msg":"no change needed"}The submitted string exactly matches stock_used.
Runtime type errorval is a native array and reaches string escaping.

Legacy application errors may be returned with HTTP 200. Check the decoded response for error, not only the HTTP status.

Behaviour and edge cases

  • Quantities can be fractional because the stored value is not numerically normalized.
  • Derived stock cost readers multiply these quantities by each stock row’s current average cost.

Side effects

  • On change, advances last_edited and the scheduleOfRates cache marker.
  • Fires the tenant-configurable SOR_edit event with the rate ID. Any configured listeners run synchronously and can add integration-specific side effects.

See it in Fieldmotion

CRM1

Edit the Stock Used table on the Schedule of Rates page.

CRM2

CRM2 stores stock through ScheduleOfRate_updateData, which does accept native arrays.

Related endpoints