Skip to content

Get a Label by ID

This endpoint returns a single label from the labels collection. Use it when you already hold a label ID and need its name, stored color, or the number of users assigned to it. The call requires the labels:read scope and a Bearer token in the Authorization header.

Request contract

The method is GET and the path is /v2/labels/{id}. The only path parameter is id, a required string that identifies the label resource. Authentication uses the Authorization header with the form Bearer <token>, and the key must carry the labels:read scope. The server base URL is $API_BASE_URL. The complete request and response contracts, including the exact cURL example and JSON schemas, are delivered in the protected modules referenced below.

What the response contains

A successful 200 application/json response wraps a label object inside a data property. The label object has four required fields. Use the field map below to read them correctly.

Field map

The table below explains each field in the returned label object.

Error handling and failure distinction

The endpoint can return several error statuses. A 404 with code RESOURCE_NOT_FOUND means the label does not exist or is outside the data this key can access. A 401 means the API key is missing, malformed, or not recognized. A 403 can indicate the key lacks a required scope or that the acting user may not perform the action. A 429 means too many requests were sent in a short time. A 500 means something went wrong on the server side. Every error envelope includes a requestId to quote when contacting support. The exact error bodies are delivered in the protected modules referenced below.

Worked example

Suppose the label ID is 969f8429-7dc3-48a1-96b1-6049a99dda06. A successful response returns data with name "contractor", color "#FF0000", and userCount 12. The color is returned as stored; the dashboard uses a hex code. The userCount is the number of users with this label, and it is 0 when none are assigned. The exact JSON body is delivered in the protected module referenced below.

Decision checklist before you call

  1. Confirm you have the label ID as a string. 2. Confirm your API key includes labels:read. 3. Confirm the key owner can see the label; otherwise the endpoint returns 404 rather than revealing it. 4. Send the request to the correct base URL with the Authorization header. 5. If you receive 401, check the key format and that it starts with vt_live_. 6. If you receive 403, check the scope and the acting user's role. 7. If you receive 404, verify the ID and the key owner's access. 8. If you receive 429, wait and retry. 9. If you receive 500, retry later and quote the requestId if the problem persists.
Label response fields
FieldTypeRequiredMeaning
idstringYeslabel ID
namestringYeslabel name
colorstringYeslabel color, as stored (the dashboard uses a hex code)
userCountintegerYesthe number of users with this label, 0 when none

Field types and requiredness are taken from the supplied response schema. The color is returned as stored; the dashboard uses a hex code.

Frequently asked questions

What scope does this endpoint require?

The labels:read scope. The API key must be sent as Authorization: Bearer vt_live_<secret>.

What does a 404 RESOURCE_NOT_FOUND mean here?

The label does not exist or is outside the data this key can access. Check the ID and confirm the key owner can see the label.

How do I tell a 401 apart from a 403?

A 401 means the API key is missing, malformed, or not recognized. A 403 means the key lacks a required scope or the acting user may not perform the action. Both return an error envelope with a requestId.

What does userCount represent?

It is the number of users with this label, and it is 0 when none are assigned.

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

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
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