Skip to content

Replace a location's work week with the REST API v2 endpoint

Use this endpoint when a location's standard working pattern changes for everyone, rather than for one person. It sets the complete set of working days and any day-specific hours in one write, and can optionally remove personal exceptions so the whole location follows the new pattern.

Who is acting, and what permission is needed

This write needs the locations:write scope, sent as a bearer API key. The person treated as acting is normally the key owner. If X-On-Behalf-Of is supplied, the write is performed for that user instead, and that use needs the users:act-on-behalf scope plus a key owner who manages the target user; otherwise the call fails with 403 ON_BEHALF_OF_NOT_ALLOWED. The location identifier goes in the path as id.

Build the complete replacement payload

Treat the payload as a complete new schedule, not as edits to individual days. Include every intended working day in days. For any working day that needs hours different from the location default, add exactly one entry for that day in workHours; working days without an entry fall back to the default hours. Days are numbered 0 for Sunday through 6 for Saturday, each at most once, with no more than seven entries in either list. Hours for a day must use the range and steps allowed in the dashboard, or validation fails.

Field map for the request body

days is required and carries the full replacement set of working days. workHours is optional and carries at most one entry per day. resetUserOverrides is optional and defaults to false. Setting it to true clears every per-user work week override in the location, so every user follows the new work week; leaving it false preserves those personal overrides.

Reading the result: immediate or asynchronous

A 200 response returns the new work week immediately. A 202 response means the write is still running, or finished but its result cannot be read back yet; the body carries an operation with an id, a status, and a url, and the Location header carries the same URL. Poll that URL until the status is SUCCEEDED or FAILED. UNKNOWN means no result arrived within 15 minutes and the change may or may not have been applied, so read the resource to check; a later result can still move it to SUCCEEDED or FAILED.

Make retries safe with Idempotency-Key

Add an Idempotency-Key to make retries safe. It must be 1 to 255 printable ASCII characters and is retained for 24 hours per API key. Repeating the same key with the same request in that window replays the original response, marked with the Idempotent-Replayed header. Reusing the key for a different request returns 422 IDEMPOTENCY_KEY_REUSED, retrying while the first request is still running returns 409 IDEMPOTENCY_REQUEST_IN_PROGRESS, and an invalid key returns 400 INVALID_IDEMPOTENCY_KEY. For rate limiting, wait a few seconds and retry writes with the same Idempotency-Key.

Pre-flight checklist

Before sending, confirm the location is within the key's data reach, the full day list is intentional, custom hours are allowed on the current plan, and you have decided whether personal overrides should be cleared. After sending, check whether you received 200 with the new schedule or 202 with an operation to poll, and verify the result by reading the work week again if the status is UNKNOWN.

Troubleshooting by error code

400 VALIDATION_ERROR points to fields listed in details.fields; fix those and resend. 400 INVALID_REQUEST_BODY means the body itself could not be accepted. 403 FORBIDDEN and 403 ON_BEHALF_OF_NOT_ALLOWED separate a general permission problem from an acting-on-behalf problem. 403 WORK_HOURS_LIMIT_REACHED means custom work hours need a plan that includes them. 404 RESOURCE_NOT_FOUND means the location does not exist or is outside the key's data reach. 401 means the key is missing, malformed, or not recognized, and 429 means too many requests were sent in a short time. 500 means something went wrong on the server side; retry later and quote the requestId if it persists. Every error uses the same envelope with code, name, description, resolution, and requestId, plus optional details.

Worked example pattern

The captured example sets Monday to Friday as working days, gives Friday four hours, and leaves resetUserOverrides false. That pattern is useful as a template: copy the shape, then replace the day numbers and hours with the location's actual schedule. If Friday should use default hours instead, remove its workHours entry rather than sending a duplicate or a placeholder value.

Frequently asked questions

Can I send only the days that changed?

No. The call replaces the whole schedule: every working day belongs in days, and every day needing non-default hours needs its own workHours entry. A day left out of days is no longer a working day.

When should resetUserOverrides be true?

Leave it false, or omit it, when individual exceptions should survive. Set it true only when you intend every person in that location to move onto the new schedule.

What does a 202 response mean for my client?

Poll the operation URL until it reports SUCCEEDED or FAILED. If it reports UNKNOWN, read the location's work week again before deciding whether the change was applied.

curl -X PUT "$API_BASE_URL/v2/locations/string/work-week" \
  -H "Authorization: Bearer " \
  -H "Content-Type: application/json" \
  -d '{
    "days": [
      1,
      2,
      3,
      4,
      5
    ],
    "workHours": [
      {
        "day": 5,
        "hours": 4
      }
    ],
    "resetUserOverrides": false
  }'
{
  "data": {
    "days": [
      1,
      2,
      3,
      4,
      5
    ],
    "workHours": [
      {
        "day": 5,
        "hours": 4
      }
    ]
  }
}
{
  "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": "RESOURCE_NOT_FOUND",
    "name": "ResourceNotFound",
    "description": "Example post details.",
    "resolution": "Check the ID of the resource named in details.resource and that the key owner can see it.",
    "requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef"
  }
}
{
  "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"
  }
}

