object token.create(object/array tokens)
This method allows to create new tokens.
The Manage API tokens permission is required for the user role to manage tokens for other users.
A token created by this method also has to be generated before it is usable.
(object/array)
Tokens to create.
The method accepts tokens with the standard token properties.
(object)
Returns an object containing the IDs of the created tokens under the tokenids
property. The order of the returned IDs matches the order of the passed tokens.
Create an enabled token that never expires and authenticates user of ID 2.
{
"jsonrpc": "2.0",
"method": "token.create",
"params": {
"name": "Your token",
"userid": "2"
},
"id": 1
}
Response:
Create a disabled token that expires at January 21st, 2021. This token will authenticate current user.
{
"jsonrpc": "2.0",
"method": "token.create",
"params": {
"name": "Your token",
"status": "1",
"expires_at": "1611238072"
},
"id": 1
}
Response:
CToken::create() in ui/include/classes/api/services/CToken.php.