Skip to content

Update a label with the REST API v2 endpoint

Use this endpoint when an existing label needs a new name, a new colour, or both. It is a partial update: you supply only the fields that should change, and everything else stays as it is.

What to send

Send a PATCH request to /v2/labels/{id}, where id is the required string identifier of the label in the path. The request body is JSON and must contain at least one of two optional string fields: name for the label name, or color for the label colour. Both fields require a length of at least 1 when present. For color, any non-empty string is accepted, but a # hex code such as #00AAFF is recommended so the dashboard can display it. The supplied example changes only the colour to #FF0000, which leaves the existing name untouched.

Authorisation and acting user

Authenticate with an API key sent as a Bearer token in the Authorization header, using the labels:write scope. By default the key owner is the acting user. Naming a different person through X-On-Behalf-Of is permitted only when the key also carries users:act-on-behalf and the owner is responsible for that person; failing either condition produces 403 ON_BEHALF_OF_NOT_ALLOWED. This header has no effect on GET calls. Before calling, check that the key is valid, carries the required scope, and that any on-behalf target is manageable by the key owner.

Retrying safely with Idempotency-Key

For a retry-safe write, add an optional Idempotency-Key. Acceptable values run from 1 to 255 printable ASCII characters, and the service keeps each one for a day, scoped to the API key. An exact repeat inside that day gets the first outcome back again, flagged with Idempotent-Replayed. Three distinct failures are possible: pairing the key with altered content yields 422 IDEMPOTENCY_KEY_REUSED, sending it again before completion yields 409 IDEMPOTENCY_REQUEST_IN_PROGRESS, and a malformed value yields 400 INVALID_IDEMPOTENCY_KEY. In practice, generate one key per logical update, keep it unchanged across retries of that update, and generate a fresh key for a different change.

Reading the response: 200 versus 202

A 200 response returns the label in a data object with id, name, color, and userCount, the last being the number of users carrying the label or 0 when none do. A 202 response instead returns an operation object with id, status, and url; poll that URL until the status becomes SUCCEEDED or FAILED. An UNKNOWN status means no result arrived within 15 minutes and the change may or may not have been applied, so read the label to check before retrying. Do not treat a 202 as a failure, and do not assume the new values are readable until the operation settles.

Errors and a pre-flight checklist

Errors use a common envelope with a stable code, a short name, a description, a suggested resolution, and a requestId to quote when seeking help. A 400 VALIDATION_ERROR names the offending fields in details.fields, and a malformed body returns 400 INVALID_REQUEST_BODY. A 401 means the key is missing, malformed, or unrecognised, while a 403 can mean the acting user may not perform the action or that on-behalf use is not allowed. A 404 RESOURCE_NOT_FOUND means the label does not exist or is outside the data the key can access. Further documented outcomes include 409 for a conflict with current state, 422 for an idempotency-key reuse, 429 for rate limiting, and 500 for an internal error. Work through this checklist in order: fix any fields listed in details.fields, confirm the label ID and key visibility, confirm scopes and on-behalf permission, then retry with up-to-date values and the same Idempotency-Key where appropriate.

Field and header map
Field or headerRequiredPurpose
id (path)YesIdentifier of the label to change
name (body)NoNew label name, minimum length 1
color (body)NoNew label colour, minimum length 1; a # hex code is recommended
Idempotency-Key (header)No1 to 255 printable ASCII characters; retained for 24 hours per API key
X-On-Behalf-Of (header)NoUser the write is performed for; requires users:act-on-behalf and a manageable target user

Partial update: at least one body field is required; omitted fields keep their current values.

Frequently asked questions

Can I send only the colour and leave the name unchanged?

No. Include only the property or properties you intend to alter, and include at least one. Any property left out retains its existing value, so a colour-only change does not clear the name.

What is the difference between a 200 and a 202 response?

A 200 response returns the updated label directly. A 202 response means the write is still running or its result cannot yet be read back, so poll the operation URL until it reports SUCCEEDED or FAILED. If it reports UNKNOWN, read the label to check whether the change was applied.

How should an Idempotency-Key be used for a safe retry?

Use a key of 1 to 255 printable ASCII characters. Repeating the same key with the same request within 24 hours replays the original response. Reusing it with a different request returns 422, retrying while the first request is still running returns 409, and an invalid key returns 400.

What authorisation is required to update a label?

The request needs the labels:write scope and a valid Bearer API key. If X-On-Behalf-Of is used, the users:act-on-behalf scope is also required and the key owner must manage the target user, otherwise the request fails with 403 ON_BEHALF_OF_NOT_ALLOWED.

curl -X PATCH "$API_BASE_URL/v2/labels/string" \
  -H "Authorization: Bearer " \
  -H "Content-Type: application/json" \
  -d '{
    "color": "#FF0000"
  }'
{
  "data": {
    "id": "969f8429-7dc3-48a1-96b1-6049a99dda06",
    "name": "contractor",
    "color": "#FF0000",
    "userCount": 12
  }
}
{
  "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.

body

FieldTypeRequiredDescriptionConstraints
bodyobjectYes1 <= properties
body.namestringNolabel name1 <= length
body.colorstringNolabel color. Any non-empty string is accepted; use a # hex code such as #00AAFF so the dashboard can show it.1 <= length

response

FieldTypeRequiredDescriptionConstraints
responseobject
response.dataobjectYes
response.data.idstringYeslabel ID
response.data.namestringYeslabel name
response.data.colorstringYeslabel color, as stored (the dashboard uses a hex code)
response.data.userCountintegerYesthe number of users with this label, 0 when none

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