Stock items and catalogue maintenance
Delete stock created on a date
/a/Stock_deleteByDate
Soft-delete the tenant’s undeleted stock rows whose creation datetime begins with a date.
When to use this endpoint
This is a main-account maintenance tool, not a range filter or deletion by last-edited date.
Authentication and permissions
Authenticate with a signed API key or a logged-in CRM session on the account’s routed host. API keys act as their owner; session calls require dispatcher CSRF protection where configured. IDs address the authenticated tenant.
Additionally requires userdata.id to equal userdata.parent. This is an account-owner check, not a CRM2 role grant.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
date | YYYY-MM-DD string | Yes | Pattern check only; blank/malformed values rejected, but impossible calendar dates can pass the regex. |
Example request
$result = FM_api('Stock_deleteByDate', ['date'=>'2026-11-17']);
Example response
{
"ok": 1,
"deleted": 3
}
Application errors can use HTTP 200. Inspect error/warning fields; database numeric values can be strings unless this handler explicitly converts them.
Errors and unusual responses
| Response | Condition |
|---|---|
{"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: date"} | Date is empty or fails YYYY-MM-DD pattern. |
{"error":"only the main account user can delete by date"} | User ID differs from tenant account ID. |
{"error":"no stock in the database was created on that date"} | No undeleted creation-date matches. |
Legacy application errors may be returned with HTTP 200. Check the decoded response for error, not only the HTTP status.
Behaviour and edge cases
- Requires the logged-in user ID to equal the tenant account ID. Includes archived and active undeleted items; the single-item archived prerequisite is not used.
- Counts undeleted cdate prefix matches, logs each deletion, then bulk-updates deleted/ddate/last_edited. The returned deleted number is the pre-count, not an affected-row acknowledgement.
- Unlike Stock_delete, does not clear api_syncs links or legacy upload queues. Category, supplier and allocation rows remain. No transaction spans the log and bulk update.
Side effects
- Marks matching items deleted, creates deletion log rows and invalidates stock cache.
See it in Fieldmotion
CRM1
In CRM1 Stock, use the main-account delete-by-date maintenance dialog; Network shows Stock_deleteByDate with date.
CRM2
Source search found no current direct CRM2 delete-by-date caller. Normal Stocks selection deletes individual archived items.
Related endpoints
Stock_delete— Soft-delete one catalogue item and record its tenant deletion event.Stock_deleteByIDs— Soft-delete catalogue items within an inclusive numeric ID interval.Stock_restore— Restore one stock tombstone through an Admin-console authenticated session.