Create a scheduled report
This endpoint registers a report that is emailed to its receivers once a month. You send a JSON body to POST /v2/scheduled-reports with the notifications:write scope. The acting user — the key owner or the user named in X-On-Behalf-Of — becomes the report's creatorId. The call either returns the finished report with 201 or hands back a 202 with an operation you poll until it settles.
Who is allowed to create a report
The acting user must be an admin, or a location admin who manages every location listed in locationIds. A location admin must send at least one location; an empty locationIds array is not acceptable for them. If the acting user is neither an admin nor a location admin, or the location list is empty or contains a location they do not manage, the request fails with 403 FORBIDDEN. If scheduled reports are not available on the account, the response is 403 SCHEDULED_REPORTS_NOT_AVAILABLE. When X-On-Behalf-Of is used, the key needs the users:act-on-behalf scope and the key owner must manage the target user; otherwise the call returns 403 ON_BEHALF_OF_NOT_ALLOWED.
Request fields and defaults
The body is application/json. Required fields are name, reportType, receivers (at least one email address), timezone, sendDayOfMonth, sendHourUtc and sendMinuteUtc. reportType accepts leaveHistoryReport, leaveBalanceReport or monthlyLeaveBalanceReport. period is optional and its only value is LAST_MONTH, which is also the default. locationIds, departmentIds and labelIds are optional arrays that default to empty, meaning everyone. leaveStatus is optional and applies only to leaveHistoryReport; it accepts APPROVED, DENIED, EXPIRED and CANCELLED. name fails validation if it looks like HTML or script, and unknown fields fail validation. sendDayOfMonth ranges from 1 to 31, sendHourUtc from 0 to 23, and sendMinuteUtc from 0 to 59.
Send time is UTC; timezone only dates the report
A common mistake is to put a local send time into sendHourUtc and sendMinuteUtc. Those two fields are always UTC. The timezone field is used for the dates inside the report, not for scheduling the email. Convert local send times yourself before sending the request. For example, the captured leave-balance example uses Europe/Belgrade with sendDayOfMonth 1, sendHourUtc 7 and sendMinuteUtc 30, meaning 07:30 UTC on the first of the month. The leave-history example uses America/Los_Angeles with sendHourUtc 16 and sendMinuteUtc 0, meaning 16:00 UTC on the second.
Headers: Idempotency-Key and X-On-Behalf-Of
Idempotency-Key is optional. When you supply it, use between 1 and 255 printable ASCII characters. Records are scoped to the API key and kept for 24 hours. Within that window, sending the same request again with the same key does not create a second report; the earlier response is returned instead and carries the Idempotent-Replayed header. If the key is reused for a request whose contents differ, the response is 422 IDEMPOTENCY_KEY_REUSED. If the first request has not finished yet, a retry under the same key returns 409 IDEMPOTENCY_REQUEST_IN_PROGRESS. A key that violates the character or length rule produces 400 INVALID_IDEMPOTENCY_KEY. X-On-Behalf-Of is also optional: it identifies the user the write is performed for, and GET requests ignore it.
Reading 201 and 202
A 201 returns the created scheduled report in a data object: id, name, reportType, period (omitted when not stored), locationIds, departmentIds, labelIds, receivers, timezone, sendDayOfMonth, sendHourUtc, sendMinuteUtc, leaveStatus (omitted when none are stored), creatorId, and error (the last error that stopped the report from being sent, omitted when there is none). A 202 returns an operation object with id, status and url. The Location header carries the same URL as operation.url. Poll it until status is SUCCEEDED or FAILED. UNKNOWN means no result arrived within 15 minutes; the change may or may not have been applied, so read the resource to check. A result that arrives later still changes it to SUCCEEDED or FAILED.
Error codes and what they mean
400 VALIDATION_ERROR returns details.fields listing the failing fields; fix them and resend. 400 INVALID_REQUEST_BODY means the body could not be parsed. 401 UNAUTHORIZED means the API key is missing, malformed or not recognized. 403 SCHEDULED_REPORTS_NOT_AVAILABLE means the feature is not enabled for the account. 403 ON_BEHALF_OF_NOT_ALLOWED means the on-behalf-of scope or management relationship is missing. 403 FORBIDDEN covers the admin/location-admin rule and locationIds problems. 409 CONFLICT means the request conflicts with current state; 409 IDEMPOTENCY_REQUEST_IN_PROGRESS means the first request is still running. 422 IDEMPOTENCY_KEY_REUSED means the key was used with a different request. 429 RATE_LIMITED means too many requests; wait and retry with the same Idempotency-Key for writes. 500 INTERNAL_ERROR means retry later and quote the requestId if it persists.
Pre-flight checklist
- Confirm the key has notifications:write. 2) Confirm the acting user is an admin, or a location admin who manages every location in locationIds and sends at least one. 3) Include name, reportType, receivers, timezone, sendDayOfMonth, sendHourUtc and sendMinuteUtc. 4) Convert the local send time to UTC yourself. 5) Use leaveStatus only with leaveHistoryReport. 6) Generate an Idempotency-Key if you may retry. 7) Handle 201 directly; for 202, poll operation.url until SUCCEEDED or FAILED.
Frequently asked questions
Does timezone set when the email is sent?
No. timezone is used for the dates inside the report. sendHourUtc and sendMinuteUtc are always UTC, so convert local send times yourself.
Which reports can use leaveStatus?
Only leaveHistoryReport. It accepts APPROVED, DENIED, EXPIRED and CANCELLED.
Can a location admin create a report for all locations?
No. A location admin must send at least one location and must manage every location in locationIds. An empty locationIds array is not acceptable for them, and including a location they do not manage returns 403 FORBIDDEN.
What should I do with a 202 response?
Read operation.url (the same URL appears in the Location header) and poll it until status is SUCCEEDED or FAILED. UNKNOWN means no result arrived within 15 minutes; the change may or may not have been applied, so read the resource to check.
How does Idempotency-Key behave?
Each API key keeps its idempotency records for 24 hours. Resending the identical request with the same key returns the stored response again with the Idempotent-Replayed header. A different request under the same key returns 422 IDEMPOTENCY_KEY_REUSED; a resend while the original is still executing returns 409 IDEMPOTENCY_REQUEST_IN_PROGRESS; a key that breaks the character or length rule returns 400 INVALID_IDEMPOTENCY_KEY.
curl -X POST "$API_BASE_URL/v2/scheduled-reports" \
-H "Authorization: Bearer " \
-H "Content-Type: application/json" \
-d '{
"name": "Monthly balances",
"reportType": "leaveBalanceReport",
"receivers": [
"[email protected]"
],
"timezone": "Europe/Belgrade",
"sendDayOfMonth": 1,
"sendHourUtc": 7,
"sendMinuteUtc": 30
}'{
"data": {
"id": "scheduledReport-8a47c61e-2b7f-4d5e-9c61-3f1c2b9e1d93",
"name": "Monthly balances",
"reportType": "leaveBalanceReport",
"period": "LAST_MONTH",
"locationIds": [],
"departmentIds": [],
"labelIds": [],
"receivers": [
"[email protected]"
],
"timezone": "Europe/Belgrade",
"sendDayOfMonth": 1,
"sendHourUtc": 7,
"sendMinuteUtc": 30,
"creatorId": "user-63b17e97-d38b-4586-8498-bb4f5d2e2c14"
}
}{
"operation": {
"id": "pa_3f1c2b9e-8a47-4d5e-9c61-2b7f0e4a1d93",
"status": "PENDING",
"url": "/v2/operations/pa_3f1c2b9e-8a47-4d5e-9c61-2b7f0e4a1d93"
}
}{
"error": {
"code": "VALIDATION_ERROR",
"name": "ValidationError",
"description": "Example post details.",
"resolution": "Fix the fields listed in details.fields and send the request again.",
"requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef",
"details": {
"fields": [
{
"path": "startDate",
"message": "\"startDate\" is required"
}
]
}
}
}{
"error": {
"code": "UNAUTHORIZED",
"name": "Unauthorized",
"description": "Example post details.",
"resolution": "Send a valid API key in the Authorization header as Bearer followed by the full vt_live_ key.",
"requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef"
}
}{
"error": {
"code": "INSUFFICIENT_SCOPE",
"name": "InsufficientScope",
"description": "Example post details.",
"resolution": "Add the scopes listed in details.requiredScopes to the key in the OnlyLeave dashboard.",
"requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef",
"details": {
"requiredScopes": [
"leaves:write"
]
}
}
}{
"error": {
"code": "CONFLICT",
"name": "Conflict",
"description": "Example post details.",
"resolution": "Read the resource again and retry with up-to-date values.",
"requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef"
}
}{
"error": {
"code": "LEAVE_NEGATIVE_BALANCE",
"name": "LeaveNegativeBalance",
"description": "Example post details.",
"resolution": "Shorten the leave, use a different leave type, or ask an admin to adjust the quota.",
"requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef"
}
}{
"error": {
"code": "RATE_LIMITED",
"name": "RateLimited",
"description": "Example post details.",
"resolution": "Wait a few seconds and retry, using the same Idempotency-Key for writes.",
"requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef"
}
}{
"error": {
"code": "INTERNAL_ERROR",
"name": "InternalError",
"description": "Example post details.",
"resolution": "Retry later, and if it keeps happening, contact OnlyLeave support and quote the requestId.",
"requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef"
}
}Idempotency-Key
| Field | Type | Required | Description | Constraints |
|---|---|---|---|---|
| Idempotency-Key | string | No | optional key (1 to 255 printable ASCII characters) that makes a write request safe to retry. Keys are retained for 24 hours per API key. Retrying with the same key and the same request within those 24 hours replays the original response (with the Idempotent-Replayed header). Reusing the key with a different request returns 422 IDEMPOTENCY_KEY_REUSED ; retrying while the first request is still running returns 409 IDEMPOTENCY_REQUEST_IN_PROGRESS ; an invalid key returns 400 INVALID_IDEMPOTENCY_KEY . | 1 <= length <= 255 |
X-On-Behalf-Of
| Field | Type | Required | Description | Constraints |
|---|---|---|---|---|
| X-On-Behalf-Of | string | No | ID of the user the write is performed for. Requires the users:act-on-behalf scope, and the key owner must manage the target user; otherwise the request fails with 403 ON_BEHALF_OF_NOT_ALLOWED . Ignored on GET requests. |
body
| Field | Type | Required | Description | Constraints |
|---|---|---|---|---|
| body | object | Yes | ||
| body.name | string | Yes | report name. Text that looks like HTML or script fails validation. | |
| body.reportType | string | Yes | the kind of report | Allowed values: "leaveHistoryReport" | "leaveBalanceReport" | "monthlyLeaveBalanceReport" |
| body.period | string | No | the period the report covers; LAST_MONTH is the only value | Allowed values: "LAST_MONTH" |
| body.locationIds | array<string> | No | IDs of the locations included; empty means all locations. A location admin must send at least one location they manage. | [] |
| body.locationIds[] | string | |||
| body.departmentIds | array<string> | No | IDs of the departments included; empty means all departments | [] |
| body.departmentIds[] | string | |||
| body.labelIds | array<string> | No | IDs of the labels included; empty means users with or without labels | [] |
| body.labelIds[] | string | |||
| body.receivers | array<string> | Yes | email addresses the report is sent to | 1 <= items |
| body.receivers[] | string | |||
| body.timezone | string | Yes | the time zone used for the report's dates, not for the send time | |
| body.sendDayOfMonth | integer | Yes | the day of the month the report is sent | 1 <= value <= 31 |
| body.sendHourUtc | integer | Yes | the hour the report is sent, in UTC | 0 <= value <= 23 |
| body.sendMinuteUtc | integer | Yes | the minute the report is sent, in UTC | 0 <= value <= 59 |
| body.leaveStatus | array<ScheduledReportLeaveStatus> | No | the leave statuses included, only for leaveHistoryReport | |
| body.leaveStatus[] | string | a leave status a leaveHistoryReport includes | "APPROVED" | "DENIED" | "EXPIRED" | "CANCELLED" |
response
| Field | Type | Required | Description | Constraints |
|---|---|---|---|---|
| response | object | |||
| response.data | object | Yes | ||
| response.data.id | string | Yes | scheduled report ID | |
| response.data.name | string | Yes | report name | |
| response.data.reportType | string | Yes | the kind of report | "leaveHistoryReport" | "leaveBalanceReport" | "monthlyLeaveBalanceReport" |
| response.data.period | string | No | the period the report covers; left out when it is not stored | "LAST_MONTH" |
| response.data.locationIds | array<string> | Yes | IDs of the locations included; empty means all locations | |
| response.data.locationIds[] | string | |||
| response.data.departmentIds | array<string> | Yes | IDs of the departments included; empty means all departments | |
| response.data.departmentIds[] | string | |||
| response.data.labelIds | array<string> | Yes | IDs of the labels included; empty means users with or without labels | |
| response.data.labelIds[] | string | |||
| response.data.receivers | array<string> | Yes | email addresses the report is sent to | |
| response.data.receivers[] | string | |||
| response.data.timezone | string | Yes | the time zone used for the report's dates. It does not apply to sendHourUtc and sendMinuteUtc. | |
| response.data.sendDayOfMonth | integer | Yes | the day of the month the report is sent | 1 <= value <= 31 |
| response.data.sendHourUtc | integer | Yes | the hour the report is sent, in UTC | 0 <= value <= 23 |
| response.data.sendMinuteUtc | integer | Yes | the minute the report is sent, in UTC | 0 <= value <= 59 |
| response.data.leaveStatus | array<ScheduledReportLeaveStatus> | No | the leave statuses included, only for leaveHistoryReport; left out when none are stored | |
| response.data.leaveStatus[] | string | a leave status a leaveHistoryReport includes | "APPROVED" | "DENIED" | "EXPIRED" | "CANCELLED" | |
| response.data.creatorId | string | Yes | the ID of the user who created the report | |
| response.data.error | string | No | the last error that stopped the report from being sent; left out when there is none |
response
| Field | Type | Required | Description | Constraints |
|---|---|---|---|---|
| response | object | Returned with HTTP 202 when a write operation is still running, or succeeded but its result could not be read back yet. The Location header carries the same URL as operation.url . Poll it until the status is SUCCEEDED or FAILED . | ||
| response.operation | object | Yes | ||
| response.operation.id | string | Yes | ||
| response.operation.status | string | Yes | operation status. UNKNOWN means no result arrived within 15 minutes; the change may or may not have been applied, so read the resource to check. A result that arrives later still changes it to SUCCEEDED or FAILED. | Allowed values: "PENDING" | "SUCCEEDED" | "FAILED" | "UNKNOWN" |
| response.operation.url | string | Yes |
response
| Field | Type | Required | Description | Constraints |
|---|---|---|---|---|
| response | object | Error envelope returned by every endpoint, including authentication and rate limit errors. error.code is one of the codes in x-error-catalog . | ||
| response.error | object | Yes | ||
| response.error.code | string | Yes | stable machine-readable error code | |
| response.error.name | string | Yes | short human-readable error name | |
| response.error.description | string | Yes | what went wrong | |
| response.error.resolution | string | Yes | how to fix the problem | |
| response.error.requestId | string | Yes | request ID, include it when contacting support | |
| response.error.details | object | No | optional additional information specific to the error code | |
| response.error.details.[key: string] | any | No |
response
| Field | Type | Required | Description | Constraints |
|---|---|---|---|---|
| response | object | Error envelope returned by every endpoint, including authentication and rate limit errors. error.code is one of the codes in x-error-catalog . | ||
| response.error | object | Yes | ||
| response.error.code | string | Yes | stable machine-readable error code | |
| response.error.name | string | Yes | short human-readable error name | |
| response.error.description | string | Yes | what went wrong | |
| response.error.resolution | string | Yes | how to fix the problem | |
| response.error.requestId | string | Yes | request ID, include it when contacting support | |
| response.error.details | object | No | optional additional information specific to the error code | |
| response.error.details.[key: string] | any | No |
response
| Field | Type | Required | Description | Constraints |
|---|---|---|---|---|
| response | object | Error envelope returned by every endpoint, including authentication and rate limit errors. error.code is one of the codes in x-error-catalog . | ||
| response.error | object | Yes | ||
| response.error.code | string | Yes | stable machine-readable error code | |
| response.error.name | string | Yes | short human-readable error name | |
| response.error.description | string | Yes | what went wrong | |
| response.error.resolution | string | Yes | how to fix the problem | |
| response.error.requestId | string | Yes | request ID, include it when contacting support | |
| response.error.details | object | No | optional additional information specific to the error code | |
| response.error.details.[key: string] | any | No |
response
| Field | Type | Required | Description | Constraints |
|---|---|---|---|---|
| response | object | Error envelope returned by every endpoint, including authentication and rate limit errors. error.code is one of the codes in x-error-catalog . | ||
| response.error | object | Yes | ||
| response.error.code | string | Yes | stable machine-readable error code | |
| response.error.name | string | Yes | short human-readable error name | |
| response.error.description | string | Yes | what went wrong | |
| response.error.resolution | string | Yes | how to fix the problem | |
| response.error.requestId | string | Yes | request ID, include it when contacting support | |
| response.error.details | object | No | optional additional information specific to the error code | |
| response.error.details.[key: string] | any | No |
response
| Field | Type | Required | Description | Constraints |
|---|---|---|---|---|
| response | object | Error envelope returned by every endpoint, including authentication and rate limit errors. error.code is one of the codes in x-error-catalog . | ||
| response.error | object | Yes | ||
| response.error.code | string | Yes | stable machine-readable error code | |
| response.error.name | string | Yes | short human-readable error name | |
| response.error.description | string | Yes | what went wrong | |
| response.error.resolution | string | Yes | how to fix the problem | |
| response.error.requestId | string | Yes | request ID, include it when contacting support | |
| response.error.details | object | No | optional additional information specific to the error code | |
| response.error.details.[key: string] | any | No |
response
| Field | Type | Required | Description | Constraints |
|---|---|---|---|---|
| response | object | Error envelope returned by every endpoint, including authentication and rate limit errors. error.code is one of the codes in x-error-catalog . | ||
| response.error | object | Yes | ||
| response.error.code | string | Yes | stable machine-readable error code | |
| response.error.name | string | Yes | short human-readable error name | |
| response.error.description | string | Yes | what went wrong | |
| response.error.resolution | string | Yes | how to fix the problem | |
| response.error.requestId | string | Yes | request ID, include it when contacting support | |
| response.error.details | object | No | optional additional information specific to the error code | |
| response.error.details.[key: string] | any | No |
response
| Field | Type | Required | Description | Constraints |
|---|---|---|---|---|
| response | object | Error envelope returned by every endpoint, including authentication and rate limit errors. error.code is one of the codes in x-error-catalog . | ||
| response.error | object | Yes | ||
| response.error.code | string | Yes | stable machine-readable error code | |
| response.error.name | string | Yes | short human-readable error name | |
| response.error.description | string | Yes | what went wrong | |
| response.error.resolution | string | Yes | how to fix the problem | |
| response.error.requestId | string | Yes | request ID, include it when contacting support | |
| response.error.details | object | No | optional additional information specific to the error code | |
| response.error.details.[key: string] | any | No |