Unable to create a group token
I tried to create a group token by UI:
- I have opened a group settings > access tokens and I have a message: Group access token creation is disabled in this group. You can enable group access token creation in group settings. You can still use and manage existing tokens. Learn more.
- When I clicked on group settings I cannot find the option to enable creation of access tokens.
I tried the way with the API.
-
I have created a PRIVATE access token for the "api" scope with the UI.
-
I have created a script to fetch groups with the api:
import requests from config import GITLAB_URL, PRIVATE_TOKEN # API endpoint to list groups list_groups_endpoint = f"{GITLAB_URL}/api/v4/groups" # Headers for the request headers = { "PRIVATE-TOKEN": PRIVATE_TOKEN, "Content-Type": "application/json", } # Make the request to list groups response = requests.get(list_groups_endpoint, headers=headers) if response.status_code == 200: groups = response.json() print("Groups accessible by the user:") for group in groups: print(f"ID: {group['id']}, Name: {group['name']}, Access Level: {group.get('access_level', 'N/A')}") else: print(f"Failed to list groups: {response.status_code}") print("Response content:", response.text)
The result is:
python3 src/get-groups.py Groups accessible by the user: ID: 88861511, Name: nan.web, Access Level: N/A
-
I have created a script to create a group token with the api:
import requests from config import GITLAB_URL, PRIVATE_TOKEN, GROUP_ID # API endpoint to create a group access token api_endpoint = f"{GITLAB_URL}/api/v4/groups/{GROUP_ID}/access_tokens" # Access token data data = { "name": "api", "scopes": ["api"], "expires_at": "2025-06-17", } # Headers for the request headers = { "PRIVATE-TOKEN": PRIVATE_TOKEN, "Content-Type": "application/json", } # Make the request to create the access token response = requests.post(api_endpoint, json=data, headers=headers) # Detailed error handling and logging if response.status_code == 201: print("Access token created successfully:") print(response.json()) elif response.status_code == 400: print("Failed to create access token: 400 Bad Request") print("Response content:", response.json()) else: print(f"Failed to create access token: {response.status_code}") print("Response content:", response.text)
The result is:
python3 src/create-group-token.py Failed to create access token: 400 Bad Request Response content: {'message': '400 Bad request - User does not have permission to create group access token'}
How can I create a token for a group?
What am I missing?