User work shifts
Delete a user work shift
POST
/a/UserWorkShift_delete
Delete one indexed work-shift row from user metadata; this is the alias used by CRM2’s row action.
When to use this endpoint
Use UserWorkShift_delete for the CRM2 Work Shifts table’s delete action. It delegates directly to UserWorkShift_deleteData.
Authentication and permissions
The request must authenticate and HR enhancements must be enabled.
The handler does not enforce pageUserWorkShifts_delete, Users edit permission, target ownership, or active-user state.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
id | Synthetic integer string | Yes | ID returned by a work-shift reader: encodedUserID * 1000 + index + 1. The remainder selects the zero-based row. |
userID / user_id | Integer string | No | Optional target-user override; userID wins. If supplied, the endpoint uses this user with the row index decoded from id, even when the ID encodes a different user. |
Example request
$result = FM_api('UserWorkShift_delete', [
'id' => '18002',
'userID' => '18',
]);
Example response
{
"ok": 1
}
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":"HR enhancements are disabled"} | The tenant feature disables these APIs. |
{"error":"missing or invalid parameter: userID"} | Neither the override nor encoded ID yields a positive user. |
{"error":"missing or invalid parameter: id"} | The ID is below one or decodes to a negative index. |
{"error":"user does not exist"} | The selected target user does not exist. |
{"error":"shift does not exist"} | The decoded index is absent from the user’s normalized effective rows. |
Legacy application errors may be returned with HTTP 200. Check the decoded response for error, not only the HTTP status.
Behaviour and edge cases
- Rows are read with company-default fallback enabled. Deleting the only custom row removes
meta.work_hours, so subsequent reads show the current company default. - If the user has no custom schedule, deleting a displayed fallback row merely unsets an already-absent key; the fallback reappears on the next read.
- When rows remain, the complete remainder is parsed and validated again. Overlapping/day-duplicate shifts remain allowed.
Side effects
- Replaces or removes
meta.work_hours, preserves other metadata, sets currentlast_edited/edited_uuid="UserWorkShift", and invalidates the users cache. - Does not create a deletion tombstone or audit-history row because shifts are embedded metadata, not table records.
See it in Fieldmotion
CRM1
No direct CRM1 caller was found.
CRM2
Choose Delete from a Work Shifts table row. The shared widget’s default singular delete route resolves here.
Related endpoints
UserWorkShift_deleteDatais the delegated implementation route with the same contract.UserWorkShifts_getDataTablereturns the current positional IDs.