Skip to content

Writing

The writes are about the calendar and need the calendar:write scope. They go through the app's own functions: same checks, same error messages, same notifications, same activity log entry, on behalf of whoever created the key.

The body is a JSON object (Content-Type: application/json). With another Content-Type the answer is 415; a body that is not valid JSON, or that is null, a list or a number, gets 400 invalid_request. A field the app refuses comes back in fields under its public name; a nested field under its path, such as repeat.until or vehicles[1] (see Errors).

Operation Endpoint Answer
create a shift, or a series POST /shifts/ 201, the shift
change a shift PATCH /shifts/<id>/ 200, the shift
delete a shift DELETE /shifts/<id>/ 200, the ids deleted
sign up the key's author POST /shifts/<id>/signup/ 200, the availability
withdraw the key's author DELETE /shifts/<id>/signup/ 200, the availability
put a person on a shift POST /shifts/<id>/assignments/ 200, the availability
take a person off a shift DELETE /availabilities/<id>/ 200, the availability

Who is notified

Every write notifies whom the app would notify. There is no parameter to turn notifications off.

Operation Who gets a notification
create a shift as from the app; with notify_candidates: true, everyone who can take part
move a shift the people signed up
delete a shift the people signed up
sign up, withdraw the staff, according to the calendar's notification rules
put a person on, or take them off that person

A program going wrong in a loop can send hundreds of notifications to real people. That is why writes have their own limit (10 per minute and 50 per day per key), and why it pays to try with dry_run first.

Trying without saving: dry_run

With ?dry_run=true the write is checked as the real one, but nothing is saved and no notification leaves. The answer is 200 and tells what would happen, with the warnings:

curl -s -X POST "$APPTOME_API/shifts/9120/assignments/?dry_run=true" \
  -H "Authorization: Bearer $APPTOME_KEY" -H "Content-Type: application/json" \
  -d '{"person": 340, "task": 7}'
{
  "dry_run": true,
  "availability": {"id": null, "shift": 9120, "person": {"id": 340, "first_name": "Marta", "last_name": "Conti", "role": "volunteer"}, "task": 7, "type": "available", "…": "…"},
  "warnings": [{"code": "busy_elsewhere", "message": "The person is taken off the overlapping shifts.", "shifts": [9118]}]
}
Warning Meaning
past_shift the shift has already started or is over; on a change, the shift is moved into the past
pending_approval the availability waits for the staff's approval
busy_elsewhere the person is taken off the overlapping shifts, listed in shifts
leaves_series the shift leaves its series

In the dry run of a write on availabilities availability.id is always null: the dry run saves no row, and the real write may save the person's row anew, with a new id.

On creating and changing a shift the dry run also returns preview, the shift as the write would leave it, built from the same checks:

{
  "dry_run": true,
  "preview": {"id": null, "name": "Weekday night", "start": "2027-01-04T20:00:00+01:00", "end": "2027-01-05T08:00:00+01:00",
              "calendar": 1, "shift_type": 3, "occurrences": 124, "dates": ["2027-01-04", "2027-01-05", "…"]},
  "warnings": []
}
Field of preview
id the shift changed; null when the write would create it
name, start, end, calendar, shift_type as in the real answer; shift_type null if none
occurrences the shifts the write creates or changes: 1, or those of the series. For a new series an upper bound: a day whose shift fails the checks (a vehicle already busy) is skipped when saving
dates a new series only: the days of its shifts, the first 100 at most

A dry run gets the same errors as the real write. It counts as a request, not as a write.

Never writing twice: Idempotency-Key

A program that gets no answer (a timeout, a dropped connection) does not know whether the write happened. With the Idempotency-Key header it can repeat it safely:

key=$(uuidgen)
curl -s -X POST "$APPTOME_API/shifts/" \
  -H "Authorization: Bearer $APPTOME_KEY" -H "Content-Type: application/json" \
  -H "Idempotency-Key: $key" \
  -d '{"calendar": 1, "shift_type": 3, "start": "2026-12-20T08:00:00", "end": "2026-12-20T14:00:00"}'

The contract:

  • it applies to POST only, and not with dry_run=true. A repeated PATCH or DELETE lands on the same state anyway;
  • the client chooses the key: 1 to 255 printable ASCII characters, no spaces, new for each write (a UUID is fine). Malformed: 400 invalid_request. It is bound to the API key's user;
  • the first request with a key claims it before writing. The same request sent again with the same key while the first is running gets 409 idempotency_in_progress, with Retry-After: 1: never two writes;
  • a 2xx answer is kept for 24 hours. The same request (same method, path, parameters and body) with the same key gets the first answer, status and body, with the Idempotent-Replayed: true header, and nothing is done again. It counts as a request, not as a write;
  • a different request with the same key gets 422 idempotency_key_reused, even while the first is still running;
  • any other outcome (an error, a refusal, a limit) frees the key: fix the request and send it again with the same key;
  • a key left claimed by a request that died is freed after 5 minutes.

