Time offs
Overview
The Time Off API allows you to programmatically manage employee time off periods in Swarmia, enabling you to sync time off data from external systems like HR platforms or leave management systems. The API provides full CRUD operations for managing time off periods.
Authentication
Authentication works based on a token which you can generate here.
Two options are currently available:
Include an HTTP header like
Authorization: Bearer {TOKEN}in the request. Example request with the curl command line tool:curl https://app.swarmia.com/api/v0/time-offs -H "Authorization: Bearer {TOKEN}"Pass the token as a value for the
tokenquery parameter. Example request:GET https://app.swarmia.com/api/v0/time-offs/{id}?token={TOKEN}Security note: Even though Swarmia redacts secret tokens from query logs, please bear in mind that some other proxies might log query parameters before reaching Swarmia.
Create a time off period
POST /api/v0/time-offs
Creates a new time off period for a team member.
Example query
curl -H "Content-Type: application/json" \
-H "Authorization: Bearer TOKEN" \
-X POST https://app.swarmia.com/api/v0/time-offs \
-d '{
"email": "developer@example.com",
"startDate": "2024-12-20",
"endDate": "2024-12-27",
"externalId": "HR-VACATION-12345"
}'Parameters
Body parameters
email string required
Email address of the team member. Must match an existing author in your organization.
startDate string required
Start date of the time off period in yyyy-MM-dd format.
endDate string required
End date of the time off period in yyyy-MM-dd format. Must be on or after the start date.
externalId string optional
Identifier for the time off period used in your external system. This allows you to reference and update the period using your own ID system.
Maximum 128 characters
Cannot contain whitespace, slashes (
/,\), or quotes (',")Must be unique within your organization
Cannot be changed after creation
Response
Response codes
201
Created
400
Validation error (invalid email format, date format, date range, or externalId format)
404
Email not found in organization
409
Duplicate time off period or externalId already exists
Example response
Get a time off period
GET /api/v0/time-offs/{id}
Retrieves a specific time off period by its Swarmia UUID or your external ID.
Example queries
By Swarmia id:
By external id:
Parameters
Path parameters
id string required
Either the Swarmia id or your externalId for the time off period.
Response
Response codes
200
Ok
404
Time off period not found
Example response
Update a time off period
PUT /api/v0/time-offs/{id}
Updates an existing time off period. You can update the dates and the associated email. The externalId cannot be changed after creation.
Example query
Parameters
Path parameters
id string required
Either the Swarmia UUID or your externalId for the time off period.
Body parameters
email string required
Email address of the team member. Must match an existing author in your organization.
startDate string required
Start date of the time off period in yyyy-MM-dd format.
endDate string required
End date of the time off period in yyyy-MM-dd format. Must be on or after the start date.
Note: The
externalIdfield is immutable and cannot be changed through the update endpoint.
Response
Response codes
200
Ok
400
Validation error (invalid email format, date format, or date range)
404
Time off period not found or email not found in organization
409
Updated period conflicts with existing time off period
Example response
Delete a time off period
DELETE /api/v0/time-offs/{id}
Permanently deletes a time off period. FTE calculations are automatically recalculated for the affected time range.
This is a permanent operation and cannot be undone.
Example query
Parameters
Path parameters
id string required
Either the Swarmia id or your externalId for the time off period.
Response
Response codes
204
No Content - Successfully deleted
404
Time off period not found
Example response
No response body is returned on successful deletion (204 status code).
Using External IDs
The Time Off API supports a dual-identifier system to make integration with external systems easier:
Swarmia UUID (
id): Automatically generated by Swarmia when a time off period is createdExternal ID (
externalId): Optional identifier from your HR or leave management system
Benefits of using External IDs
Simplified integration: Use your existing HR system's identifiers instead of storing Swarmia ids
Idempotent operations: Prevent duplicate entries by using consistent external IDs
System independence: If you migrate HR systems, you can maintain the same external IDs
External ID requirements
Maximum 128 characters
Cannot contain whitespace, slashes (
/,\), or quotes (',")Must be unique within your organization
Cannot be changed after creation
Can be used interchangeably with Swarmia id in
GET,PUT, andDELETEoperations
Example workflow with External IDs
Common validation errors
Invalid email format
Invalid date format
Invalid date range
Email not found
The specified email address doesn't match any team member in your organization.
External ID already exists
Another time off period in your organization is already using this externalId.
Time off period already exists
A time off period for this team member with these exact dates already exists.
Invalid External ID format
Best practices
Use External IDs for easier integration
If you're integrating with an HR system, always provide externalId to:
Avoid storing and managing Swarmia ids in your system
Prevent duplicate entries when syncing
Simplify updates and deletions
Handle date changes carefully
When updating dates, keep in mind:
FTE calculations are automatically recalculated for affected time ranges
Large date changes may affect multiple months of FTE data
Consider the impact on reporting and metrics
Error handling
Always check response status codes and handle errors appropriately:
400errors indicate validation issues - check your input data404errors mean the resource wasn't found - verify IDs are correct409errors indicate conflicts - check for duplicates500errors are server issues - implement retry logic
Last updated
Was this helpful?