Skip to navigation

Assign Shift

Assigns one shift to one or more people for a period, exactly as an administrator would from Attendance in Crehana. Built for HR and workforce-planning systems that own the schedule and push it to Crehana. Step-by-step guide: Assign shifts.

Once assigned, the shift drives the attendance of those days: marks are matched to it, punctuality is classified against it and the daily attendance is recalculated.

  • start_date and end_date are calendar days, inclusive; end_date is optional for an open-ended assignment.
  • A rotating shift needs start_cycle_id, the cycle it starts with on start_date. A fixed shift takes no cycle.
  • If a person already has a shift that overlaps the new one in that period, the previous assignment is deactivated and the new one takes its place. Once shifts are allowed to coexist on the same day, an overlap is rejected instead: 409 with one conflict per person, and nobody gets the shift (all-or-nothing).
  • Sending the same assignment again is safe: people who already have this exact shift in this period are listed in already_assigned_user_ids, nothing is duplicated and the answer is 200 when there is nothing new.
  • The shift must belong to the organization and be active, and every person must belong to it, otherwise 404 (detail.code says which).
  • Requires credentials of an administrator of the organization.

Authentication

Api-Keystring

API key of the organization. Always sent together with the Secret-Access header.

Path parameters

organization_slugstringRequired

Headers

Secret-AccessstringRequired

Request

This endpoint expects an object.
shift_idstringRequiredformat: "uuid"
Id of the shift to assign, as shown in Attendance in Crehana. The shift must belong to the organization and be active.
user_idslist of integersRequired

Centralized ids of the people who get the shift: user.id in GET /org/{organization_slug}/users/user-organizations/. Not the learning user id. Between 1 and 100 ids, without repeats. The request is all-or-nothing: if one person cannot take the shift, nobody gets it.

start_datedateRequired

First day of the assignment, YYYY-MM-DD.

end_datedateOptional

Last day of the assignment, YYYY-MM-DD, inclusive. Omit it or send null for an open-ended assignment.

start_cycle_idstringOptionalformat: "uuid"

For rotating shifts only: id of the cycle the rotation starts with on start_date. Required for a rotating shift, and must be omitted for a fixed one.

Response

Everybody already had this shift in this period; nothing new

successboolean
True when the shift is assigned.
messagestring
Human readable result.
codestring

attendance-003 when at least one assignment was created, attendance-004 when everybody already had the shift. Not an HTTP status.

datetimestring
Datetime of the API in ISO Format
dataobject

Errors

400
Bad Request Error
401
Unauthorized Error
403
Forbidden Error
404
Not Found Error
409
Conflict Error
422
Unprocessable Entity Error