Create API key
curl --request POST \
--url https://your-instance.example.com/admin/keys \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"label": "My API Key",
"lifetimeDays": 90,
"scopes": [
"<string>"
]
}
'const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({label: 'My API Key', lifetimeDays: 90, scopes: ['<string>']})
};
fetch('https://your-instance.example.com/admin/keys', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));import requests
url = "https://your-instance.example.com/admin/keys"
payload = {
"label": "My API Key",
"lifetimeDays": 90,
"scopes": ["<string>"]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://your-instance.example.com/admin/keys"
payload := strings.NewReader("{\n \"label\": \"My API Key\",\n \"lifetimeDays\": 90,\n \"scopes\": [\n \"<string>\"\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://your-instance.example.com/admin/keys",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'label' => 'My API Key',
'lifetimeDays' => 90,
'scopes' => [
'<string>'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}{
"createdAt": "<string>",
"expiresAt": "<string>",
"id": "<string>",
"key": "<string>",
"label": "<string>",
"scopes": [
"<string>"
]
}{
"docs": "https://docs.polymorfa.com/api/messages/send",
"error": "missing required field: chatId"
}{
"error": "internal server error"
}{
"docs": "<string>",
"error": "<string>"
}keys
Create API key
Generates a new scoped API key. The raw key is shown only once.
POST
/
admin
/
keys
Create API key
curl --request POST \
--url https://your-instance.example.com/admin/keys \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"label": "My API Key",
"lifetimeDays": 90,
"scopes": [
"<string>"
]
}
'const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({label: 'My API Key', lifetimeDays: 90, scopes: ['<string>']})
};
fetch('https://your-instance.example.com/admin/keys', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));import requests
url = "https://your-instance.example.com/admin/keys"
payload = {
"label": "My API Key",
"lifetimeDays": 90,
"scopes": ["<string>"]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://your-instance.example.com/admin/keys"
payload := strings.NewReader("{\n \"label\": \"My API Key\",\n \"lifetimeDays\": 90,\n \"scopes\": [\n \"<string>\"\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://your-instance.example.com/admin/keys",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'label' => 'My API Key',
'lifetimeDays' => 90,
'scopes' => [
'<string>'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}{
"createdAt": "<string>",
"expiresAt": "<string>",
"id": "<string>",
"key": "<string>",
"label": "<string>",
"scopes": [
"<string>"
]
}{
"docs": "https://docs.polymorfa.com/api/messages/send",
"error": "missing required field: chatId"
}{
"error": "internal server error"
}{
"docs": "<string>",
"error": "<string>"
}Authorizations
Scoped API key created via POST /api/account/keys.
Body
application/json
Key parameters
Human-readable label for the key
Example:
"My API Key"
Key lifetime in days (required, max configurable via MAX_API_KEY_LIFETIME_DAYS)
Example:
90
Permission scopes to grant (string names converted to bitmask internally). Valid values: *, sessions:read, sessions:manage, messages:write, chats:read, chats:manage, contacts:read, contacts:manage, groups:read, groups:manage, channels:read, channels:manage, status:write, presence:read, presence:write, labels:read, labels:manage, profile:read, profile:write, webhooks:manage, media:read, media:manage
Response
Created