---
title: "Create token"
method: POST
path: "/api/users/service/{userId}/personal-access-tokens"
tags: ["Personal access token"]
---

# Create token

`POST /api/users/service/{userId}/personal-access-tokens`

Create a new personal access token with specified permissions and project access.

## Path parameters

- `userId` string, uuid, nullable, required

## Request body

- object
  - `note` string, required — A descriptive note for the token (1-100 characters)
  - `allProjects` boolean, required — Indicates if token can be used for all projects.
  - `projects` string[] — List of projects where token can be used. Applicable if allProjects is false.
  - `permissions` string[] — List of permissions to grant to the token
  - `expiry` 'week' | 'month' | 'three_months' | 'year' | 'indefinite', required — Token expiration period (week, month, three_months, year, or indefinite)

## Response `200`

Created personal access token with the generated token value

- object — Created personal access token with the generated token value
  - `id` string, uuid, required — Unique identifier of the personal access token
  - `note` string, required — Description or note for the token
  - `permissions` string[], required — List of permissions granted to this token
  - `allProjects` boolean, required — Whether the token has access to all projects
  - `projects` object[], required — List of projects the token has access to
    - `id` string, uuid, required — Unique identifier of the project
    - `name` string, required — Name of the project
    - `key` string — Project key
    - `organisationId` string, uuid, required — Organisation ID the project belongs to
    - `version` string, required — Project version
    - `createdAt` string, required — Timestamp when the project was created
    - `updatedAt` string, required — Timestamp when the project was last updated
    - `protected` boolean — Whether the project is protected
  - `user` object, required — User who owns the token
    - `id` string, uuid, required — Unique identifier of the user
    - `email` string, email, required — Email address of the user
    - `firstName` string, nullable — First name of the user
    - `lastName` string, nullable — Last name of the user
    - `type` string, required — User type (e.g., member, admin, owner)
    - `status` string, required — User status (e.g., active, disabled)
    - `isService` boolean — Whether the user is a service account
    - `createdAt` string, required — Timestamp when the user was created
    - `updatedAt` string, required — Timestamp when the user was last updated
  - `createdAt` string, required — Timestamp when the token was created
  - `updatedAt` string, required — Timestamp when the token was last updated
  - `expiresAt` string, nullable — Timestamp when the token expires, null if indefinite
  - `token` string, required — The generated token value (only returned on create or regenerate)

---

[API](https://skmtc.dev/gorules/apis/gorules-agent-api.md) · [All operations](https://skmtc.dev/gorules/apis/gorules-agent-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/gorules/gorules-agent-api/revisions/52c0773fcd80/schema)