id

FieldTypeRequiredDescriptionConstraints
idstringYesresource ID.

Idempotency-Key

FieldTypeRequiredDescriptionConstraints
Idempotency-KeystringNooptional 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

FieldTypeRequiredDescriptionConstraints
X-On-Behalf-OfstringNoID 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.

response

FieldTypeRequiredDescriptionConstraints
responseobjectReturned 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.operationobjectYes
response.operation.idstringYes
response.operation.statusstringYesoperation 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.urlstringYes

response

FieldTypeRequiredDescriptionConstraints
responseobjectError envelope returned by every endpoint, including authentication and rate limit errors. error.code is one of the codes in x-error-catalog .
response.errorobjectYes
response.error.codestringYesstable machine-readable error code
response.error.namestringYesshort human-readable error name
response.error.descriptionstringYeswhat went wrong
response.error.resolutionstringYeshow to fix the problem
response.error.requestIdstringYesrequest ID, include it when contacting support
response.error.detailsobjectNooptional additional information specific to the error code
response.error.details.[key: string]anyNo

response

FieldTypeRequiredDescriptionConstraints
responseobjectError envelope returned by every endpoint, including authentication and rate limit errors. error.code is one of the codes in x-error-catalog .
response.errorobjectYes
response.error.codestringYesstable machine-readable error code
response.error.namestringYesshort human-readable error name
response.error.descriptionstringYeswhat went wrong
response.error.resolutionstringYeshow to fix the problem
response.error.requestIdstringYesrequest ID, include it when contacting support
response.error.detailsobjectNooptional additional information specific to the error code
response.error.details.[key: string]anyNo

response

FieldTypeRequiredDescriptionConstraints
responseobjectError envelope returned by every endpoint, including authentication and rate limit errors. error.code is one of the codes in x-error-catalog .
response.errorobjectYes
response.error.codestringYesstable machine-readable error code
response.error.namestringYesshort human-readable error name
response.error.descriptionstringYeswhat went wrong
response.error.resolutionstringYeshow to fix the problem
response.error.requestIdstringYesrequest ID, include it when contacting support
response.error.detailsobjectNooptional additional information specific to the error code
response.error.details.[key: string]anyNo

response

FieldTypeRequiredDescriptionConstraints
responseobjectError envelope returned by every endpoint, including authentication and rate limit errors. error.code is one of the codes in x-error-catalog .
response.errorobjectYes
response.error.codestringYesstable machine-readable error code
response.error.namestringYesshort human-readable error name
response.error.descriptionstringYeswhat went wrong
response.error.resolutionstringYeshow to fix the problem
response.error.requestIdstringYesrequest ID, include it when contacting support
response.error.detailsobjectNooptional additional information specific to the error code
response.error.details.[key: string]anyNo

response

FieldTypeRequiredDescriptionConstraints
responseobjectError envelope returned by every endpoint, including authentication and rate limit errors. error.code is one of the codes in x-error-catalog .
response.errorobjectYes
response.error.codestringYesstable machine-readable error code
response.error.namestringYesshort human-readable error name
response.error.descriptionstringYeswhat went wrong
response.error.resolutionstringYeshow to fix the problem
response.error.requestIdstringYesrequest ID, include it when contacting support
response.error.detailsobjectNooptional additional information specific to the error code
response.error.details.[key: string]anyNo

response

FieldTypeRequiredDescriptionConstraints
responseobjectError envelope returned by every endpoint, including authentication and rate limit errors. error.code is one of the codes in x-error-catalog .
response.errorobjectYes
response.error.codestringYesstable machine-readable error code
response.error.namestringYesshort human-readable error name
response.error.descriptionstringYeswhat went wrong
response.error.resolutionstringYeshow to fix the problem
response.error.requestIdstringYesrequest ID, include it when contacting support
response.error.detailsobjectNooptional additional information specific to the error code
response.error.details.[key: string]anyNo

response

FieldTypeRequiredDescriptionConstraints
responseobjectError envelope returned by every endpoint, including authentication and rate limit errors. error.code is one of the codes in x-error-catalog .
response.errorobjectYes
response.error.codestringYesstable machine-readable error code
response.error.namestringYesshort human-readable error name
response.error.descriptionstringYeswhat went wrong
response.error.resolutionstringYeshow to fix the problem
response.error.requestIdstringYesrequest ID, include it when contacting support
response.error.detailsobjectNooptional additional information specific to the error code
response.error.details.[key: string]anyNo

response

FieldTypeRequiredDescriptionConstraints
responseobjectError envelope returned by every endpoint, including authentication and rate limit errors. error.code is one of the codes in x-error-catalog .
response.errorobjectYes
response.error.codestringYesstable machine-readable error code
response.error.namestringYesshort human-readable error name
response.error.descriptionstringYeswhat went wrong
response.error.resolutionstringYeshow to fix the problem
response.error.requestIdstringYesrequest ID, include it when contacting support
response.error.detailsobjectNooptional additional information specific to the error code
response.error.details.[key: string]anyNo