Vacation Tracker Docs
REST API v2API referenceDepartments

Create a department

This API method creates a department. Requires `departments:write`. The acting user is the key owner, or the `X-On-Behalf-Of` user. It waits for the department to be created and returns it, with its parent and approvers, with `201`; if that takes longer than the wait window it returns `202 Accepted` with an operation to poll. - `name` and at least one entry in `approvers` are required. Each approver's `levels` defaults to `["FIRST"]`; `SECOND` needs a plan with multi-level approval. - `userIds` moves those users into the new department and defaults to an empty array. `isDefault` defaults to `false`; `true` makes this the company's default department. - `parentId` makes this a sub-department; omit it for a top-level department. - Unknown fields and values of the wrong type fail validation. Errors: `400 VALIDATION_ERROR` (`details.fields`), `400 INVALID_REQUEST_BODY`, `403 ON_BEHALF_OF_NOT_ALLOWED`, `403 FORBIDDEN`, `403 FEATURE_NOT_IN_PLAN` (a `SECOND` approval level without multi-level approval in the plan), `409 DUPLICATE_NAME` (another department already uses the name), `422 UNKNOWN_USER_IDS` (`userIds` or `approvers` name users who are not active users of the company), `422 PLAN_LIMIT_REACHED`, and the `Idempotency-Key` codes.

POST
/v2/departments

Authorization

bearerAuth departments:write
AuthorizationBearer <token>

API key sent as Authorization: Bearer vt_live_<secret>. See the Authentication and Scopes sections at the top of this document for how keys are created, which scopes exist and how the key owner's role limits them.

In: header

Scope: departments:write

Header Parameters

Idempotency-Key?string

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.

Length1 <= length <= 255
X-On-Behalf-Of?string

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.

Request Body

application/json

TypeScript Definitions

Use the request body type in TypeScript.

Response Body

application/json

application/json

application/json

application/json

application/json

application/json

application/json

application/json

application/json

curl -X POST "https://example.com/v2/departments" \  -H "Content-Type: application/json" \  -d '{    "name": "Dev Team",    "approvers": [      {        "userId": "user-63b17e97-d38b-4586-8498-bb4f5d2e2c14"      }    ],    "userIds": [      "user-cfe5d39b-f1f0-45aa-85cd-ce93e637a262"    ]  }'
{
  "data": {
    "id": "team-0a21c25e-6925-4a5b-90ee-ecf82096c4f6",
    "name": "Dev Team",
    "isDefault": false,
    "createdAt": "2022-08-22T15:00:00.000Z",
    "parentId": "team-969f8429-7dc3-48a1-96b1-6049a99dda06",
    "approvers": [
      {
        "userId": "user-63b17e97-d38b-4586-8498-bb4f5d2e2c14",
        "levels": [
          "FIRST"
        ]
      },
      {
        "userId": "user-0f3a9c1e-6c2b-4a5d-9e7f-1b2c3d4e5f60",
        "levels": [
          "SECOND"
        ]
      }
    ]
  }
}
{
  "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": "A query parameter, body field or header failed validation.",
    "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": "The API key is missing, malformed or not recognized.",
    "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": "The API key does not have the scopes this request needs.",
    "resolution": "Add the scopes listed in details.requiredScopes to the key in the Vacation Tracker dashboard.",
    "requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef",
    "details": {
      "requiredScopes": [
        "leaves:write"
      ]
    }
  }
}

{
  "error": {
    "code": "CONFLICT",
    "name": "Conflict",
    "description": "The request conflicts with the current state of the resource.",
    "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": "The user does not have enough balance for this leave.",
    "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": "Too many requests were sent in a short time.",
    "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": "Something went wrong on our side.",
    "resolution": "Retry later, and if it keeps happening, contact Vacation Tracker support and quote the requestId.",
    "requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef"
  }
}