AppToMe keeps only a fingerprint of the key and of the request; the stored answers are deleted after 24 hours.

Creating a shift

POST /shifts/

Field
calendar required calendar id
shift_type required shift type id
start, end required ISO 8601, in the years 2000-2100; end after start, at most 60 days later
name the name of the shift
note notes, shown on the shift; at most 2000 characters
vehicles ids of the vehicles on the shift
repeat for a series, see below
notify_candidates true: tell everyone who can take part. Not with repeat
curl -s -X POST "$APPTOME_API/shifts/" \
  -H "Authorization: Bearer $APPTOME_KEY" -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{"calendar": 1, "shift_type": 3, "name": "Ambulanza mattina",
       "start": "2026-12-20T08:00:00", "end": "2026-12-20T14:00:00",
       "notify_candidates": true}'

A series is created with repeat:

Field of repeat
until required: the last day, YYYY-MM-DD, not before the start of the shift and not beyond the first of January five years ahead
every_days days from one shift to the next: 1 every day (when absent), 7 every week; at most 3660
on the days: monday … sunday, working_day, day_before_holiday, holiday, every_day (when absent)
except_on the days to skip, with the same names
{"calendar": 1, "shift_type": 3, "start": "2027-01-04T20:00:00", "end": "2027-01-05T08:00:00",
 "repeat": {"until": "2027-06-30", "on": ["working_day"], "except_on": ["day_before_holiday"]}}

A value outside these bounds gets 400 invalid_request, with the field in fields: start, repeat.until, repeat.every_days. So does a key of repeat that is not one of these, on repeat.<key>. notify_candidates and employee take only JSON true and false, not "yes" or 1.

The answer is the shift, the first of the series. Custom fields the organization added to the shift form cannot be filled from the API: if one is required, the error comes in non_field_errors with its name.

Changing a shift

PATCH /shifts/<id>/?scope=single|following

The same fields as for creating, without repeat and notify_candidates, all optional: only what you send changes. vehicles, when sent, is the whole list. repeat or notify_candidates in a change get 400 invalid_request on that field.

  • scope=single (when absent): this shift only. If it is in a series, it leaves it, as in the app.
  • scope=following: this shift and the following ones of the series. Name, type, times, notes and vehicles change; not the day nor the calendar. On a shift that is not in a series: 400.
curl -s -X PATCH "$APPTOME_API/shifts/9120/?scope=following" \
  -H "Authorization: Bearer $APPTOME_KEY" -H "Content-Type: application/json" \
  -d '{"start": "2026-12-14T07:30:00", "end": "2026-12-14T14:00:00"}'

A shift can be moved into the past, as in the app: what counts is whether the key's author could edit the shift as it was before. The dry run warns past_shift.

The leaves_series and past_shift warnings come only with dry_run: the real answer is the shift.

Deleting a shift

DELETE /shifts/<id>/?scope=single|following

single (when absent) deletes the shift, following the following ones of its series too. The whole series cannot be deleted from here.

curl -s -X DELETE "$APPTOME_API/shifts/9120/?scope=single" -H "Authorization: Bearer $APPTOME_KEY"
{"dry_run": false, "deleted": [9120]}

Signing up and withdrawing

POST /shifts/<id>/signup/ signs the key's author up for the shift, as when signing up from the app. They need a record in the registry, not removed from it: otherwise 409 no_person.

Field
task required the task
start, end partial availability, within the shift: only on calendars that allow it and on shifts under 24 hours
note note on the availability, at most 2000 characters

The task must be one the app would let that person pick on that shift: asked for by the shift, among the person's own, with room left. With any other the answer is 400 invalid_request, with the reason in fields.task.

Someone already on the shift who changes task needs room in the new one: the place they hold now counts as free. Sending the same task again, to change the hours or the note, is always accepted.

curl -s -X POST "$APPTOME_API/shifts/9120/signup/" \
  -H "Authorization: Bearer $APPTOME_KEY" -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" -d '{"task": 7}'

DELETE /shifts/<id>/signup/ withdraws them: the availability stays, as unavailable. Repeating the call changes nothing and still answers 200. The 404 comes only if the person never gave an availability for that shift.

Putting a person on and off

POST /shifts/<id>/assignments/ puts a person on the shift with a task, as the staff do in the app: it approves a pending availability or changes its task.

Field
person required person id, from /people/
task required task id: one the shift asks for and the person has, otherwise 400 invalid_request
start, end, note as for signing up
employee on the shift as an employee
curl -s -X POST "$APPTOME_API/shifts/9120/assignments/" \
  -H "Authorization: Bearer $APPTOME_KEY" -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" -d '{"person": 340, "task": 7}'

DELETE /availabilities/<id>/ takes the person off: the availability stays, as unavailable, with its task and note. The id is the one from /availabilities/ or from the answer above.

curl -s -X DELETE "$APPTOME_API/availabilities/50211/" -H "Authorization: Bearer $APPTOME_KEY"