--- id: create-token title: "Create a Token" description: "Create a new token for a user" sidebar_label: "Create a Token" hide_title: true hide_table_of_contents: true api: {"description":"Create a new token for a user","tags":["Tokens"],"operationId":"createToken","security":[{"BearerAuth":[]},{"TokenAuth":[]}],"parameters":[{"in":"path","name":"userId","required":true,"schema":{"type":"string"},"description":"The unique identifier of a user"}],"requestBody":{"description":"PersonalAccessToken create parameters","content":{"application/json":{"schema":{"type":"object","properties":{"name":{"description":"Name of the token","type":"string"},"expires_in":{"description":"Expiration in days","type":"integer","minimum":1,"maximum":365}},"required":["name","expires_in"],"title":"PersonalAccessTokenRequest"}}}},"responses":{"200":{"description":"The token in plain text","content":{"application/json":{"schema":{"type":"object","properties":{"plain_token":{"description":"Plain text representation of the generated token","type":"string"},"personal_access_token":{"type":"object","properties":{"id":{"description":"ID of a token","type":"string"},"name":{"description":"Name of the token","type":"string"},"expiration_date":{"description":"Date the token expires","type":"string","format":"date-time"},"created_by":{"description":"User ID of the user who created the token","type":"string"},"created_at":{"description":"Date the token was created","type":"string","format":"date-time"},"last_used":{"description":"Date the token was last used","type":"string","format":"date-time"}},"required":["id","name","expiration_date","created_by","created_at"],"title":"PersonalAccessToken"}},"required":["plain_token","personal_access_token"],"title":"PersonalAccessTokenGenerated"}}}},"400":{"description":"Bad Request","content":{}},"401":{"description":"Requires authentication","content":{}},"403":{"description":"Forbidden","content":{}},"500":{"description":"Internal Server Error","content":{}}},"method":"post","path":"/api/users/{userId}/tokens","servers":[{"url":"https://netbird.io","description":"Default server"}],"securitySchemes":{"BearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"JWT"},"TokenAuth":{"type":"apiKey","in":"header","name":"Authorization","description":"Prefix the value with \\\"Token\\\" to indicate the custom authorization type"}},"jsonRequestBodyExample":{"name":"string","expires_in":0},"info":{"title":"NetBird REST API","description":"API to manipulate groups, rules, policies and retrieve information about peers and users","version":"0.0.1"},"postman":{"name":"Create a Token","description":{"content":"Create a new token for a user","type":"text/plain"},"url":{"path":["api","users",":userId","tokens"],"host":["{{baseUrl}}"],"query":[],"variable":[{"disabled":false,"description":{"content":"(Required) The unique identifier of a user","type":"text/plain"},"type":"any","value":"","key":"userId"}]},"header":[{"key":"Content-Type","value":"application/json"},{"key":"Accept","value":"application/json"}],"method":"POST","body":{"mode":"raw","raw":"\"\"","options":{"raw":{"language":"json"}}},"auth":{"type":"bearer","bearer":[{"type":"any","value":"","key":"token"}]}}} sidebar_class_name: "post api-method" info_path: api/netbird-rest-api custom_edit_url: null --- import ApiTabs from "@theme/ApiTabs"; import MimeTabs from "@theme/MimeTabs"; import ParamsItem from "@theme/ParamsItem"; import ResponseSamples from "@theme/ResponseSamples"; import SchemaItem from "@theme/SchemaItem"; import SchemaTabs from "@theme/SchemaTabs"; import DiscriminatorTabs from "@theme/DiscriminatorTabs"; import TabItem from "@theme/TabItem"; ## Create a Token Create a new token for a user
Path Parameters
Request Body
PersonalAccessToken create parameters
    = 1` and `<= 365`"} schema={{"description":"Expiration in days","type":"integer","minimum":1,"maximum":365}}>
The token in plain text
Schema
    personal_access_token object required
Bad Request
Requires authentication
Forbidden
Internal Server Error